Commit 08bf28ef authored by unknown's avatar unknown

Fix LP BUG#680005

Analysis:
This another instance of the problem fixed in LP BUG#675981 -
evaluation of subqueries during EXPLAIN when the subquery plan
is incomplete because JOIN::optimize() generally doesn't create
complete execution plans for EXPLAIN statements.

In this case the call path is:
mysql_explain_union -> outer_join.exec -> outer_join.init_execution ->
create_sort_index -> filesort -> find_all_keys ->
SQL_SELECT::skip_record -> outer_where_clause.val_int -> ...
-> subselect_join.exec -> ... -> sub_select_cache

When calling sub_select_cache JOIN_TAB::cache is NULL because the cache
objects are not created for EXPLAIN statements.

Solution:
Delay the call to init_execution() after all EXPLAIN related processing
is completed. Thus init_execution() is not called at all during EXPLAIN.
parent 7fd37390
...@@ -456,6 +456,38 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -456,6 +456,38 @@ id select_type table type possible_keys key key_len ref rows Extra
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer 2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer
drop table t1, t2, t3; drop table t1, t2, t3;
# #
# LP BUG#680005 Second assertion `cache != __null' failed in
# sub_select_cache() on EXPLAIN
#
CREATE TABLE t1 (f1 int,f2 int,f4 int,f6 int,KEY (f4)) ;
INSERT IGNORE INTO t1 VALUES
('1','5','1','0'),('2','1','1','0'),('2','2','2','0'),('0',NULL,'0','0'),
('2','1','2','0'),('2','0','0','0'),('2','2','2','0'),('2','8','2','0'),
('2','7','2','0'),('2','5','2','0'),('2',NULL,'1','0');
CREATE TABLE t2 (f3 int) ;
INSERT IGNORE INTO t2 VALUES ('7');
CREATE TABLE t3 (f3 int) ;
INSERT IGNORE INTO t3 VALUES ('2');
EXPLAIN
SELECT t1.f4
FROM t2 JOIN t1 ON t1.f6
WHERE
( t1.f2 ) IN (SELECT SUBQUERY2_t1.f3
FROM t3 AS SUBQUERY2_t1
JOIN
(t1 AS SUBQUERY2_t2
JOIN
t1 AS SUBQUERY2_t3 ON SUBQUERY2_t3.f1)
ON SUBQUERY2_t3.f2)
GROUP BY t1.f4 ORDER BY t1.f1 LIMIT 10;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t2 system NULL NULL NULL NULL 1 Using temporary; Using filesort
1 PRIMARY t1 index NULL f4 5 NULL 10 Using where
2 DEPENDENT SUBQUERY SUBQUERY2_t1 system NULL NULL NULL NULL 1
2 DEPENDENT SUBQUERY SUBQUERY2_t2 index NULL f4 5 NULL 11 Using where; Using index
2 DEPENDENT SUBQUERY SUBQUERY2_t3 ALL NULL NULL NULL NULL 11 Using where; Using join buffer
drop table t1, t2, t3;
#
# BUG#52317: Assertion failing in Field_varstring::store() # BUG#52317: Assertion failing in Field_varstring::store()
# at field.cc:6833 # at field.cc:6833
# #
......
...@@ -418,6 +418,38 @@ WHERE f1 IN (SELECT t1.f2 FROM t1 JOIN t3 ON t3.f4); ...@@ -418,6 +418,38 @@ WHERE f1 IN (SELECT t1.f2 FROM t1 JOIN t3 ON t3.f4);
drop table t1, t2, t3; drop table t1, t2, t3;
--echo #
--echo # LP BUG#680005 Second assertion `cache != __null' failed in
--echo # sub_select_cache() on EXPLAIN
--echo #
CREATE TABLE t1 (f1 int,f2 int,f4 int,f6 int,KEY (f4)) ;
INSERT IGNORE INTO t1 VALUES
('1','5','1','0'),('2','1','1','0'),('2','2','2','0'),('0',NULL,'0','0'),
('2','1','2','0'),('2','0','0','0'),('2','2','2','0'),('2','8','2','0'),
('2','7','2','0'),('2','5','2','0'),('2',NULL,'1','0');
CREATE TABLE t2 (f3 int) ;
INSERT IGNORE INTO t2 VALUES ('7');
CREATE TABLE t3 (f3 int) ;
INSERT IGNORE INTO t3 VALUES ('2');
EXPLAIN
SELECT t1.f4
FROM t2 JOIN t1 ON t1.f6
WHERE
( t1.f2 ) IN (SELECT SUBQUERY2_t1.f3
FROM t3 AS SUBQUERY2_t1
JOIN
(t1 AS SUBQUERY2_t2
JOIN
t1 AS SUBQUERY2_t3 ON SUBQUERY2_t3.f1)
ON SUBQUERY2_t3.f2)
GROUP BY t1.f4 ORDER BY t1.f1 LIMIT 10;
drop table t1, t2, t3;
--echo # --echo #
--echo # BUG#52317: Assertion failing in Field_varstring::store() --echo # BUG#52317: Assertion failing in Field_varstring::store()
--echo # at field.cc:6833 --echo # at field.cc:6833
......
...@@ -1747,9 +1747,6 @@ JOIN::exec() ...@@ -1747,9 +1747,6 @@ JOIN::exec()
int tmp_error; int tmp_error;
DBUG_ENTER("JOIN::exec"); DBUG_ENTER("JOIN::exec");
if (!initialized && init_execution())
DBUG_VOID_RETURN;
thd_proc_info(thd, "executing"); thd_proc_info(thd, "executing");
error= 0; error= 0;
if (procedure) if (procedure)
...@@ -1880,6 +1877,9 @@ JOIN::exec() ...@@ -1880,6 +1877,9 @@ JOIN::exec()
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
if (!initialized && init_execution())
DBUG_VOID_RETURN;
JOIN *curr_join= this; JOIN *curr_join= this;
List<Item> *curr_all_fields= &all_fields; List<Item> *curr_all_fields= &all_fields;
List<Item> *curr_fields_list= &fields_list; List<Item> *curr_fields_list= &fields_list;
......
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