Skip to content

Commit 40c62c4

Browse files
author
Maheedhar PV
committed
Bug#34347116 - Range intersection is not available for a compound
index when joining a derived table Issue: When merging the derived table, a nested join condition is added to the derived table and the underlying tables are added to this join nest. Also, the join condition is associated with the derived table and not the table in the join nest. Evaluating for range access is skipped if the table is inner table of an outer join or if the table is inner and it is not a semi-join. In this case the underlying base table is of the latter kind, the range analysis is skipped and we do not have the range access method. Fix: If the embedded table is derived, use the join condition associated with the derived table to evaluate range access. Skip marking the table as "constant" if the range check evaluates to "impossible range" and the condition used for the range check is from the derived embedding table. Change-Id: I31b2a739198d3e2e5d8aff3e0b049aa1549734a9
1 parent c7c1490 commit 40c62c4

File tree

9 files changed

+275
-26
lines changed

9 files changed

+275
-26
lines changed

mysql-test/include/range.inc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3201,3 +3201,26 @@ SET @@GLOBAL.innodb_stats_transient_sample_pages= @innodb_stats_transient_sample
32013201
SET @@GLOBAL.innodb_stats_persistent_sample_pages= @innodb_stats_persistent_sample_pages;
32023202
-- enable_result_log
32033203
-- enable_query_log
3204+
3205+
--echo #
3206+
--echo # Bug#34347116 - Range intersection is not available for a
3207+
--echo # compound index when joining a derived table
3208+
--echo #
3209+
3210+
CREATE TABLE t1 (a SERIAL, b INT);
3211+
INSERT INTO t1(b) VALUES (1),(2),(3),(100);
3212+
CREATE TABLE t2 (a SERIAL, b INT, c INT, INDEX(b,c));
3213+
INSERT INTO t2(b,c) VALUES (10,10),(100,100),(200,200);
3214+
3215+
EXPLAIN SELECT t1.* FROM t1 LEFT JOIN (SELECT a,b,c FROM t2 WHERE b=100 AND c<=100 AND c>=100) t ON t1.a=t.b;
3216+
EXPLAIN SELECT b,c FROM t2 WHERE b=100 AND c<=100 AND c>=100;
3217+
3218+
DROP TABLE t1, t2;
3219+
3220+
CREATE TABLE t1 (c1 INT AUTO_INCREMENT, c2 INT, c3 VARCHAR(1) , PRIMARY KEY(c1));
3221+
INSERT INTO t1 VALUES (1,1,'a'), (2,2,'b'), (3,4,'c'), (4,4,'z'),(5,5,'L');
3222+
ANALYZE TABLE t1;
3223+
3224+
SELECT at1.c3 FROM (t1 AS at1 LEFT JOIN (SELECT at2.* FROM (t1 AS at2 JOIN t1 AS at3 ON ((1,2) IN (SELECT c1,c1 FROM t1 as at4)))) AS at5 ON at5.c1 = at1.c1);
3225+
3226+
DROP TABLE t1;

