diff options
author | Igor Babaev <igor@askmonty.org> | 2011-09-06 07:17:39 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2011-09-06 07:17:39 -0700 |
commit | da59130ec18a5801080a034a3c1cb442f1ad4498 (patch) | |
tree | 0fc54554be489011905a9f3f15f5f2c3d0b656ab | |
parent | 26bd06feef0d3f2e6f0a20457db1f8397117d2d5 (diff) | |
download | mariadb-git-da59130ec18a5801080a034a3c1cb442f1ad4498.tar.gz |
Fixed LP bug #838633.
For any query JOIN::optimize() should call the method
SELECT::save_leaf_tables after the last transformation
that utilizes the statement memory rather than the
execution memory.
-rw-r--r-- | mysql-test/r/join_outer.result | 33 | ||||
-rw-r--r-- | mysql-test/r/join_outer_jcl6.result | 33 | ||||
-rw-r--r-- | mysql-test/t/join_outer.test | 34 | ||||
-rw-r--r-- | sql/sql_select.cc | 5 |
4 files changed, 102 insertions, 3 deletions
diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index a400cbc44ed..85470f772d2 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -1615,3 +1615,36 @@ a a 4 NULL DEALLOCATE PREPARE stmt; DROP TABLE t1,t2; +# +# LP bug #838633: second execution of PS with outer join +# converted to inner join +# +CREATE TABLE t1 ( b int NOT NULL ) ; +INSERT INTO t1 VALUES (9),(10); +CREATE TABLE t2 ( b int NOT NULL, PRIMARY KEY (b)) ; +INSERT INTO t2 VALUES +(75),(76),(77),(78),(79),(80),(81),(82),(83),(84),(85),(86),(87),(88),(89), +(10), (90),(91),(92),(93),(94),(95),(96),(97),(98),(99),(100); +CREATE TABLE t3 ( a int, b int NOT NULL , PRIMARY KEY (b)) ; +INSERT INTO t3 VALUES +(0,6),(0,7),(0,8),(2,9),(0,10),(2,21),(0,22),(2,23),(2,24),(2,25); +SET SESSION join_cache_level=4; +EXPLAIN EXTENDED +SELECT * FROM (t2 LEFT JOIN t1 ON t1.b = t2.b) JOIN t3 ON t1.b = t3.b; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +1 SIMPLE t3 hash_ALL PRIMARY #hash#PRIMARY 4 test.t1.b 10 10.00 Using join buffer (flat, BNLH join) +1 SIMPLE t2 hash_index PRIMARY #hash#PRIMARY:PRIMARY 4:4 test.t1.b 27 3.70 Using join buffer (incremental, BNLH join) +Warnings: +Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t1`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t2` join `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`b` = `test`.`t1`.`b`) and (`test`.`t2`.`b` = `test`.`t1`.`b`)) +PREPARE stmt FROM +'SELECT * FROM (t2 LEFT JOIN t1 ON t1.b = t2.b) JOIN t3 ON t1.b = t3.b'; +EXECUTE stmt; +b b a b +10 10 0 10 +EXECUTE stmt; +b b a b +10 10 0 10 +DEALLOCATE PREPARE stmt; +SET SESSION join_cache_level=default; +DROP TABLE t1,t2,t3; diff --git a/mysql-test/r/join_outer_jcl6.result b/mysql-test/r/join_outer_jcl6.result index 735fb514d08..ff83c3bfd03 100644 --- a/mysql-test/r/join_outer_jcl6.result +++ b/mysql-test/r/join_outer_jcl6.result @@ -1624,6 +1624,39 @@ a a 4 NULL DEALLOCATE PREPARE stmt; DROP TABLE t1,t2; +# +# LP bug #838633: second execution of PS with outer join +# converted to inner join +# +CREATE TABLE t1 ( b int NOT NULL ) ; +INSERT INTO t1 VALUES (9),(10); +CREATE TABLE t2 ( b int NOT NULL, PRIMARY KEY (b)) ; +INSERT INTO t2 VALUES +(75),(76),(77),(78),(79),(80),(81),(82),(83),(84),(85),(86),(87),(88),(89), +(10), (90),(91),(92),(93),(94),(95),(96),(97),(98),(99),(100); +CREATE TABLE t3 ( a int, b int NOT NULL , PRIMARY KEY (b)) ; +INSERT INTO t3 VALUES +(0,6),(0,7),(0,8),(2,9),(0,10),(2,21),(0,22),(2,23),(2,24),(2,25); +SET SESSION join_cache_level=4; +EXPLAIN EXTENDED +SELECT * FROM (t2 LEFT JOIN t1 ON t1.b = t2.b) JOIN t3 ON t1.b = t3.b; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +1 SIMPLE t3 hash_ALL PRIMARY #hash#PRIMARY 4 test.t1.b 10 10.00 Using join buffer (flat, BNLH join) +1 SIMPLE t2 hash_index PRIMARY #hash#PRIMARY:PRIMARY 4:4 test.t1.b 27 3.70 Using join buffer (incremental, BNLH join) +Warnings: +Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t1`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t2` join `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`b` = `test`.`t1`.`b`) and (`test`.`t2`.`b` = `test`.`t1`.`b`)) +PREPARE stmt FROM +'SELECT * FROM (t2 LEFT JOIN t1 ON t1.b = t2.b) JOIN t3 ON t1.b = t3.b'; +EXECUTE stmt; +b b a b +10 10 0 10 +EXECUTE stmt; +b b a b +10 10 0 10 +DEALLOCATE PREPARE stmt; +SET SESSION join_cache_level=default; +DROP TABLE t1,t2,t3; set join_cache_level=default; show variables like 'join_cache_level'; Variable_name Value diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test index d47ceab6b74..2311edc46b7 100644 --- a/mysql-test/t/join_outer.test +++ b/mysql-test/t/join_outer.test @@ -1173,3 +1173,37 @@ EXECUTE stmt; DEALLOCATE PREPARE stmt; DROP TABLE t1,t2; + +--echo # +--echo # LP bug #838633: second execution of PS with outer join +--echo # converted to inner join +--echo # + +CREATE TABLE t1 ( b int NOT NULL ) ; +INSERT INTO t1 VALUES (9),(10); + +CREATE TABLE t2 ( b int NOT NULL, PRIMARY KEY (b)) ; +INSERT INTO t2 VALUES + (75),(76),(77),(78),(79),(80),(81),(82),(83),(84),(85),(86),(87),(88),(89), + (10), (90),(91),(92),(93),(94),(95),(96),(97),(98),(99),(100); + +CREATE TABLE t3 ( a int, b int NOT NULL , PRIMARY KEY (b)) ; +INSERT INTO t3 VALUES + (0,6),(0,7),(0,8),(2,9),(0,10),(2,21),(0,22),(2,23),(2,24),(2,25); + +SET SESSION join_cache_level=4; + +EXPLAIN EXTENDED +SELECT * FROM (t2 LEFT JOIN t1 ON t1.b = t2.b) JOIN t3 ON t1.b = t3.b; + +PREPARE stmt FROM +'SELECT * FROM (t2 LEFT JOIN t1 ON t1.b = t2.b) JOIN t3 ON t1.b = t3.b'; + +EXECUTE stmt; +EXECUTE stmt; + +DEALLOCATE PREPARE stmt; + +SET SESSION join_cache_level=default; + +DROP TABLE t1,t2,t3; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 54c1215164e..d9c6a1b668e 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -899,9 +899,6 @@ JOIN::optimize() /* dump_TABLE_LIST_graph(select_lex, select_lex->leaf_tables); */ select_lex->update_used_tables(); - /* Save this info for the next executions */ - if (select_lex->save_leaf_tables(thd)) - DBUG_RETURN(1); } eval_select_list_used_tables(); @@ -961,6 +958,8 @@ JOIN::optimize() /* Convert all outer joins to inner joins if possible */ conds= simplify_joins(this, join_list, conds, TRUE, FALSE); + if (select_lex->save_leaf_tables(thd)) + DBUG_RETURN(1); build_bitmap_for_nested_joins(join_list, 0); sel->prep_where= conds ? conds->copy_andor_structure(thd) : 0; |