Bug #8615 server crash with distinct and rollup (includin aggregate function)
Submitted: 19 Feb 2005 1:21 Modified: 21 Mar 2005 20:01
Reporter: Martin Friebe (Gold Quality Contributor) (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.10 OS:
Assigned to: Igor Babaev

[19 Feb 2005 1:21] Martin Friebe
Description:
please see examples, the indicatd queries crash a mysql 4.1.10 server

How to repeat:
# those work:
#only one row (includes two rollup lines, but we dont see b=null)
select  distinct  a,sum(b) from (select 1  a,2 b) x group by a,b  with rollup;
+---+--------+
| a | sum(b) |
+---+--------+
| 1 |      2 |
| 1 |      2 |
|NULL |      2 |
+---+--------+
3 rows in set (0.00 sec)

# 2 rows, but a and b in result (works
select  distinct  a,b,sum(b) from (select 1  a,2 b union select 1,3) x group by a,b  with rollup;
+---+---+--------+
| a | b | sum(b) |
+---+---+--------+
| 1 | 2 |      2 |
| 1 | 3 |      3 |
| 1 |NULL |      5 |
|NULL |NULL |      5 |
+---+---+--------+
4 rows in set (0.00 sec)

#CRASH
select  distinct  a,sum(b) from (select 1  a,2 b union select 1,3) x group by a,b  
with rollup;

#without rollup (works)
select  distinct  a,sum(b) from (select 1  a,2 b union select 1,3) x group by a,b ;
+---+--------+
| a | sum(b) |
+---+--------+
| 1 |      2 |
| 1 |      3 |
+---+--------+
2 rows in set (0.00 sec)

#also crashes
 select  distinct  sum(b) from (select 1  a,2 b union select 1,3) x group by a,b  with rollup;

# same with a table
create table x (a integer, b integer);
insert into x values (1,4), (2,2),(2,2), (4,1),(4,1),(4,1),(4,1);
select  distinct  sum(b) from (select 1  a,2 b union select 1,3) x group by a,b  with rollup;

Suggested fix:
-
[16 Mar 2005 23:55] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/23119
[20 Mar 2005 8:07] Igor Babaev
This bug is fixed by the patch submitted for bug #8616 and the patch of the changeset specified below.

Both were merged from 4.1 into 5.0.

The fixes will appear in 4.1.11 and 5.0.3.

ChangeSet
  1.2122 05/03/16 15:55:04 igor@rurik.mysql.com +3 -0
  olap.result, olap.test:
    Added a test for bug #8615.
  sql_select.cc:
    Fixed bug #8615.
    This fix only removed the cause of the reported crash.
    It does not resolve other problems of rollup queries
    with DISTINCT. They were fixed in the previous patch 
    for bug 8616.
[21 Mar 2005 20:01] Paul Dubois
Noted in 4.1.11, 5.0.4 changelogs.