Commit a87f424c authored by Sergey Petrunya's avatar Sergey Petrunya

BUG#834758: Wrong result with innner join, LooseScan, two-column IN() predicate

- get_bound_sj_equalities() would produce incorrect bitmap when non-first 
  equality was bound, which resulted in invalid LooseScan plans.
parent b6a09bb3
......@@ -1749,4 +1749,27 @@ FROM t2
);
a
drop table t1, t2,t3;
#
# BUG#834758: Wrong result with innner join, LooseScan, two-column IN() predicate
#
set @tmp835758=@@optimizer_switch;
set optimizer_switch='semijoin=on,loosescan=on,materialization=off,firstmatch=off';
CREATE TABLE t1 (b int) ;
INSERT INTO t1 VALUES (1),(5);
CREATE TABLE t2 (a int, PRIMARY KEY (a)) ;
INSERT INTO t2 VALUES (6),(10);
CREATE TABLE t3 (a int, b int, KEY (b)) ;
INSERT INTO t3 VALUES (6,5),(6,2),(8,0),(9,1),(6,5);
# This used to incorrectly pick a join order of (t1, LooseScan(t3), t2):
explain
SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Start temporary
1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 2 Using index; Using join buffer (flat, BNL join)
1 PRIMARY t3 ALL b NULL NULL NULL 5 Using where; End temporary; Using join buffer (flat, BNL join)
SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3);
b a
5 6
DROP TABLE t1, t2, t3;
set @@optimizer_switch= @tmp835758;
set optimizer_switch=@subselect_sj_tmp;
......@@ -1760,6 +1760,29 @@ FROM t2
);
a
drop table t1, t2,t3;
#
# BUG#834758: Wrong result with innner join, LooseScan, two-column IN() predicate
#
set @tmp835758=@@optimizer_switch;
set optimizer_switch='semijoin=on,loosescan=on,materialization=off,firstmatch=off';
CREATE TABLE t1 (b int) ;
INSERT INTO t1 VALUES (1),(5);
CREATE TABLE t2 (a int, PRIMARY KEY (a)) ;
INSERT INTO t2 VALUES (6),(10);
CREATE TABLE t3 (a int, b int, KEY (b)) ;
INSERT INTO t3 VALUES (6,5),(6,2),(8,0),(9,1),(6,5);
# This used to incorrectly pick a join order of (t1, LooseScan(t3), t2):
explain
SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Start temporary
1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 2 Using index; Using join buffer (flat, BNL join)
1 PRIMARY t3 ALL b NULL NULL NULL 5 Using where; End temporary; Using join buffer (incremental, BNL join)
SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3);
b a
5 6
DROP TABLE t1, t2, t3;
set @@optimizer_switch= @tmp835758;
set optimizer_switch=@subselect_sj_tmp;
#
# BUG#49129: Wrong result with IN-subquery with join_cache_level=6 and firstmatch=off
......
......@@ -1594,5 +1594,29 @@ WHERE (t3.a) IN (
);
drop table t1, t2,t3;
--echo #
--echo # BUG#834758: Wrong result with innner join, LooseScan, two-column IN() predicate
--echo #
set @tmp835758=@@optimizer_switch;
set optimizer_switch='semijoin=on,loosescan=on,materialization=off,firstmatch=off';
CREATE TABLE t1 (b int) ;
INSERT INTO t1 VALUES (1),(5);
CREATE TABLE t2 (a int, PRIMARY KEY (a)) ;
INSERT INTO t2 VALUES (6),(10);
CREATE TABLE t3 (a int, b int, KEY (b)) ;
INSERT INTO t3 VALUES (6,5),(6,2),(8,0),(9,1),(6,5);
--echo # This used to incorrectly pick a join order of (t1, LooseScan(t3), t2):
explain
SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3);
SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3);
DROP TABLE t1, t2, t3;
set @@optimizer_switch= @tmp835758;
# The following command must be the last one the file
set optimizer_switch=@subselect_sj_tmp;
......@@ -2639,6 +2639,7 @@ ulonglong get_bound_sj_equalities(TABLE_LIST *sj_nest,
{
res |= 1ULL << i;
}
i++;
}
return res;
}
......
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