mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Bug #30596 GROUP BY optimization gives wrong result order
The optimization that uses a unique index to remove GROUP BY, did not ensure that the index was actually used, thus violating the ORDER BY that is impled by GROUP BY. Fixed by replacing GROUP BY with ORDER BY if the GROUP BY clause contains a unique index. In case GROUP BY ... ORDER BY null is used, GROUP BY is simply removed.
This commit is contained in:
@ -882,4 +882,31 @@ alter table t1 add index(a(1024));
|
||||
show create table t1;
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# Bug#30596: GROUP BY optimization gives wrong result order
|
||||
#
|
||||
CREATE TABLE t1(
|
||||
a INT,
|
||||
b INT NOT NULL,
|
||||
c INT NOT NULL,
|
||||
d INT,
|
||||
UNIQUE KEY (c,b)
|
||||
) engine=innodb;
|
||||
|
||||
INSERT INTO t1 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4);
|
||||
|
||||
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d;
|
||||
SELECT c,b,d FROM t1 GROUP BY c,b,d;
|
||||
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
|
||||
SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
|
||||
EXPLAIN SELECT c,b,d FROM t1 ORDER BY c,b,d;
|
||||
SELECT c,b,d FROM t1 ORDER BY c,b,d;
|
||||
|
||||
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b;
|
||||
SELECT c,b,d FROM t1 GROUP BY c,b;
|
||||
EXPLAIN SELECT c,b FROM t1 GROUP BY c,b;
|
||||
SELECT c,b FROM t1 GROUP BY c,b;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo End of 5.0 tests
|
||||
|
Reference in New Issue
Block a user