Commit 7d1df207 authored by Monty's avatar Monty

MDEV-30373 Wrong result with range access

This issue was caused by the bug fix for
MDEV-30325 Wrong result upon range query using index condition

The bug could happen in the case of several overlapping key ranges
with OR
parent 17858e03
......@@ -3655,6 +3655,17 @@ b
SET @@optimizer_switch=@save_optimizer_switch;
drop table t1,t2;
#
# MDEV-30373 Wrong result with range access
#
CREATE TABLE t1 (pk int, a int, PRIMARY KEY (pk), KEY(a)) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1,3),(2,6),(3,9);
SELECT * FROM t1 WHERE a < 8 OR ( pk BETWEEN 1 AND 5 AND a BETWEEN 7 AND 10 );
pk a
1 3
2 6
3 9
DROP TABLE t1;
#
# End of 10.5 tests
#
set global innodb_stats_persistent= @innodb_stats_persistent_save;
......
......@@ -2520,6 +2520,15 @@ SELECT t1.b FROM t1 LEFT JOIN t2 ON t1.a = t2.pk WHERE t1.a IS NULL ORDER BY t1.
SET @@optimizer_switch=@save_optimizer_switch;
drop table t1,t2;
--echo #
--echo # MDEV-30373 Wrong result with range access
--echo #
CREATE TABLE t1 (pk int, a int, PRIMARY KEY (pk), KEY(a)) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1,3),(2,6),(3,9);
SELECT * FROM t1 WHERE a < 8 OR ( pk BETWEEN 1 AND 5 AND a BETWEEN 7 AND 10 );
DROP TABLE t1;
--echo #
--echo # End of 10.5 tests
--echo #
......
......@@ -6,8 +6,20 @@ use dbt3_s001;
#
SELECT COUNT(*) FROM lineitem force index (i_l_orderkey_quantity,i_l_shipdate) WHERE l_shipdate < '1994-01-01' AND l_orderkey < 800 OR l_quantity > 3 AND l_orderkey NOT IN ( 157, 1444 );
COUNT(*)
5056
5658
SELECT COUNT(*) FROM lineitem ignore index (i_l_orderkey_quantity,i_l_shipdate) WHERE l_shipdate < '1994-01-01' AND l_orderkey < 800 OR l_quantity > 3 AND l_orderkey NOT IN ( 157, 1444 );
COUNT(*)
5658
#
# End of 10.5 tests
# MDEV-30373 Wrong result with range access
#
explain SELECT COUNT(*) FROM lineitem WHERE l_orderkey BETWEEN 111 AND 262 OR ( l_orderkey BETWEEN 152 AND 672 AND l_linenumber BETWEEN 4 AND 9 );
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE lineitem range PRIMARY,i_l_orderkey,i_l_orderkey_quantity PRIMARY 8 NULL 506 Using where; Using index
SELECT COUNT(*) FROM lineitem WHERE l_orderkey BETWEEN 111 AND 262 OR ( l_orderkey BETWEEN 152 AND 672 AND l_linenumber BETWEEN 4 AND 9 );
COUNT(*)
293
DROP DATABASE dbt3_s001;
#
# End of 10.5 tests
#
......@@ -16,9 +16,18 @@ use dbt3_s001;
--echo #
SELECT COUNT(*) FROM lineitem force index (i_l_orderkey_quantity,i_l_shipdate) WHERE l_shipdate < '1994-01-01' AND l_orderkey < 800 OR l_quantity > 3 AND l_orderkey NOT IN ( 157, 1444 );
SELECT COUNT(*) FROM lineitem ignore index (i_l_orderkey_quantity,i_l_shipdate) WHERE l_shipdate < '1994-01-01' AND l_orderkey < 800 OR l_quantity > 3 AND l_orderkey NOT IN ( 157, 1444 );
--echo #
--echo # End of 10.5 tests
--echo # MDEV-30373 Wrong result with range access
--echo #
explain SELECT COUNT(*) FROM lineitem WHERE l_orderkey BETWEEN 111 AND 262 OR ( l_orderkey BETWEEN 152 AND 672 AND l_linenumber BETWEEN 4 AND 9 );
SELECT COUNT(*) FROM lineitem WHERE l_orderkey BETWEEN 111 AND 262 OR ( l_orderkey BETWEEN 152 AND 672 AND l_linenumber BETWEEN 4 AND 9 );
DROP DATABASE dbt3_s001;
--echo #
--echo # End of 10.5 tests
--echo #
......@@ -3644,6 +3644,17 @@ b
SET @@optimizer_switch=@save_optimizer_switch;
drop table t1,t2;
#
# MDEV-30373 Wrong result with range access
#
CREATE TABLE t1 (pk int, a int, PRIMARY KEY (pk), KEY(a)) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1,3),(2,6),(3,9);
SELECT * FROM t1 WHERE a < 8 OR ( pk BETWEEN 1 AND 5 AND a BETWEEN 7 AND 10 );
pk a
1 3
2 6
3 9
DROP TABLE t1;
#
# End of 10.5 tests
#
set global innodb_stats_persistent= @innodb_stats_persistent_save;
......
......@@ -10621,7 +10621,7 @@ key_or(RANGE_OPT_PARAM *param, SEL_ARG *key1,SEL_ARG *key2)
tmp: [---------]
*/
key2->copy_max_to_min(tmp);
key2= key2_next;
key2->next= key2_next; // In case of key2_shared
}
continue;
}
......
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