summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <evgen@moonbone.local>2006-09-29 20:02:53 +0400
committerunknown <evgen@moonbone.local>2006-09-29 20:02:53 +0400
commitda9f990b5480645014f982fe5c2b1880ce54b314 (patch)
tree9ac98a7a0d43988b14f38280adabfe7dafd1623c
parentb8fe620615adb5a5ab6804689e5111b4d9952c2e (diff)
downloadmariadb-git-da9f990b5480645014f982fe5c2b1880ce54b314.tar.gz
Fixed bug#20825: rollup puts non-equal values together
Fix for bug 7894 replaces a field(s) in a non-aggregate function with a item reference if such a field was specified in the GROUP BY clause in order to get a correct result. When ROLLUP is involved this lead to a wrong result due to value of a such field is got through a copy function and copying happens after the function evaluation. Such replacement isn't needed if grouping is also done by such a function. The change_group_ref() function now isn't called for a function present in the group list. mysql-test/t/olap.test: Added the test case for the bug#20825: rollup puts non-equal values together mysql-test/r/olap.result: Added the test case for the bug#20825: rollup puts non-equal values together sql/sql_select.cc: Fixed bug#20825: rollup puts non-equal values together The change_group_ref() function now isn't called for a function present in the group list.
-rw-r--r--mysql-test/r/olap.result15
-rw-r--r--mysql-test/t/olap.test9
-rw-r--r--sql/sql_select.cc7
3 files changed, 30 insertions, 1 deletions
diff --git a/mysql-test/r/olap.result b/mysql-test/r/olap.result
index fef990297d9..74b7570ea2a 100644
--- a/mysql-test/r/olap.result
+++ b/mysql-test/r/olap.result
@@ -541,3 +541,18 @@ a max(b)
NULL 2
a 1
drop table t1;
+create table t1 (a varchar(22) not null , b int);
+insert into t1 values ("2006-07-01 21:30", 1), ("2006-07-01 23:30", 10);
+select left(a,10), a, sum(b) from t1 group by 1,2 with rollup;
+left(a,10) a sum(b)
+2006-07-01 2006-07-01 21:30 1
+2006-07-01 2006-07-01 23:30 10
+2006-07-01 NULL 11
+NULL NULL 11
+select left(a,10) x, a, sum(b) from t1 group by x,a with rollup;
+x a sum(b)
+2006-07-01 2006-07-01 21:30 1
+2006-07-01 2006-07-01 23:30 10
+2006-07-01 NULL 11
+NULL NULL 11
+drop table t1;
diff --git a/mysql-test/t/olap.test b/mysql-test/t/olap.test
index 4f9790b0de6..683e1402678 100644
--- a/mysql-test/t/olap.test
+++ b/mysql-test/t/olap.test
@@ -272,4 +272,13 @@ select a, max(b) from t1 group by a with rollup;
select distinct a, max(b) from t1 group by a with rollup;
drop table t1;
+#
+# Bug #20825: rollup puts non-equal values together
+#
+create table t1 (a varchar(22) not null , b int);
+insert into t1 values ("2006-07-01 21:30", 1), ("2006-07-01 23:30", 10);
+select left(a,10), a, sum(b) from t1 group by 1,2 with rollup;
+select left(a,10) x, a, sum(b) from t1 group by x,a with rollup;
+drop table t1;
+
# End of 4.1 tests
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 74a9fc573c4..57b7fcceebe 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -9706,12 +9706,17 @@ bool JOIN::rollup_init()
while ((item= it++))
{
ORDER *group_tmp;
+ bool found_in_group= 0;
+
for (group_tmp= group_list; group_tmp; group_tmp= group_tmp->next)
{
if (*group_tmp->item == item)
+ {
item->maybe_null= 1;
+ found_in_group= 1;
+ }
}
- if (item->type() == Item::FUNC_ITEM)
+ if (item->type() == Item::FUNC_ITEM && !found_in_group)
{
bool changed= FALSE;
if (change_group_ref(thd, (Item_func *) item, group_list, &changed))