[Commits] Rev 2849: Fix LP BUG#680005 in file:///home/tsk/mprog/src/5.3-mwl89-lpb-675981/

timour at askmonty.org timour at askmonty.org
Mon Nov 22 16:32:46 EET 2010


At file:///home/tsk/mprog/src/5.3-mwl89-lpb-675981/

------------------------------------------------------------
revno: 2849
revision-id: timour at askmonty.org-20101122143236-cirfc4rdd4lesh7b
parent: timour at askmonty.org-20101122090745-gxi7sdbdy2u9fkra
committer: timour at askmonty.org
branch nick: 5.3-mwl89-lpb-675981
timestamp: Mon 2010-11-22 16:32:36 +0200
message:
  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.
-------------- next part --------------
=== modified file 'mysql-test/r/subselect4.result'
--- a/mysql-test/r/subselect4.result	2010-11-22 09:07:45 +0000
+++ b/mysql-test/r/subselect4.result	2010-11-22 14:32:36 +0000
@@ -456,6 +456,38 @@ id	select_type	table	type	possible_keys	
 2       DEPENDENT SUBQUERY      t3      ALL     NULL    NULL    NULL    NULL    2       Using where; Using join buffer
 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() 
 #           at field.cc:6833
 #

=== modified file 'mysql-test/t/subselect4.test'
--- a/mysql-test/t/subselect4.test	2010-11-22 09:07:45 +0000
+++ b/mysql-test/t/subselect4.test	2010-11-22 14:32:36 +0000
@@ -419,6 +419,38 @@ WHERE f1 IN (SELECT t1.f2 FROM t1 JOIN t
 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 # BUG#52317: Assertion failing in Field_varstring::store() 
 --echo #            at field.cc:6833
 --echo #

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2010-11-22 09:07:45 +0000
+++ b/sql/sql_select.cc	2010-11-22 14:32:36 +0000
@@ -1747,9 +1747,6 @@ JOIN::exec()
   int      tmp_error;
   DBUG_ENTER("JOIN::exec");
 
-  if (!initialized && init_execution())
-    DBUG_VOID_RETURN;
-
   thd_proc_info(thd, "executing");
   error= 0;
   if (procedure)
@@ -1880,6 +1877,9 @@ JOIN::exec()
     DBUG_VOID_RETURN;
   }
 
+  if (!initialized && init_execution())
+    DBUG_VOID_RETURN;
+
   JOIN *curr_join= this;
   List<Item> *curr_all_fields= &all_fields;
   List<Item> *curr_fields_list= &fields_list;



More information about the commits mailing list