Commit 9441a9cc authored by Igor Babaev's avatar Igor Babaev

Fixed LP bug #674423.

The patch that introduced the new enumeration type Match_flag
for the values of match flags in the records put into join buffers
missed the necessary modifications in JOIN_CACHE::set_match_flag_if_none.
This could cause wrong results for outer joins with on expressions
only over outer tables.

parent 9259ef4c
...@@ -5809,4 +5809,33 @@ x 2 2 NULL ...@@ -5809,4 +5809,33 @@ x 2 2 NULL
SET SESSION optimizer_switch = 'outer_join_with_cache=off'; SET SESSION optimizer_switch = 'outer_join_with_cache=off';
SET SESSION join_cache_level = DEFAULT; SET SESSION join_cache_level = DEFAULT;
DROP TABLE t1,t2,t3,t4; DROP TABLE t1,t2,t3,t4;
#
# Bug #674423: outer join with ON expression over only outer tables
#
CREATE TABLE t1 (a int) ;
INSERT INTO t1 VALUES ('9');
CREATE TABLE t2 (pk int, a int) ;
INSERT INTO t2 VALUES ('9',NULL), ('1',NULL);
SET SESSION optimizer_switch = 'outer_join_with_cache=on';
SET SESSION join_cache_level = 0;
EXPLAIN
SELECT * FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t1.a <> 0 OR t2.pk < 9;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
1 SIMPLE t1 ALL NULL NULL NULL NULL 1 Using where
SELECT * FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t1.a <>0 OR t2.pk < 9;
pk a a
1 NULL NULL
SET SESSION join_cache_level = 1;
EXPLAIN
SELECT * FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t1.a <> 0 OR t2.pk < 9;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
1 SIMPLE t1 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join)
SELECT * FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t1.a <> 0 OR t2.pk < 9;
pk a a
1 NULL NULL
SET SESSION optimizer_switch = 'outer_join_with_cache=off';
SET SESSION join_cache_level = DEFAULT;
DROP TABLE t1,t2;
set @@optimizer_switch=@save_optimizer_switch; set @@optimizer_switch=@save_optimizer_switch;
...@@ -2495,5 +2495,32 @@ SET SESSION join_cache_level = DEFAULT; ...@@ -2495,5 +2495,32 @@ SET SESSION join_cache_level = DEFAULT;
DROP TABLE t1,t2,t3,t4; DROP TABLE t1,t2,t3,t4;
--echo #
--echo # Bug #674423: outer join with ON expression over only outer tables
--echo #
CREATE TABLE t1 (a int) ;
INSERT INTO t1 VALUES ('9');
CREATE TABLE t2 (pk int, a int) ;
INSERT INTO t2 VALUES ('9',NULL), ('1',NULL);
SET SESSION optimizer_switch = 'outer_join_with_cache=on';
SET SESSION join_cache_level = 0;
EXPLAIN
SELECT * FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t1.a <> 0 OR t2.pk < 9;
SELECT * FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t1.a <>0 OR t2.pk < 9;
SET SESSION join_cache_level = 1;
EXPLAIN
SELECT * FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t1.a <> 0 OR t2.pk < 9;
SELECT * FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t1.a <> 0 OR t2.pk < 9;
SET SESSION optimizer_switch = 'outer_join_with_cache=off';
SET SESSION join_cache_level = DEFAULT;
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;
...@@ -2219,9 +2219,9 @@ bool JOIN_CACHE::set_match_flag_if_none(JOIN_TAB *first_inner, ...@@ -2219,9 +2219,9 @@ bool JOIN_CACHE::set_match_flag_if_none(JOIN_TAB *first_inner,
DBUG_ASSERT(cache); DBUG_ASSERT(cache);
rec_ptr= cache->get_rec_ref(rec_ptr); rec_ptr= cache->get_rec_ref(rec_ptr);
} }
if (rec_ptr[0] == 0) if ((Match_flag) rec_ptr[0] != MATCH_FOUND)
{ {
rec_ptr[0]= 1; rec_ptr[0]= MATCH_FOUND;
first_inner->found= 1; first_inner->found= 1;
return TRUE; return TRUE;
} }
......
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