Commit 3d617fdc authored by Monty's avatar Monty

MDEV-31375 Assertion `dbl_records <= s->records' failed with optimizer_use_condition_selectivity=1

The reason for the crash wad that 'best splitting' optimization
predicted less rows to be found than what opt_range did.
This code in apply_selectivity_for_table(), when using use_cond_selectivity=1,
was not prepared for this case which caused an assert in debug builds.
Production builds is not affected.

The fix is to choose the smaller of the two row counts. It will have a
minimum on costs when using use_cond_selectivity=1 and should not cause
any problems in production.
parent d3c81804
......@@ -55,5 +55,19 @@ SELECT a FROM t1 JOIN t2 WHERE a = b AND c <> 7 GROUP BY a HAVING a != 6 AND a <
a
DROP TABLE t1, t2;
#
# MDEV-31375 Assertion `dbl_records <= s->records' failed with
# optimizer_use_condition_selectivity=1
#
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (id INT PRIMARY KEY);
INSERT INTO t2 VALUES (2),(3);
SET optimizer_switch = 'derived_with_keys=off';
SET optimizer_use_condition_selectivity = 1;
SELECT t1.* FROM t1 JOIN (SELECT id, COUNT(*) FROM t2 GROUP BY id) sq ON sq.id = t1.a;
a
2
DROP TABLE t1, t2;
#
# End of 11.0 tests
#
......@@ -63,6 +63,20 @@ EXPLAIN SELECT a FROM t1 JOIN t2 WHERE a = b AND c <> 7 GROUP BY a HAVING a != 6
SELECT a FROM t1 JOIN t2 WHERE a = b AND c <> 7 GROUP BY a HAVING a != 6 AND a <= 9;
DROP TABLE t1, t2;
--echo #
--echo # MDEV-31375 Assertion `dbl_records <= s->records' failed with
--echo # optimizer_use_condition_selectivity=1
--echo #
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (id INT PRIMARY KEY);
INSERT INTO t2 VALUES (2),(3);
SET optimizer_switch = 'derived_with_keys=off';
SET optimizer_use_condition_selectivity = 1;
SELECT t1.* FROM t1 JOIN (SELECT id, COUNT(*) FROM t2 GROUP BY id) sq ON sq.id = t1.a;
DROP TABLE t1, t2;
--echo #
--echo # End of 11.0 tests
--echo #
......@@ -7870,12 +7870,15 @@ static double apply_selectivity_for_table(JOIN_TAB *s,
/*
This is only taking into considering constant key parts used with
this table!
If no such conditions existed the following should hold:
If no such conditions existed the following should normally hold:
s->table->opt_range_condition_rows == s->found_rows ==
s->records.
The case when this does not hold is when using 'best splitting'
in which case s->records may be less than s->found_rows;
*/
DBUG_ASSERT(s->table->opt_range_condition_rows <= s->found_records);
dbl_records= rows2double(s->table->opt_range_condition_rows);
dbl_records= rows2double(MY_MIN(s->table->opt_range_condition_rows,
s->records));
}
DBUG_ASSERT(dbl_records <= s->records);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment