diff options
author | Igor Babaev <igor@askmonty.org> | 2011-10-26 04:27:09 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2011-10-26 04:27:09 -0700 |
commit | 16942bc5ca0f239c2aa2c2cde4eaba144495e9aa (patch) | |
tree | 7ab736c490f43d35199b7279a8bace3563f408db | |
parent | fbcff7a488ba5b0e90d55df081f374b0aaff9e87 (diff) | |
download | mariadb-git-16942bc5ca0f239c2aa2c2cde4eaba144495e9aa.tar.gz |
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.
-rw-r--r-- | mysql-test/r/derived_view.result | 23 | ||||
-rw-r--r-- | mysql-test/t/derived_view.test | 26 | ||||
-rw-r--r-- | sql/sql_lex.cc | 12 |
3 files changed, 58 insertions, 3 deletions
diff --git a/mysql-test/r/derived_view.result b/mysql-test/r/derived_view.result index 3ec274acb9d..cfd98a78601 100644 --- a/mysql-test/r/derived_view.result +++ b/mysql-test/r/derived_view.result @@ -1741,4 +1741,27 @@ a b SET SESSION join_cache_level = default; DROP VIEW v2; 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; diff --git a/mysql-test/t/derived_view.test b/mysql-test/t/derived_view.test index 7f70fbef35a..5ff945c094f 100644 --- a/mysql-test/t/derived_view.test +++ b/mysql-test/t/derived_view.test @@ -1140,5 +1140,31 @@ SET SESSION join_cache_level = default; DROP VIEW v2; 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 set optimizer_switch=@exit_optimizer_switch; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index cc10cd5dee3..a6494c72889 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -3408,12 +3408,12 @@ void SELECT_LEX::update_used_tables() { TABLE_LIST *tl; List_iterator<TABLE_LIST> ti(leaf_tables); + while ((tl= ti++)) { - TABLE_LIST *embedding; if (tl->table && !tl->is_view_or_derived()) { - embedding= tl->embedding; + TABLE_LIST *embedding= tl->embedding; for (embedding= tl->embedding; embedding; embedding=embedding->embedding) { if (embedding->is_view_or_derived()) @@ -3429,7 +3429,12 @@ void SELECT_LEX::update_used_tables() } } } - embedding= tl; + } + + ti.rewind(); + while ((tl= ti++)) + { + TABLE_LIST *embedding= tl; do { bool maybe_null; @@ -3458,6 +3463,7 @@ void SELECT_LEX::update_used_tables() embedding= tl->embedding; } } + if (join->conds) { join->conds->update_used_tables(); |