mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Fix for BUG#14920 Ordering aggregated result sets corrupts resultset.
The cause of the bug was the use of end_write_group instead of end_write in the case when ORDER BY required a temporary table, which didn't take into account the fact that loose index scan already computes the result of MIN/MAX aggregate functions (and performs grouping). The solution is to call end_write instead of end_write_group and to add the MIN/MAX functions to the list of regular functions so that their values are inserted into the temporary table.
This commit is contained in:
@@ -2002,3 +2002,34 @@ a count(a)
|
||||
1 1
|
||||
NULL 1
|
||||
drop table t1;
|
||||
create table t1 (c1 int not null,c2 int not null, primary key(c1,c2));
|
||||
insert into t1 (c1,c2) values
|
||||
(10,1),(10,2),(10,3),(20,4),(20,5),(20,6),(30,7),(30,8),(30,9);
|
||||
select distinct c1, c2 from t1 order by c2;
|
||||
c1 c2
|
||||
10 1
|
||||
10 2
|
||||
10 3
|
||||
20 4
|
||||
20 5
|
||||
20 6
|
||||
30 7
|
||||
30 8
|
||||
30 9
|
||||
select c1,min(c2) as c2 from t1 group by c1 order by c2;
|
||||
c1 c2
|
||||
10 1
|
||||
20 4
|
||||
30 7
|
||||
select c1,c2 from t1 group by c1,c2 order by c2;
|
||||
c1 c2
|
||||
10 1
|
||||
10 2
|
||||
10 3
|
||||
20 4
|
||||
20 5
|
||||
20 6
|
||||
30 7
|
||||
30 8
|
||||
30 9
|
||||
drop table t1;
|
||||
|
@@ -693,3 +693,16 @@ create table t1(a int, key(a)) engine=innodb;
|
||||
insert into t1 values(1);
|
||||
select a, count(a) from t1 group by a with rollup;
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# Bug #14920 Ordering aggregated result sets with composite primary keys
|
||||
# corrupts resultset
|
||||
#
|
||||
|
||||
create table t1 (c1 int not null,c2 int not null, primary key(c1,c2));
|
||||
insert into t1 (c1,c2) values
|
||||
(10,1),(10,2),(10,3),(20,4),(20,5),(20,6),(30,7),(30,8),(30,9);
|
||||
select distinct c1, c2 from t1 order by c2;
|
||||
select c1,min(c2) as c2 from t1 group by c1 order by c2;
|
||||
select c1,c2 from t1 group by c1,c2 order by c2;
|
||||
drop table t1;
|
||||
|
Reference in New Issue
Block a user