#At file:///work/bzr/mysql-5.1/ based on
revid:joerg@stripped
2858 Gleb Shchepa 2009-05-13
Bug #44290: explain crashes for subquery with distinct in
SQL_SELECT::test_quick_select
The crash was caused by an incomplete cleanup of JOIN_TAB::select
during the filesort of rows for GROUP BY clause inside a subquery.
Queries where a quick index access is replaced with filesort was
was affected. For example:
SELECT 1 FROM
(SELECT COUNT(DISTINCT c1) FROM t1
WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x
Quick index access related data in the SQL_SELECT::test_quick_select
function was inconsistent after an incomplete cleanup.
This function has been completed to prevent crashes in the
SQL_SELECT::test_quick_select function.
@ 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
Quick index access related data in the SQL_SELECT::test_quick_select
function was inconsistent after an incomplete cleanup.
This function has been completed to prevent crashes in the
SQL_SELECT::test_quick_select 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-05-13 07:51:39 +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-05-13 07:51:39 +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 c3,c2 c2 10 NULL 5
+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-29 02:59:10 +0000
+++ b/sql/sql_select.cc 2009-05-13 07:51:39 +0000
@@ -13471,6 +13471,7 @@ create_sort_index(THD *thd, JOIN *join,
{
select->cleanup(); // filesort did select
tab->select= 0;
+ table->quick_keys.clear_all(); // as far as we cleanup select->quick
}
tab->select_cond=0;
tab->last_inner= 0;
Attachment: [text/bzr-bundle] bzr/gshchepa@mysql.com-20090513075139-g50shsfjaf1dstdn.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1 branch (gshchepa:2858) Bug#44290 | Gleb Shchepa | 13 May 2009 |