Commit d4f1884d authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-31380: Assertion `s->table->opt_range_condition_rows <= s->found_records' failed

LooseScan code set opt_range_condition_rows to be the

  MIN(loose_scan_plan->records, table->records)

totally ignoring possible quick range selects.  If there was a quick
select $QUICK on another index with

  $QUICK->records < loose_scan_plan->records

this would create a situation where

   opt_range_condition_rows > $QUICK->records

which caused an assert.
Fixed by making opt_range_condition_rows to be the minimum #rows
of any quick select.
parent 5919f7b6
......@@ -4226,5 +4226,19 @@ MIN(a)
0
drop table t1;
#
# MDEV-31380: Assertion `s->table->opt_range_condition_rows <= s->found_records' failed
#
CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a), KEY(b)) ENGINE=InnoDB;
INSERT INTO t1 SELECT seq, seq FROM seq_1_to_100;
SET
@tmp=@@optimizer_use_condition_selectivity,
optimizer_use_condition_selectivity = 1;
SELECT DISTINCT * FROM t1 WHERE a IN (1, 2);
a b
1 1
2 2
set optimizer_use_condition_selectivity = @tmp;
drop table t1;
#
# End of 10.6 tests
#
......@@ -1876,6 +1876,21 @@ EXPLAIN select MIN(a) from t1 group by p;
SELECT MIN(a) from t1 where p = 2;
drop table t1;
--echo #
--echo # MDEV-31380: Assertion `s->table->opt_range_condition_rows <= s->found_records' failed
--echo #
CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a), KEY(b)) ENGINE=InnoDB;
INSERT INTO t1 SELECT seq, seq FROM seq_1_to_100;
SET
@tmp=@@optimizer_use_condition_selectivity,
optimizer_use_condition_selectivity = 1;
SELECT DISTINCT * FROM t1 WHERE a IN (1, 2);
set optimizer_use_condition_selectivity = @tmp;
drop table t1;
--echo #
--echo # End of 10.6 tests
--echo #
......@@ -3030,8 +3030,8 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
restore_nonrange_trees(&param, tree, backup_keys);
if ((group_trp= get_best_group_min_max(&param, tree, read_time)))
{
param.table->opt_range_condition_rows= MY_MIN(group_trp->records,
head->stat_records());
set_if_smaller(param.table->opt_range_condition_rows,
group_trp->records);
Json_writer_object grp_summary(thd, "best_group_range_summary");
if (unlikely(thd->trace_started()))
......
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