Commit c05e5b9c authored by Igor Babaev's avatar Igor Babaev

Fixed LP bug #887479.

The function setup_semijoin_dups_elimination erroneously assumed
that if join_cache_level is set to 3 or 4 then the type of the
access to a table cannot be JT_REF or JT_EQ_REF. This could lead
to wrong query result sets.
parent 4d358f48
...@@ -5146,4 +5146,37 @@ a ...@@ -5146,4 +5146,37 @@ a
0 0
SET SESSION join_cache_level = DEFAULT; SET SESSION join_cache_level = DEFAULT;
DROP TABLE t1, t2; DROP TABLE t1, t2;
#
# Bug #887479: join_cache_level=3 + semijoin=on
#
CREATE TABLE t1 (a int, b int);
INSERT INTO t1 VALUES (3914,17), (3710,5), (3888,20);
CREATE TABLE t2 (c int, KEY (c));
INSERT INTO t2 VALUES (27), (17), (33), (20), (3), (7), (18), (2);
SET @tmp887479_optimizer_switch=@@optimizer_switch;
SET SESSION optimizer_switch='semijoin=on';
SET SESSION optimizer_switch='semijoin_with_cache=on';
SET SESSION join_cache_level=1;
EXPLAIN
SELECT * FROM t1 WHERE (t1.b) IN (SELECT c FROM t2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
1 PRIMARY t2 ref c c 5 test.t1.b 2 Using index; Start temporary; End temporary
SELECT * FROM t1 WHERE (t1.b) IN (SELECT c FROM t2);
a b
3914 17
3888 20
SET SESSION join_cache_level=3;
EXPLAIN
SELECT * FROM t1 WHERE (t1.b) IN (SELECT c FROM t2);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Start temporary
1 PRIMARY t2 hash_index c #hash#c:c 5:5 test.t1.b 8 End temporary; Using join buffer (flat, BNLH join)
SELECT * FROM t1 WHERE (t1.b) IN (SELECT c FROM t2);
a b
3914 17
3888 20
SET SESSION join_cache_level = DEFAULT;
SET optimizer_switch=@tmp887479_optimizer_switch;
DROP TABLE t1,t2;
set @@optimizer_switch=@save_optimizer_switch; set @@optimizer_switch=@save_optimizer_switch;
...@@ -3225,5 +3225,34 @@ SET SESSION join_cache_level = DEFAULT; ...@@ -3225,5 +3225,34 @@ SET SESSION join_cache_level = DEFAULT;
DROP TABLE t1, t2; DROP TABLE t1, t2;
--echo #
--echo # Bug #887479: join_cache_level=3 + semijoin=on
--echo #
CREATE TABLE t1 (a int, b int);
INSERT INTO t1 VALUES (3914,17), (3710,5), (3888,20);
CREATE TABLE t2 (c int, KEY (c));
INSERT INTO t2 VALUES (27), (17), (33), (20), (3), (7), (18), (2);
SET @tmp887479_optimizer_switch=@@optimizer_switch;
SET SESSION optimizer_switch='semijoin=on';
SET SESSION optimizer_switch='semijoin_with_cache=on';
SET SESSION join_cache_level=1;
EXPLAIN
SELECT * FROM t1 WHERE (t1.b) IN (SELECT c FROM t2);
SELECT * FROM t1 WHERE (t1.b) IN (SELECT c FROM t2);
SET SESSION join_cache_level=3;
EXPLAIN
SELECT * FROM t1 WHERE (t1.b) IN (SELECT c FROM t2);
SELECT * FROM t1 WHERE (t1.b) IN (SELECT c FROM t2);
SET SESSION join_cache_level = DEFAULT;
SET optimizer_switch=@tmp887479_optimizer_switch;
DROP TABLE t1,t2;
# this must be the last command in the file # this must be the last command in the file
set @@optimizer_switch=@save_optimizer_switch; set @@optimizer_switch=@save_optimizer_switch;
...@@ -3921,7 +3921,7 @@ int setup_semijoin_dups_elimination(JOIN *join, ulonglong options, ...@@ -3921,7 +3921,7 @@ int setup_semijoin_dups_elimination(JOIN *join, ulonglong options,
if (j != join->const_tables && js_tab->use_quick != 2 && if (j != join->const_tables && js_tab->use_quick != 2 &&
j <= no_jbuf_after && j <= no_jbuf_after &&
((js_tab->type == JT_ALL && join_cache_level != 0) || ((js_tab->type == JT_ALL && join_cache_level != 0) ||
(join_cache_level > 4 && (tab->type == JT_REF || (join_cache_level > 2 && (tab->type == JT_REF ||
tab->type == JT_EQ_REF)))) tab->type == JT_EQ_REF))))
{ {
/* Looks like we'll be using join buffer */ /* Looks like we'll be using join buffer */
......
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