summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Petrunia <sergey@mariadb.com>2023-02-22 12:11:55 +0300
committerSergei Petrunia <sergey@mariadb.com>2023-02-22 12:11:55 +0300
commit301fd687f790a4ebfd1dc6b275926a6071895e6d (patch)
tree6d4dc91c1ac686052c3da8caac885380ffa4ddfe
parentd61bc94fa02c76fc3d9b0acf22d59377fc4a5d0a (diff)
downloadmariadb-git-bb-11.0-mdev30693.tar.gz
MDEV-30693: Assertion `dbl_records <= s->records' failed in apply_selectivity_for_table on SELECTbb-11.0-mdev30693
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().
-rw-r--r--mysql-test/main/selectivity_innodb.result9
-rw-r--r--mysql-test/main/selectivity_innodb.test9
-rw-r--r--sql/opt_split.cc7
3 files changed, 24 insertions, 1 deletions
diff --git a/mysql-test/main/selectivity_innodb.result b/mysql-test/main/selectivity_innodb.result
index 965a1ffd117..b324c0357d3 100644
--- a/mysql-test/main/selectivity_innodb.result
+++ b/mysql-test/main/selectivity_innodb.result
@@ -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
#
diff --git a/mysql-test/main/selectivity_innodb.test b/mysql-test/main/selectivity_innodb.test
index dc06287a1f9..efdb3c1853b 100644
--- a/mysql-test/main/selectivity_innodb.test
+++ b/mysql-test/main/selectivity_innodb.test
@@ -283,5 +283,14 @@ SELECT b FROM t WHERE a > 'a' GROUP BY b HAVING b >= 6 OR b <= 0;
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 #
diff --git a/sql/opt_split.cc b/sql/opt_split.cc
index 99082813d7f..c64d60398b3 100644
--- a/sql/opt_split.cc
+++ b/sql/opt_split.cc
@@ -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=
+ select_lex->master_unit()->derived->table->stat_records();
rec_len= table->s->rec_buff_length;