mysql-test/r/partition_pruning.result

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6039,7 +6039,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
60396039
1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 10 100.00 NULL
60406040
1 SIMPLE t1 p4 eq_ref PRIMARY PRIMARY 4 test.t2.pk 1 100.00 Using where
60416041
1 SIMPLE <subquery3> NULL eq_ref <auto_distinct_key> <auto_distinct_key> 5 test.t1.pk 1 100.00 Using where
6042-
3 MATERIALIZED t3 p3,p4 ALL PRIMARY NULL NULL NULL 8 100.00 Using where
6042+
3 MATERIALIZED t3 p3,p4 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where
60436043
Warnings:
60446044
Note 1003 /* select#1 */ select `test`.`t2`.`pk` AS `pk`,`test`.`t2`.`c` AS `c`,`test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c` AS `c` from `test`.`t2` left join (`test`.`t1` semi join (`test`.`t3`)) on(((`test`.`t1`.`pk` = `test`.`t2`.`pk`) and (`<subquery3>`.`c` = `test`.`t2`.`pk`) and (`test`.`t1`.`pk` > 3) and (`test`.`t3`.`pk` > 2))) where true
60456045
SELECT * FROM t2 LEFT JOIN (SELECT * FROM t1 WHERE t1.pk IN (SELECT c FROM t3 WHERE pk > 2)) t13 on t13.pk = t2.pk AND t13.pk > 3;
@@ -6080,7 +6080,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
60806080
1 SIMPLE t3 p0,p1,p2 eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 100.00 NULL
60816081
1 SIMPLE t2 NULL eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 100.00 NULL
60826082
1 SIMPLE tx p0,p1,p2,p3,p4 eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 100.00 NULL
6083-
1 SIMPLE t3 p3,p4 ALL PRIMARY NULL NULL NULL 8 100.00 Using where; FirstMatch(tx)
6083+
1 SIMPLE t3 p3,p4 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where; FirstMatch(tx)
60846084
Warnings:
60856085
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c` AS `c`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`c` AS `c`,`test`.`t3`.`pk` AS `pk`,`test`.`t3`.`c` AS `c`,`test`.`tx`.`pk` AS `pk`,`test`.`tx`.`c` AS `c` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`pk` = `test`.`t1`.`pk`)) join `test`.`t3` left join (`test`.`t1` `tx` semi join (`test`.`t3`)) on(((`test`.`tx`.`pk` = `test`.`t1`.`pk`) and (`test`.`t3`.`c` = `test`.`t1`.`pk`) and (`test`.`t3`.`pk` > 2))) where ((`test`.`t3`.`pk` = `test`.`t1`.`pk`) and (`test`.`t1`.`pk` < 3))
60866086
SELECT * FROM (t1 LEFT JOIN t2 on t1.pk = t2.pk) JOIN (t3 LEFT JOIN (SELECT * FROM t1 as tx WHERE tx.pk IN (SELECT c FROM t3 WHERE pk > 2)) t13 on t3.pk = t13.pk) on t1.pk = t3.pk AND t1.pk < 3;
@@ -6094,7 +6094,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
60946094
1 SIMPLE t3 p0,p1,p2 ALL PRIMARY NULL NULL NULL 2 100.00 Using where
60956095
1 SIMPLE tx p0,p1,p2,p3,p4 eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 100.00 NULL
60966096
1 SIMPLE <subquery3> NULL eq_ref <auto_distinct_key> <auto_distinct_key> 5 test.tx.pk 1 100.00 Using where
6097-
3 MATERIALIZED t3 p3,p4 ALL PRIMARY NULL NULL NULL 8 100.00 Using where
6097+
3 MATERIALIZED t3 p3,p4 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where
60986098
Warnings:
60996099
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c` AS `c`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`c` AS `c`,`test`.`t3`.`pk` AS `pk`,`test`.`t3`.`c` AS `c`,`test`.`tx`.`pk` AS `pk`,`test`.`tx`.`c` AS `c` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`pk` = `test`.`t1`.`pk`)) left join (`test`.`t3` left join (`test`.`t1` `tx` semi join (`test`.`t3`)) on(((`test`.`tx`.`pk` = `test`.`t1`.`pk`) and (`<subquery3>`.`c` = `test`.`t1`.`pk`) and (`test`.`t3`.`pk` > 2)))) on(((`test`.`t3`.`pk` = `test`.`t1`.`pk`) and (`test`.`t1`.`pk` < 3))) where true
61006100
SELECT * FROM (t1 LEFT JOIN t2 on t1.pk = t2.pk) LEFT JOIN (t3 LEFT JOIN (SELECT * FROM t1 as tx WHERE tx.pk IN (SELECT c FROM t3 WHERE pk > 2)) t13 on t3.pk = t13.pk) on t1.pk = t3.pk AND t1.pk < 3;
@@ -6126,7 +6126,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
61266126
1 SIMPLE <subquery3> NULL eq_ref <auto_distinct_key> <auto_distinct_key> 5 test.tx.pk 1 100.00 Using where
61276127
1 SIMPLE t1 p0,p1,p2 ALL PRIMARY NULL NULL NULL 2 100.00 Using where
61286128
1 SIMPLE t2 NULL eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 100.00 Using where
6129-
3 MATERIALIZED t3 p3,p4 ALL PRIMARY NULL NULL NULL 8 100.00 Using where
6129+
3 MATERIALIZED t3 p3,p4 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where
61306130
Warnings:
61316131
Note 1003 /* select#1 */ select `test`.`t3`.`pk` AS `pk`,`test`.`t3`.`c` AS `c`,`test`.`tx`.`pk` AS `pk`,`test`.`tx`.`c` AS `c`,`test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c` AS `c`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`c` AS `c` from `test`.`t3` left join (`test`.`t1` `tx` semi join (`test`.`t3`)) on(((`test`.`tx`.`pk` = `test`.`t3`.`pk`) and (`<subquery3>`.`c` = `test`.`t3`.`pk`) and (`test`.`t3`.`pk` > 2))) left join (`test`.`t1` left join `test`.`t2` on((`test`.`t2`.`pk` = `test`.`t3`.`pk`))) on(((`test`.`t1`.`pk` = `test`.`t3`.`pk`) and (`test`.`t3`.`pk` < 3))) where true
61326132
SELECT * FROM (t3 LEFT JOIN (SELECT * FROM t1 as tx WHERE tx.pk IN (SELECT c FROM t3 WHERE pk > 2)) t13 on t3.pk = t13.pk) LEFT JOIN (t1 LEFT JOIN t2 on t1.pk = t2.pk) on t1.pk = t3.pk AND t1.pk < 3;
@@ -6147,7 +6147,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
61476147
1 SIMPLE t1 p0,p1,p2 eq_ref PRIMARY PRIMARY 4 test.t3.pk 1 100.00 NULL
61486148
1 SIMPLE t2 NULL eq_ref PRIMARY PRIMARY 4 test.t3.pk 1 100.00 NULL
61496149
1 SIMPLE tx p0,p1,p2,p3,p4 eq_ref PRIMARY PRIMARY 4 test.t3.pk 1 100.00 NULL
6150-
1 SIMPLE t3 p3,p4 ALL PRIMARY NULL NULL NULL 8 100.00 Using where; FirstMatch(tx)
6150+
1 SIMPLE t3 p3,p4 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where; FirstMatch(tx)
61516151
Warnings:
61526152
Note 1003 /* select#1 */ select `test`.`t3`.`pk` AS `pk`,`test`.`t3`.`c` AS `c`,`test`.`tx`.`pk` AS `pk`,`test`.`tx`.`c` AS `c`,`test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c` AS `c`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`c` AS `c` from `test`.`t3` left join (`test`.`t1` `tx` semi join (`test`.`t3`)) on(((`test`.`tx`.`pk` = `test`.`t3`.`pk`) and (`test`.`t3`.`c` = `test`.`t3`.`pk`) and (`test`.`t3`.`pk` > 2))) join `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`pk` = `test`.`t3`.`pk`)) where ((`test`.`t1`.`pk` = `test`.`t3`.`pk`) and (`test`.`t3`.`pk` < 3))
61536153
SELECT * FROM (t3 LEFT JOIN (SELECT * FROM t1 as tx WHERE tx.pk IN (SELECT c FROM t3 WHERE pk > 2)) t13 on t3.pk = t13.pk) JOIN (t1 LEFT JOIN t2 on t1.pk = t2.pk) on t1.pk = t3.pk AND t1.pk < 3;
@@ -6174,7 +6174,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
61746174
1 SIMPLE tx p0,p1,p2 ALL PRIMARY NULL NULL NULL 2 100.00 Using where
61756175
1 SIMPLE <subquery3> NULL eq_ref <auto_distinct_key> <auto_distinct_key> 5 test.tx.pk 1 100.00 Using where
61766176
1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 10 100.00 Using where
6177-
3 MATERIALIZED t3 p3,p4 ALL PRIMARY NULL NULL NULL 8 100.00 NULL
6177+
3 MATERIALIZED t3 p3,p4 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where
61786178
Warnings:
61796179
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c` AS `c`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`c` AS `c`,`test`.`t5`.`pk` AS `pk`,`test`.`t5`.`c` AS `c`,`test`.`tx`.`pk` AS `pk`,`test`.`tx`.`c` AS `c`,`test`.`t4`.`pk` AS `pk`,`test`.`t4`.`c` AS `c` from `test`.`t1` left join `test`.`t2` on(((`test`.`t2`.`pk` = `test`.`t1`.`pk`) and (`test`.`t1`.`pk` < 2))) left join (`test`.`t5` join `test`.`t1` `tx` semi join (`test`.`t3`) left join `test`.`t4` on((`test`.`t5`.`c` = (`test`.`t4`.`c` + 15)))) on(((`test`.`t5`.`pk` = `test`.`t1`.`pk`) and (`test`.`tx`.`pk` = `test`.`t1`.`pk`) and (`<subquery3>`.`c` = `test`.`t1`.`pk`) and (`test`.`t1`.`pk` < 3) and (`test`.`t3`.`pk` > 2))) where true
61806180
SELECT * FROM (t1 LEFT JOIN t2 on t1.pk = t2.pk and t1.pk < 2) LEFT JOIN ((t5 LEFT JOIN (SELECT * FROM t1 as tx WHERE tx.pk IN (SELECT c FROM t3 WHERE pk > 2)) t13 on t5.pk = t13.pk) LEFT JOIN t4 on t5.c = t4.c + 15) on t1.pk = t13.pk AND t1.pk < 3;
@@ -6207,7 +6207,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
62076207
1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 10 100.00 Using where; Using join buffer (hash join)
62086208
1 SIMPLE t1 p0,p1,p2 eq_ref PRIMARY PRIMARY 4 test.tx.pk 1 100.00 Using where
62096209
1 SIMPLE t2 NULL eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 100.00 Using where
6210-
3 MATERIALIZED t3 p3,p4 ALL PRIMARY NULL NULL NULL 8 100.00 Using where
6210+
3 MATERIALIZED t3 p3,p4 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where
62116211
Warnings:
62126212
Note 1003 /* select#1 */ select `test`.`t5`.`pk` AS `pk`,`test`.`t5`.`c` AS `c`,`test`.`tx`.`pk` AS `pk`,`test`.`tx`.`c` AS `c`,`test`.`t4`.`pk` AS `pk`,`test`.`t4`.`c` AS `c`,`test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c` AS `c`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`c` AS `c` from `test`.`t5` left join (`test`.`t1` `tx` semi join (`test`.`t3`)) on(((`test`.`tx`.`pk` = `test`.`t5`.`pk`) and (`<subquery3>`.`c` = `test`.`t5`.`pk`) and (`test`.`t3`.`pk` > 2))) left join `test`.`t4` on((`test`.`t5`.`c` = (`test`.`t4`.`c` + 15))) left join (`test`.`t1` left join `test`.`t2` on(((`test`.`t2`.`pk` = `test`.`tx`.`pk`) and (`test`.`tx`.`pk` < 2)))) on(((`test`.`t1`.`pk` = `test`.`tx`.`pk`) and (`test`.`tx`.`pk` < 3))) where true
62136213
SELECT * FROM ((t5 LEFT JOIN (SELECT * FROM t1 as tx WHERE tx.pk IN (SELECT c FROM t3 WHERE pk > 2)) t13 on t5.pk = t13.pk) LEFT JOIN t4 on t5.c = t4.c + 15) LEFT JOIN (t1 LEFT JOIN t2 on t1.pk = t2.pk and t1.pk < 2) on t1.pk = t13.pk AND t1.pk < 3;
@@ -6255,7 +6255,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
62556255
1 SIMPLE tx p4 eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 100.00 NULL
62566256
1 SIMPLE <subquery3> NULL eq_ref <auto_distinct_key> <auto_distinct_key> 5 test.tx.pk 1 100.00 Using where
62576257
1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 10 100.00 Using where
6258-
3 MATERIALIZED t3 p3,p4 ALL PRIMARY NULL NULL NULL 8 100.00 NULL
6258+
3 MATERIALIZED t3 p3,p4 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where
62596259
Warnings:
62606260
Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c` AS `c`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`c` AS `c`,`test`.`t4`.`pk` AS `pk`,`test`.`t4`.`c` AS `c`,`test`.`t5`.`pk` AS `pk`,`test`.`t5`.`c` AS `c`,`test`.`tx`.`pk` AS `pk`,`test`.`tx`.`c` AS `c` from `test`.`t1` left join `test`.`t2` on(((`test`.`t2`.`pk` = `test`.`t1`.`pk`) and (`test`.`t1`.`pk` > 3))) left join (`test`.`t4` join `test`.`t5` join `test`.`t1` `tx` semi join (`test`.`t3`)) on(((`test`.`t5`.`pk` = `test`.`t1`.`pk`) and (`test`.`tx`.`pk` = `test`.`t1`.`pk`) and (`<subquery3>`.`c` = `test`.`t1`.`pk`) and (`test`.`t1`.`pk` > 3) and (`test`.`t3`.`pk` > 2) and (`test`.`t5`.`c` = (`test`.`t4`.`c` + 20)))) where true
62616261
SELECT * FROM (t1 LEFT JOIN t2 on t1.pk = t2.pk and t1.pk > 3) LEFT JOIN (t4 LEFT JOIN (t5 LEFT JOIN (SELECT * FROM t1 as tx WHERE tx.pk IN (SELECT c FROM t3 WHERE pk > 2)) t13 on t5.pk = t13.pk) on t5.c = t4.c + 20) on t1.pk = t13.pk AND t1.pk > 3;
@@ -6288,7 +6288,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
62886288
1 SIMPLE <subquery3> NULL eq_ref <auto_distinct_key> <auto_distinct_key> 5 test.tx.pk 1 100.00 Using where
62896289
1 SIMPLE t1 p4 eq_ref PRIMARY PRIMARY 4 test.tx.pk 1 100.00 Using where
62906290
1 SIMPLE t2 NULL eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 100.00 Using where
6291-
3 MATERIALIZED t3 p3,p4 ALL PRIMARY NULL NULL NULL 8 100.00 Using where
6291+
3 MATERIALIZED t3 p3,p4 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where
62926292
Warnings:
62936293
Note 1003 /* select#1 */ select `test`.`t4`.`pk` AS `pk`,`test`.`t4`.`c` AS `c`,`test`.`t5`.`pk` AS `pk`,`test`.`t5`.`c` AS `c`,`test`.`tx`.`pk` AS `pk`,`test`.`tx`.`c` AS `c`,`test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c` AS `c`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`c` AS `c` from `test`.`t4` left join (`test`.`t5` left join (`test`.`t1` `tx` semi join (`test`.`t3`)) on(((`test`.`tx`.`pk` = `test`.`t5`.`pk`) and (`<subquery3>`.`c` = `test`.`t5`.`pk`) and (`test`.`t3`.`pk` > 2)))) on((`test`.`t5`.`c` = (`test`.`t4`.`c` + 20))) left join (`test`.`t1` left join `test`.`t2` on(((`test`.`t2`.`pk` = `test`.`tx`.`pk`) and (`test`.`tx`.`pk` > 3)))) on(((`test`.`t1`.`pk` = `test`.`tx`.`pk`) and (`test`.`tx`.`pk` > 3))) where true
62946294
SELECT * FROM (t4 LEFT JOIN (t5 LEFT JOIN (SELECT * FROM t1 as tx WHERE tx.pk IN (SELECT c FROM t3 WHERE pk > 2)) t13 on t5.pk = t13.pk) on t5.c = t4.c + 20) LEFT JOIN (t1 LEFT JOIN t2 on t1.pk = t2.pk and t1.pk > 3) on t1.pk = t13.pk AND t1.pk > 3;

mysql-test/r/range_all.result

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4060,4 +4060,37 @@ a
40604060
2
40614061
1
40624062
DROP TABLE t1;
4063+
#
4064+
# Bug#34347116 - Range intersection is not available for a
4065+
# compound index when joining a derived table
4066+
#
4067+
CREATE TABLE t1 (a SERIAL, b INT);
4068+
INSERT INTO t1(b) VALUES (1),(2),(3),(100);
4069+
CREATE TABLE t2 (a SERIAL, b INT, c INT, INDEX(b,c));
4070+
INSERT INTO t2(b,c) VALUES (10,10),(100,100),(200,200);
4071+
EXPLAIN SELECT t1.* FROM t1 LEFT JOIN (SELECT a,b,c FROM t2 WHERE b=100 AND c<=100 AND c>=100) t ON t1.a=t.b;
4072+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
4073+
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 4 100.00 NULL
4074+
1 SIMPLE t2 NULL range b b 10 NULL 1 100.00 Using where; Using index; Using join buffer (hash join)
4075+
Warnings:
4076+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` left join (`test`.`t2`) on(((`test`.`t2`.`b` = 100) and (`test`.`t1`.`a` = `test`.`t2`.`b`) and (`test`.`t2`.`c` <= 100) and (`test`.`t2`.`c` >= 100))) where true
4077+
EXPLAIN SELECT b,c FROM t2 WHERE b=100 AND c<=100 AND c>=100;
4078+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
4079+
1 SIMPLE t2 NULL range b b 10 NULL 1 100.00 Using where; Using index
4080+
Warnings:
4081+
Note 1003 /* select#1 */ select `test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where ((`test`.`t2`.`b` = 100) and (`test`.`t2`.`c` <= 100) and (`test`.`t2`.`c` >= 100))
4082+
DROP TABLE t1, t2;
4083+
CREATE TABLE t1 (c1 INT AUTO_INCREMENT, c2 INT, c3 VARCHAR(1) , PRIMARY KEY(c1));
4084+
INSERT INTO t1 VALUES (1,1,'a'), (2,2,'b'), (3,4,'c'), (4,4,'z'),(5,5,'L');
4085+
ANALYZE TABLE t1;
4086+
Table Op Msg_type Msg_text
4087+
test.t1 analyze status OK
4088+
SELECT at1.c3 FROM (t1 AS at1 LEFT JOIN (SELECT at2.* FROM (t1 AS at2 JOIN t1 AS at3 ON ((1,2) IN (SELECT c1,c1 FROM t1 as at4)))) AS at5 ON at5.c1 = at1.c1);
4089+
c3
4090+
a
4091+
b
4092+
c
4093+
z
4094+
L
4095+
DROP TABLE t1;
40634096
set optimizer_switch=default;

mysql-test/r/range_icp.result

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4060,4 +4060,37 @@ a
40604060
2
40614061
1
40624062
DROP TABLE t1;
4063+
#
4064+
# Bug#34347116 - Range intersection is not available for a
4065+
# compound index when joining a derived table
4066+
#
4067+
CREATE TABLE t1 (a SERIAL, b INT);
4068+
INSERT INTO t1(b) VALUES (1),(2),(3),(100);
4069+
CREATE TABLE t2 (a SERIAL, b INT, c INT, INDEX(b,c));
4070+
INSERT INTO t2(b,c) VALUES (10,10),(100,100),(200,200);
4071+
EXPLAIN SELECT t1.* FROM t1 LEFT JOIN (SELECT a,b,c FROM t2 WHERE b=100 AND c<=100 AND c>=100) t ON t1.a=t.b;
4072+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
4073+
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 4 100.00 NULL
4074+
1 SIMPLE t2 NULL range b b 10 NULL 1 100.00 Using where; Using index; Using join buffer (hash join)
4075+
Warnings:
4076+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` left join (`test`.`t2`) on(((`test`.`t2`.`b` = 100) and (`test`.`t1`.`a` = `test`.`t2`.`b`) and (`test`.`t2`.`c` <= 100) and (`test`.`t2`.`c` >= 100))) where true
4077+
EXPLAIN SELECT b,c FROM t2 WHERE b=100 AND c<=100 AND c>=100;
4078+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
4079+
1 SIMPLE t2 NULL range b b 10 NULL 1 100.00 Using where; Using index
4080+
Warnings:
4081+
Note 1003 /* select#1 */ select `test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where ((`test`.`t2`.`b` = 100) and (`test`.`t2`.`c` <= 100) and (`test`.`t2`.`c` >= 100))
4082+
DROP TABLE t1, t2;
4083+
CREATE TABLE t1 (c1 INT AUTO_INCREMENT, c2 INT, c3 VARCHAR(1) , PRIMARY KEY(c1));
4084+
INSERT INTO t1 VALUES (1,1,'a'), (2,2,'b'), (3,4,'c'), (4,4,'z'),(5,5,'L');
4085+
ANALYZE TABLE t1;
4086+
Table Op Msg_type Msg_text
4087+
test.t1 analyze status OK
4088+
SELECT at1.c3 FROM (t1 AS at1 LEFT JOIN (SELECT at2.* FROM (t1 AS at2 JOIN t1 AS at3 ON ((1,2) IN (SELECT c1,c1 FROM t1 as at4)))) AS at5 ON at5.c1 = at1.c1);
4089+
c3
4090+
a
4091+
b
4092+
c
4093+
z
4094+
L
4095+
DROP TABLE t1;
40634096
set optimizer_switch=default;

mysql-test/r/range_icp_mrr.result

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4060,4 +4060,37 @@ a
40604060
2
40614061
1
40624062
DROP TABLE t1;
4063+
#
4064+
# Bug#34347116 - Range intersection is not available for a
4065+
# compound index when joining a derived table
4066+
#
4067+
CREATE TABLE t1 (a SERIAL, b INT);
4068+
INSERT INTO t1(b) VALUES (1),(2),(3),(100);
4069+
CREATE TABLE t2 (a SERIAL, b INT, c INT, INDEX(b,c));
4070+
INSERT INTO t2(b,c) VALUES (10,10),(100,100),(200,200);
4071+
EXPLAIN SELECT t1.* FROM t1 LEFT JOIN (SELECT a,b,c FROM t2 WHERE b=100 AND c<=100 AND c>=100) t ON t1.a=t.b;
4072+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
4073+
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 4 100.00 NULL
4074+
1 SIMPLE t2 NULL range b b 10 NULL 1 100.00 Using where; Using index; Using join buffer (hash join)
4075+
Warnings:
4076+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` left join (`test`.`t2`) on(((`test`.`t2`.`b` = 100) and (`test`.`t1`.`a` = `test`.`t2`.`b`) and (`test`.`t2`.`c` <= 100) and (`test`.`t2`.`c` >= 100))) where true
4077+
EXPLAIN SELECT b,c FROM t2 WHERE b=100 AND c<=100 AND c>=100;
4078+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
4079+
1 SIMPLE t2 NULL range b b 10 NULL 1 100.00 Using where; Using index
4080+
Warnings:
4081+
Note 1003 /* select#1 */ select `test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where ((`test`.`t2`.`b` = 100) and (`test`.`t2`.`c` <= 100) and (`test`.`t2`.`c` >= 100))
4082+
DROP TABLE t1, t2;
4083+
CREATE TABLE t1 (c1 INT AUTO_INCREMENT, c2 INT, c3 VARCHAR(1) , PRIMARY KEY(c1));
4084+
INSERT INTO t1 VALUES (1,1,'a'), (2,2,'b'), (3,4,'c'), (4,4,'z'),(5,5,'L');
4085+
ANALYZE TABLE t1;
4086+
Table Op Msg_type Msg_text
4087+
test.t1 analyze status OK
4088+
SELECT at1.c3 FROM (t1 AS at1 LEFT JOIN (SELECT at2.* FROM (t1 AS at2 JOIN t1 AS at3 ON ((1,2) IN (SELECT c1,c1 FROM t1 as at4)))) AS at5 ON at5.c1 = at1.c1);
4089+
c3
4090+
a
4091+
b
4092+
c
4093+
z
4094+
L
4095+
DROP TABLE t1;
40634096
set optimizer_switch=default;

0 commit comments

Comments
 (0)