summaryrefslogtreecommitdiff
path: root/mysql-test/t/range.test
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2020-09-24 22:02:00 -0700
committerIgor Babaev <igor@askmonty.org>2020-09-24 22:02:00 -0700
commit3080b7ebe3cf17107f5b21ac135b0e01fef04fe9 (patch)
treeeb39e65bc24f0e9cedba966718dc095f7b4aeccf /mysql-test/t/range.test
parent7c5519c12d46ead947d341cbdcbb6fbbe4d4fe1b (diff)
downloadmariadb-git-bb-10.2-mdev-23811.tar.gz
MDEV-23811: With large number of indexes optimizer chooses an inefficient planbb-10.2-mdev-23811
This bug could manifest itself for a query with WHERE condition containing top level OR formula such that each conjunct contained a single-range condition supported by the same index. One of these range conditions must be fully covered by another range condition that is used later in the OR formula. Additionally at least one of these condition should be ANDed with a sargable range condition supported by a different index. There were several attempts to fix related problems for OR conditions after the backport of range optimizer code from MySQL (commit 0e19f3e36f7842583feb6bead2c2600cd620bced). Unfortunately the first of these fixes contained typo remained unnoticed until recently. This typo bug led to rejection of valid range accesses. This patch fixed this typo bug. The fix revealed another two bugs: one in a constructor for SEL_ARG, the other in the function tree_or(). Both are fixed in this patch.
Diffstat (limited to 'mysql-test/t/range.test')
-rw-r--r--mysql-test/t/range.test42
1 files changed, 42 insertions, 0 deletions
diff --git a/mysql-test/t/range.test b/mysql-test/t/range.test
index 67d876d5f10..0d2fbe24835 100644
--- a/mysql-test/t/range.test
+++ b/mysql-test/t/range.test
@@ -2096,6 +2096,48 @@ set eq_range_index_dive_limit=default;
drop table t1;
--echo #
+--echo # MDEV-23811: Both disjunct of WHERE condition contain range conditions
+--echo # for the same index such that the second range condition
+--echo # fully covers the first one. Additionally one of the disjuncts
+--echo # contains a range condition for the other index.
+--echo #
+
+create table t1 (
+ pk int primary key auto_increment, a int, b int,
+ index idx1(a), index idx2(b)
+);
+insert into t1(a,b) values
+ (5,50), (1,10), (3,30), (7,70), (8,80), (4,40), (2,20), (6,60);
+insert into t1(a,b) select a+10, b+100 from t1;
+insert into t1(a,b) select a+20, b+200 from t1;
+insert into t1(a,b) select a+30, b+300 from t1;
+insert into t1(a,b) select a,b from t1;
+
+analyze table t1;
+
+let $q1=
+select * from t1 where ((a between 3 and 4) and b < 100) or (a between 2 and 5);
+eval explain $q1;
+eval $q1;
+
+let $q2=
+select * from t1 where (a between 2 and 5) or ((a between 3 and 4) and b < 100);
+eval explain $q2;
+eval $q2;
+
+let $q3=
+select * from t1 where (a between 3 and 4) or ((a between 2 and 5) and b < 100);
+eval explain $q3;
+eval $q3;
+
+let $q4=
+select * from t1 where ((a between 2 and 5) and b < 100) or (a between 3 and 4);
+eval explain $q4;
+eval $q4;
+
+drop table t1;
+
+--echo #
--echo # End of 10.2 tests
--echo #