summaryrefslogtreecommitdiff
path: root/mysql-test/t/order_by.test
diff options
context:
space:
mode:
Diffstat (limited to 'mysql-test/t/order_by.test')
-rw-r--r--mysql-test/t/order_by.test57
1 files changed, 57 insertions, 0 deletions
diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test
index 37398616299..71238504d36 100644
--- a/mysql-test/t/order_by.test
+++ b/mysql-test/t/order_by.test
@@ -779,3 +779,60 @@ EXPLAIN SELECT id,c3 FROM t2 WHERE c2 BETWEEN 20 AND 30 ORDER BY c3 LIMIT 4000;
SELECT id,c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 20;
DROP TABLE t1,t2;
+
+#
+# Bug #30665: Inconsistent optimization of IGNORE INDEX FOR {ORDER BY|GROUP BY}
+#
+CREATE TABLE t1 (
+ a INT,
+ b INT,
+ PRIMARY KEY (a),
+ KEY ab(a, b)
+);
+INSERT INTO t1 VALUES (1,1),(2,2),(3,3),(4,4);
+INSERT INTO t1 SELECT a + 4, b + 4 FROM t1;
+INSERT INTO t1 SELECT a + 8, b + 8 FROM t1;
+INSERT INTO t1 SELECT a +16, b +16 FROM t1;
+INSERT INTO t1 SELECT a +32, b +32 FROM t1;
+INSERT INTO t1 SELECT a +64, b +64 FROM t1;
+
+EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR GROUP BY (a, ab) GROUP BY a;
+
+--disable_query_log
+--let $q = `show status like 'Created_tmp_tables';`
+eval set @tmp_tables_before =
+ CAST(REPLACE('$q', 'Created_tmp_tables', '') AS UNSIGNED);
+--enable_query_log
+
+SELECT a FROM t1 IGNORE INDEX FOR GROUP BY (a, ab) GROUP BY a;
+
+# this query creates one temporary table in itself, which we are not
+# interested in.
+
+--disable_query_log
+--let $q = `show status like 'Created_tmp_tables';`
+eval set @tmp_tables_after =
+ CAST(REPLACE('$q', 'Created_tmp_tables', '') AS UNSIGNED);
+--enable_query_log
+
+SELECT @tmp_tables_after = @tmp_tables_before ;
+
+EXPLAIN SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (a, ab) ORDER BY a;
+
+--disable_query_log
+--let $q = `show status like 'Created_tmp_tables';`
+eval set @tmp_tables_before =
+ CAST(REPLACE('$q', 'Created_tmp_tables', '') AS UNSIGNED);
+--enable_query_log
+
+SELECT a FROM t1 IGNORE INDEX FOR ORDER BY (a, ab) ORDER BY a;
+
+--disable_query_log
+--let $q = `show status like 'Created_tmp_tables';`
+eval set @tmp_tables_after =
+ CAST(REPLACE('$q', 'Created_tmp_tables', '') AS UNSIGNED);
+--enable_query_log
+
+SELECT @tmp_tables_after = @tmp_tables_before;
+
+DROP TABLE t1;