summaryrefslogtreecommitdiff
path: root/mysql-test/t/join_outer.test
diff options
context:
space:
mode:
authorMartin Hansson <martin.hansson@sun.com>2009-12-17 10:55:18 +0100
committerMartin Hansson <martin.hansson@sun.com>2009-12-17 10:55:18 +0100
commit6863f7dc2d93ef9da13a2c9423eb7d0c92d45636 (patch)
tree444615724273cdd10c11db0ff88eaf5f36cffe48 /mysql-test/t/join_outer.test
parent4621d480fc476127722e7a14656051edebb3673c (diff)
downloadmariadb-git-6863f7dc2d93ef9da13a2c9423eb7d0c92d45636.tar.gz
Bug#47650: using group by with rollup without indexes
returns incorrect results with where An outer join of a const table (outer) and a normal table (inner) with GROUP BY on a field from the outer table would optimize away GROUP BY, and thus trigger the optimization to do away with a temporary table if grouping was performed on columns from the const table, hence executing the query with filesort without temporary table. But this should not be done if there is a non-indexed access to the inner table, since filesort does not handle joins. It expects either ref access, range ditto or table scan. The join condition will thus not be applied. Fixed by always forcing execution with temporary table in the case of ROLLUP with a query involving an outer join. This is a slightly broader class of queries than need fixing, but it is hard to ascertain the position of a ROLLUP field wrt outer join with current query representation. mysql-test/r/join_outer.result: Bug#47650: Test result mysql-test/t/join_outer.test: Bug#47650: Test case sql/sql_select.cc: Bug#47650: Fix
Diffstat (limited to 'mysql-test/t/join_outer.test')
-rw-r--r--mysql-test/t/join_outer.test29
1 files changed, 29 insertions, 0 deletions
diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test
index 35aec71ebb8..aeaa69657c6 100644
--- a/mysql-test/t/join_outer.test
+++ b/mysql-test/t/join_outer.test
@@ -867,3 +867,32 @@ SELECT * FROM t1 LEFT JOIN t2 ON e<>0 WHERE c=1 AND d<=>NULL;
DROP TABLE t1,t2;
+--echo #
+--echo # Bug#47650: using group by with rollup without indexes returns incorrect
+--echo # results with where
+--echo #
+CREATE TABLE t1 ( a INT );
+INSERT INTO t1 VALUES (1);
+
+CREATE TABLE t2 ( a INT, b INT );
+INSERT INTO t2 VALUES (1, 1),(1, 2),(1, 3),(2, 4),(2, 5);
+
+EXPLAIN
+SELECT t1.a, COUNT( t2.b ), SUM( t2.b ), MAX( t2.b )
+FROM t1 LEFT JOIN t2 USING( a )
+GROUP BY t1.a WITH ROLLUP;
+
+SELECT t1.a, COUNT( t2.b ), SUM( t2.b ), MAX( t2.b )
+FROM t1 LEFT JOIN t2 USING( a )
+GROUP BY t1.a WITH ROLLUP;
+
+EXPLAIN
+SELECT t1.a, COUNT( t2.b ), SUM( t2.b ), MAX( t2.b )
+FROM t1 JOIN t2 USING( a )
+GROUP BY t1.a WITH ROLLUP;
+
+SELECT t1.a, COUNT( t2.b ), SUM( t2.b ), MAX( t2.b )
+FROM t1 JOIN t2 USING( a )
+GROUP BY t1.a WITH ROLLUP;
+
+DROP TABLE t1, t2;