Commit da59130e authored by Igor Babaev's avatar Igor Babaev

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.
  
parent 26bd06fe
......@@ -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;
......@@ -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
......
......@@ -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;
......@@ -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;
......
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