Commit 16942bc5 authored by Igor Babaev's avatar Igor Babaev

Fixed LP bug #881449.

The function SELECT_LEX::update_used_tables first must clean up
all bitmaps to be recalculated for all tables that require it
and only after this walk through on conditions attached to the
tables to update these bitmaps.
  
parent fbcff7a4
...@@ -1741,4 +1741,27 @@ a b ...@@ -1741,4 +1741,27 @@ a b
SET SESSION join_cache_level = default; SET SESSION join_cache_level = default;
DROP VIEW v2; DROP VIEW v2;
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
#
# Bug #881449: OUTER JOIN usin a merged view within IN subquery
#
CREATE TABLE t1 (a varchar(1)) ;
INSERT INTO t1 VALUES ('y'), ('x');
CREATE TABLE t2 (a int, PRIMARY KEY (a)) ;
INSERT INTO t2 VALUES (1), (2);
CREATE TABLE t3 (a int, b varchar(1)) ;
INSERT INTO t3 VALUES (1,'x');
CREATE VIEW v3 AS SELECT * FROM t3;
SET SESSION optimizer_switch='semijoin=on';
EXPLAIN
SELECT * FROM t1 WHERE a IN (SELECT v3.b FROM t2 RIGHT JOIN v3 ON v3.a = t2.a);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 system NULL NULL NULL NULL 1
1 PRIMARY t2 const PRIMARY PRIMARY 4 const 1 Using index
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
SELECT * FROM t1 WHERE a IN (SELECT v3.b FROM t2 RIGHT JOIN v3 ON v3.a = t2.a);
a
x
set optimizer_switch= @save_optimizer_switch;
DROP VIEW v3;
DROP TABLE t1,t2,t3;
set optimizer_switch=@exit_optimizer_switch; set optimizer_switch=@exit_optimizer_switch;
...@@ -1140,5 +1140,31 @@ SET SESSION join_cache_level = default; ...@@ -1140,5 +1140,31 @@ SET SESSION join_cache_level = default;
DROP VIEW v2; DROP VIEW v2;
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
--echo #
--echo # Bug #881449: OUTER JOIN usin a merged view within IN subquery
--echo #
CREATE TABLE t1 (a varchar(1)) ;
INSERT INTO t1 VALUES ('y'), ('x');
CREATE TABLE t2 (a int, PRIMARY KEY (a)) ;
INSERT INTO t2 VALUES (1), (2);
CREATE TABLE t3 (a int, b varchar(1)) ;
INSERT INTO t3 VALUES (1,'x');
CREATE VIEW v3 AS SELECT * FROM t3;
SET SESSION optimizer_switch='semijoin=on';
EXPLAIN
SELECT * FROM t1 WHERE a IN (SELECT v3.b FROM t2 RIGHT JOIN v3 ON v3.a = t2.a);
SELECT * FROM t1 WHERE a IN (SELECT v3.b FROM t2 RIGHT JOIN v3 ON v3.a = t2.a);
set optimizer_switch= @save_optimizer_switch;
DROP VIEW v3;
DROP TABLE t1,t2,t3;
# The following command must be the last one the file # The following command must be the last one the file
set optimizer_switch=@exit_optimizer_switch; set optimizer_switch=@exit_optimizer_switch;
...@@ -3408,12 +3408,12 @@ void SELECT_LEX::update_used_tables() ...@@ -3408,12 +3408,12 @@ void SELECT_LEX::update_used_tables()
{ {
TABLE_LIST *tl; TABLE_LIST *tl;
List_iterator<TABLE_LIST> ti(leaf_tables); List_iterator<TABLE_LIST> ti(leaf_tables);
while ((tl= ti++)) while ((tl= ti++))
{ {
TABLE_LIST *embedding;
if (tl->table && !tl->is_view_or_derived()) if (tl->table && !tl->is_view_or_derived())
{ {
embedding= tl->embedding; TABLE_LIST *embedding= tl->embedding;
for (embedding= tl->embedding; embedding; embedding=embedding->embedding) for (embedding= tl->embedding; embedding; embedding=embedding->embedding)
{ {
if (embedding->is_view_or_derived()) if (embedding->is_view_or_derived())
...@@ -3429,7 +3429,12 @@ void SELECT_LEX::update_used_tables() ...@@ -3429,7 +3429,12 @@ void SELECT_LEX::update_used_tables()
} }
} }
} }
embedding= tl; }
ti.rewind();
while ((tl= ti++))
{
TABLE_LIST *embedding= tl;
do do
{ {
bool maybe_null; bool maybe_null;
...@@ -3458,6 +3463,7 @@ void SELECT_LEX::update_used_tables() ...@@ -3458,6 +3463,7 @@ void SELECT_LEX::update_used_tables()
embedding= tl->embedding; embedding= tl->embedding;
} }
} }
if (join->conds) if (join->conds)
{ {
join->conds->update_used_tables(); join->conds->update_used_tables();
......
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