From 607030266f83a3b81cddf40ca05245381600fdf4 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 1 Jul 2005 07:40:22 -0700 Subject: [PATCH] olap.result, olap.test: Added a test case for bug #11543. sql_select.cc: Fixed bug #11543. A ROLLUP query could return a wrong result set when its GROUP BY clause contained references to the same column. sql/sql_select.cc: Fixed bug #11543. A ROLLUP query could return a wrong result set when its GROUP BY clause contained references to the same column. mysql-test/t/olap.test: Added a test case for bug #11543. mysql-test/r/olap.result: Added a test case for bug #11543. --- mysql-test/r/olap.result | 12 ++++++++++++ mysql-test/t/olap.test | 11 +++++++++++ sql/sql_select.cc | 4 ++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/olap.result b/mysql-test/r/olap.result index 0c6c4684853..7178895cf80 100644 --- a/mysql-test/r/olap.result +++ b/mysql-test/r/olap.result @@ -504,3 +504,15 @@ IFNULL(a, 'TEST') COALESCE(b, 'TEST') 4 TEST TEST TEST DROP TABLE t1,t2; +CREATE TABLE t1 (a INT(10) NOT NULL, b INT(10) NOT NULL); +INSERT INTO t1 VALUES (1, 1); +INSERT INTO t1 VALUES (1, 2); +SELECT a, b, a AS c, COUNT(*) AS count FROM t1 GROUP BY a, b, c WITH ROLLUP; +a b c count +1 1 1 1 +1 1 NULL 1 +1 2 1 1 +1 2 NULL 1 +1 NULL NULL 2 +NULL NULL NULL 2 +DROP TABLE t1; diff --git a/mysql-test/t/olap.test b/mysql-test/t/olap.test index b9387d15320..9e6adffffcf 100644 --- a/mysql-test/t/olap.test +++ b/mysql-test/t/olap.test @@ -238,3 +238,14 @@ SELECT IFNULL(a, 'TEST'), COALESCE(b, 'TEST') FROM t2 DROP TABLE t1,t2; +# +# Test for bug #11543: ROLLUP query with a repeated column in GROUP BY +# + +CREATE TABLE t1 (a INT(10) NOT NULL, b INT(10) NOT NULL); +INSERT INTO t1 VALUES (1, 1); +INSERT INTO t1 VALUES (1, 2); + +SELECT a, b, a AS c, COUNT(*) AS count FROM t1 GROUP BY a, b, c WITH ROLLUP; + +DROP TABLE t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 044dc60e4b6..5866585bb60 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -9322,7 +9322,7 @@ bool JOIN::rollup_init() ORDER *group_tmp; for (group_tmp= group_list; group_tmp; group_tmp= group_tmp->next) { - if (item->eq(*group_tmp->item,0)) + if (*group_tmp->item == item) item->maybe_null= 1; } if (item->type() == Item::FUNC_ITEM) @@ -9444,7 +9444,7 @@ bool JOIN::rollup_make_fields(List &fields_arg, List &sel_fields, for (group_tmp= start_group, i= pos ; group_tmp ; group_tmp= group_tmp->next, i++) { - if (item->eq(*group_tmp->item,0)) + if (*group_tmp->item == item) { /* This is an element that is used by the GROUP BY and should be