diff --git a/mysql-test/r/olap.result b/mysql-test/r/olap.result index 67610108c61..fe83800f658 100644 --- a/mysql-test/r/olap.result +++ b/mysql-test/r/olap.result @@ -360,4 +360,22 @@ SUM(b) COUNT(DISTINCT b) COUNT(*) 6 2 4 4 1 4 14 3 9 +SELECT a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP; +a sum(b) +1 4 +1 4 +2 2 +2 4 +2 6 +4 4 +4 4 +NULL 14 +SELECT DISTINCT a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP; +a sum(b) +1 4 +2 2 +2 4 +2 6 +4 4 +NULL 14 DROP TABLE t1; diff --git a/mysql-test/t/olap.test b/mysql-test/t/olap.test index d2ea582e58c..6778af3d533 100644 --- a/mysql-test/t/olap.test +++ b/mysql-test/t/olap.test @@ -126,7 +126,7 @@ SELECT DROP TABLE user_day; # -# Test for bug #8616: distinct sum with rollup +# Tests for bugs #8616, #8615: distinct sum with rollup # CREATE TABLE t1 (a int, b int); @@ -150,5 +150,8 @@ SELECT SUM(b), COUNT(DISTINCT b), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP; SELECT DISTINCT SUM(b), COUNT(DISTINCT b), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP; +SELECT a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP; +SELECT DISTINCT a, sum(b) FROM t1 GROUP BY a,b WITH ROLLUP; + DROP TABLE t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 0bb4c6a9402..5bfe1346568 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1269,7 +1269,6 @@ JOIN::exec() { DBUG_VOID_RETURN; } - curr_join->group_list= 0; } thd->proc_info="Copying to group table"; @@ -1289,8 +1288,10 @@ JOIN::exec() } } if (curr_join->make_sum_func_list(*curr_all_fields, *curr_fields_list, - 1) || - (tmp_error= do_select(curr_join, (List *) 0, curr_tmp_table, + 1)) + DBUG_VOID_RETURN; + curr_join->group_list= 0; + if ((tmp_error= do_select(curr_join, (List *) 0, curr_tmp_table, 0))) { error= tmp_error;