summaryrefslogtreecommitdiff
path: root/mysql-test/r/func_group.result
diff options
context:
space:
mode:
authorJorgen Loland <jorgen.loland@sun.com>2009-10-14 10:46:50 +0200
committerJorgen Loland <jorgen.loland@sun.com>2009-10-14 10:46:50 +0200
commitbf0aa2bd3460039a0b44d5c0f1411ac2ad47b310 (patch)
tree67e6d2d27354e1926e9f6de44eb1349e9586241a /mysql-test/r/func_group.result
parent0ece5891a28d9e7f8387573a4c69f2c278edd225 (diff)
downloadmariadb-git-bf0aa2bd3460039a0b44d5c0f1411ac2ad47b310.tar.gz
Bug#47280 - strange results from count(*) with order by multiple
columns without where/group Simple SELECT with implicit grouping used to return many rows if the query was ordered by the aggregated column in the SELECT list. This was incorrect because queries with implicit grouping should only return a single record. The problem was that when JOIN:exec() decided if execution needed to handle grouping, it was assumed that sum_func_count==0 meant that there were no aggregate functions in the query. This assumption was not correct in JOIN::exec() because the aggregate functions might have been optimized away during JOIN::optimize(). The reason why queries without ordering behaved correctly was that sum_func_count is only recalculated if the optimizer chooses to use temporary tables (which it does in the ordered case). Hence, non-ordered queries were correctly treated as grouped. The fix for this bug was to remove the assumption that sum_func_count==0 means that there is no need for grouping. This was done by introducing variable "bool implicit_grouping" in the JOIN object.
Diffstat (limited to 'mysql-test/r/func_group.result')
-rw-r--r--mysql-test/r/func_group.result44
1 files changed, 44 insertions, 0 deletions
diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result
index 3d989ad1730..94147640cde 100644
--- a/mysql-test/r/func_group.result
+++ b/mysql-test/r/func_group.result
@@ -1477,3 +1477,47 @@ COUNT(*)
SET SQL_MODE=default;
DROP TABLE t1;
End of 5.0 tests
+#
+# BUG#47280 - strange results from count(*) with order by multiple
+# columns without where/group
+#
+#
+# Initialize test
+#
+CREATE TABLE t1 (
+pk INT NOT NULL,
+i INT,
+PRIMARY KEY (pk)
+);
+INSERT INTO t1 VALUES (1,11),(2,12),(3,13);
+#
+# Start test
+# All the following queries shall return 1 record
+#
+
+# Masking all correct values {11...13} for column i in this result.
+SELECT MAX(pk) as max, i
+FROM t1
+ORDER BY max;
+max i
+3 #
+
+EXPLAIN
+SELECT MAX(pk) as max, i
+FROM t1
+ORDER BY max;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using temporary
+
+# Only 11 is correct for collumn i in this result
+SELECT MAX(pk) as max, i
+FROM t1
+WHERE pk<2
+ORDER BY max;
+max i
+1 11
+#
+# Cleanup
+#
+DROP TABLE t1;
+End of 5.1 tests