From 1586eea57340cd1a202845775f285ce6acdb9c08 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 May 2005 17:32:46 +0300 Subject: [PATCH] Fixed bugs 9820, 9799 and 9800. mysql-test/r/select.result: Added test cases for bugs 9799, 9800 and 9820 mysql-test/t/select.test: Added test cases for bugs 9799, 9800 and 9820 --- mysql-test/r/select.result | 21 +++++++++++++++++++++ mysql-test/t/select.test | 27 +++++++++++++++++++++++++++ sql/item_sum.cc | 7 ++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index ff45eff68da..fd67903a576 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2455,3 +2455,24 @@ a select x.a, y.a, z.a from ( (t1 x inner join t2 y on x.a=y.a) inner join t2 z on y.a=z.a) WHERE x.a=1; a a a drop table t1,t2; +create table t1 (s1 varchar(5)); +insert into t1 values ('Wall'); +select min(s1) from t1 group by s1 with rollup; +min(s1) +Wall +Wall +drop table t1; +create table t1 (s1 int) engine=myisam; +insert into t1 values (0); +select avg(distinct s1) from t1 group by s1 with rollup; +avg(distinct s1) +0.0000 +0.0000 +drop table t1; +create table t1 (s1 int); +insert into t1 values (null),(1); +select distinct avg(s1) as x from t1 group by s1 with rollup; +x +NULL +1.0000 +drop table t1; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index a92c8ffdc66..64f6674181c 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2029,3 +2029,30 @@ select t1.a from (t1 inner join t2 on t1.a=t2.a) where t2.a=1; select t1.a from ((t1 inner join t2 on t1.a=t2.a)) where t2.a=1; select x.a, y.a, z.a from ( (t1 x inner join t2 y on x.a=y.a) inner join t2 z on y.a=z.a) WHERE x.a=1; drop table t1,t2; + +# +# Bug#9820 +# + +create table t1 (s1 varchar(5)); +insert into t1 values ('Wall'); +select min(s1) from t1 group by s1 with rollup; +drop table t1; + +# +# Bug#9799 +# + +create table t1 (s1 int) engine=myisam; +insert into t1 values (0); +select avg(distinct s1) from t1 group by s1 with rollup; +drop table t1; + +# +# Bug#9800 +# + +create table t1 (s1 int); +insert into t1 values (null),(1); +select distinct avg(s1) as x from t1 group by s1 with rollup; +drop table t1; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index a7bc08ea170..76bf8189a0e 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -240,6 +240,8 @@ Item_sum_hybrid::Item_sum_hybrid(THD *thd, Item_sum_hybrid *item) case REAL_RESULT: sum= item->sum; break; + case STRING_RESULT: // This can happen with ROLLUP. Note that the value is already + break; // copied at function call. case ROW_RESULT: default: DBUG_ASSERT(0); @@ -585,7 +587,10 @@ bool Item_sum_distinct::setup(THD *thd) DBUG_ENTER("Item_sum_distinct::setup"); - DBUG_ASSERT(tree == 0); /* setup can not be called twice */ + /* + Setup can be called twice for ROLLUP items. This is a bug. + Please add DBUG_ASSERT(tree == 0) here when it's fixed. + */ /* Virtual table and the tree are created anew on each re-execution of