summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/include/mix1.inc19
-rw-r--r--mysql-test/r/innodb_mysql.result19
-rw-r--r--sql/sql_select.cc1
3 files changed, 39 insertions, 0 deletions
diff --git a/mysql-test/include/mix1.inc b/mysql-test/include/mix1.inc
index c9cbf2d2839..7c87949830f 100644
--- a/mysql-test/include/mix1.inc
+++ b/mysql-test/include/mix1.inc
@@ -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
diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result
index 3f830378afa..191a8578d4c 100644
--- a/mysql-test/r/innodb_mysql.result
+++ b/mysql-test/r/innodb_mysql.result
@@ -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);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index cdae1581a0c..ab9c060c69c 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -13481,6 +13481,7 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order,
{
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;