Skip to content

Commit

Permalink
MDEV-30693: Assertion `dbl_records <= s->records' failed in apply_sel…
Browse files Browse the repository at this point in the history
…ectivity_for_table on SELECT

The crash happened due to rows=2 vs rows=1 difference between how the
estimate of number of rows in a derived table is computed in
TABLE_LIST::fetch_number_of_rows() and JOIN::add_keyuses_for_splitting().

Made JOIN::add_keyuses_for_splitting() use the result of computations in
TABLE_LIST::fetch_number_of_rows().
  • Loading branch information
spetrunia committed Mar 16, 2023
1 parent 1310b3a commit ef5bb08
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions mysql-test/main/selectivity_innodb.result
Expand Up @@ -2322,5 +2322,14 @@ b
9
DROP TABLE t;
#
# MDEV-30693: Assertion `dbl_records <= s->records' failed in apply_selectivity_for_table on SELECT
#
set @tmp_oucs= @@optimizer_use_condition_selectivity;
CREATE TABLE t1 (c INT KEY) ENGINE=InnoDB;
SELECT * FROM (SELECT * FROM t1) a JOIN (SELECT * FROM (SELECT * FROM t1 GROUP BY c) d WHERE c>1) b ON a.c=b.c;
c c
DROP TABLE t1;
SET optimizer_use_condition_selectivity=1;
#
# End of 11.0 tests
#
9 changes: 9 additions & 0 deletions mysql-test/main/selectivity_innodb.test
Expand Up @@ -282,6 +282,15 @@ SELECT b FROM t WHERE a > 'a' GROUP BY b HAVING b >= 6 OR b <= 0;
# Cleanup
DROP TABLE t;

--echo #
--echo # MDEV-30693: Assertion `dbl_records <= s->records' failed in apply_selectivity_for_table on SELECT
--echo #
set @tmp_oucs= @@optimizer_use_condition_selectivity;
CREATE TABLE t1 (c INT KEY) ENGINE=InnoDB;
SELECT * FROM (SELECT * FROM t1) a JOIN (SELECT * FROM (SELECT * FROM t1 GROUP BY c) d WHERE c>1) b ON a.c=b.c;
DROP TABLE t1;
SET optimizer_use_condition_selectivity=1;

--echo #
--echo # End of 11.0 tests
--echo #
7 changes: 6 additions & 1 deletion sql/opt_split.cc
Expand Up @@ -741,7 +741,12 @@ void JOIN::add_keyuses_for_splitting()
if (ext_keyuses_for_splitting->push(keyuse_ext_end))
goto err;

spl_opt_info->unsplit_card= join_record_count;
/*
Use the number of rows that was computed by
TABLE_LIST::fetch_number_of_rows():
*/
spl_opt_info->unsplit_card=
rows2double(select_lex->master_unit()->derived->table->stat_records());

rec_len= table->s->rec_buff_length;

Expand Down

0 comments on commit ef5bb08

Please sign in to comment.