List:Commits« Previous MessageNext Message »
From:Gleb Shchepa Date:April 17 2009 7:41pm
Subject:bzr commit into mysql-5.1-bugteam branch (gshchepa:2858) Bug#44290
View as plain text  
#At file:///work/bzr/44290/44290-5.1/ based on revid:davi.arnaut@stripped

 2858 Gleb Shchepa	2009-04-18
      Bug #44290: explain crashes for subquery with distinct in
                  SQL_SELECT::test_quick_select
                  
      The crash was caused by a beforehand cleanup of JOIN_TAB::select
      during the filesort. Queries combining quick index access and
      filesort was affected.
      
      Unnecessary cleanup has been deferred to prevent
      inconsistent join structure passing into
      mysql_explain_union/test_if_skip_sort_order functions.
     @ mysql-test/include/mix1.inc
        Add test case for bug #44290.
     @ mysql-test/r/innodb_mysql.result
        Add test case for bug #44290.
     @ sql/sql_select.cc
        Bug #44290: explain crashes for subquery with distinct in
                    SQL_SELECT::test_quick_select
        
        The create_sort_index function has been modified to defer
        unneeded cleanup and keep consistent quick index access 
        fields till the test_quick_select function call (like
        at the end of the mysql_derived_filling function).

    modified:
      mysql-test/include/mix1.inc
      mysql-test/r/innodb_mysql.result
      sql/sql_select.cc
=== modified file 'mysql-test/include/mix1.inc'
--- a/mysql-test/include/mix1.inc	2009-04-02 08:21:51 +0000
+++ b/mysql-test/include/mix1.inc	2009-04-17 19:41:05 +0000
@@ -1516,4 +1516,23 @@ DROP TABLE t1;
 # DROP TABLE t1;
 #
 
+--echo #
+--echo # Bug #44290: explain crashes for subquery with distinct in
+--echo #             SQL_SELECT::test_quick_select
+--echo #             (reproduced only with InnoDB tables)
+--echo #
+
+eval
+CREATE TABLE t1 (c1 INT, c2 INT, c3 INT, KEY (c3), KEY (c2, c3))
+  ENGINE=$engine_type;
+INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
+
+SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
+                 FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
+EXPLAIN 
+SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
+                 FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
+
+DROP TABLE t1;
+
 --echo End of 5.1 tests

=== modified file 'mysql-test/r/innodb_mysql.result'
--- a/mysql-test/r/innodb_mysql.result	2009-03-30 08:44:17 +0000
+++ b/mysql-test/r/innodb_mysql.result	2009-04-17 19:41:05 +0000
@@ -1687,6 +1687,25 @@ vid	tid	idx	name	type
 3	1	2	c1	NULL
 3	1	1	pk	NULL
 DROP TABLE t1;
+#
+# Bug #44290: explain crashes for subquery with distinct in
+#             SQL_SELECT::test_quick_select
+#             (reproduced only with InnoDB tables)
+#
+CREATE TABLE t1 (c1 INT, c2 INT, c3 INT, KEY (c3), KEY (c2, c3))
+ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
+SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
+FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
+1
+1
+EXPLAIN 
+SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
+FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	
+2	DERIVED	t1	index_merge	c3,c2	c3,c2	5,10	NULL	1	Using intersect(c3,c2); Using where; Using filesort
+DROP TABLE t1;
 End of 5.1 tests
 drop table if exists t1, t2, t3;
 create table t1(a int);

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2009-04-01 11:10:03 +0000
+++ b/sql/sql_select.cc	2009-04-17 19:41:05 +0000
@@ -13211,6 +13211,8 @@ test_if_skip_sort_order(JOIN_TAB *tab,OR
       bool quick_created= FALSE;
       if (table->quick_keys.is_set(best_key) && best_key != ref_key)
       {
+        // for sure, quick_keys map is empty if there is no select->quick
+        DBUG_ASSERT(select && select->quick);
         key_map map;
         map.clear_all();       // Force the creation of quick select
         map.set_bit(best_key); // only best_key.
@@ -13455,7 +13457,7 @@ create_sort_index(THD *thd, JOIN *join, 
                                      select, filesort_limit, 0,
                                      &examined_rows);
   tab->records= table->sort.found_records;	// For SQL_CALC_ROWS
-  if (select)
+  if (select && !thd->lex->describe)
   {
     select->cleanup();				// filesort did select
     tab->select= 0;


Attachment: [text/bzr-bundle] bzr/gshchepa@mysql.com-20090417194105-jwh7wfg6d7a06cl4.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (gshchepa:2858) Bug#44290Gleb Shchepa17 Apr