From d89b2a9f1d23fe6e3cc877c23b3235b0a0782323 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 4 Sep 2003 06:44:16 +0600 Subject: [PATCH] BUG correct bug 1085 (a problem with min/max functions) add tests of bugs 833,836,1085 mysql-test/r/func_gconcat.result: add tests of bugs 833, 836, 1085 mysql-test/t/func_gconcat.test: add tests of bugs #833, 836, 1085 sql/item_sum.cc: merge sql/item_sum.h: correct bug 1085 --- mysql-test/r/func_gconcat.result | 18 ++++++++++++++++++ mysql-test/t/func_gconcat.test | 21 +++++++++++++++++++++ sql/item_sum.cc | 8 ++++---- sql/item_sum.h | 4 ++-- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/func_gconcat.result b/mysql-test/r/func_gconcat.result index a4493e7c95c..5c3c2f10000 100644 --- a/mysql-test/r/func_gconcat.result +++ b/mysql-test/r/func_gconcat.result @@ -167,6 +167,11 @@ t2.URL_ID = t1.URL_ID group by REQ_ID; REQ_ID URL 1 X 5 X,X,X +select REQ_ID, Group_Concat(URL) as URL, Min(t1.URL_ID) urll, +Max(t1.URL_ID) urlg from t1, t2 where t2.URL_ID = t1.URL_ID group by REQ_ID; +REQ_ID URL urll urlg +1 X 4 4 +5 X,X,X 4 5 drop table t1; drop table t2; create table t1 (id int, name varchar(16)); @@ -178,3 +183,16 @@ select distinct ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') a with distinct: cutoff at length of shortname 1:longername,1:evenlongername drop table t1; +create table t1(id int); +create table t2(id int); +insert into t1 values(0),(1); +select group_concat(t1.id) FROM t1,t2; +group_concat(t1.id) +NULL +drop table t1; +drop table t2; +create table t1 (bar varchar(32)); +insert into t1 values('test'),('test2'); +select * from t1 having group_concat(bar)=''; +bar +drop table t1; diff --git a/mysql-test/t/func_gconcat.test b/mysql-test/t/func_gconcat.test index f426f9ca4ee..b10f6d2af21 100644 --- a/mysql-test/t/func_gconcat.test +++ b/mysql-test/t/func_gconcat.test @@ -91,6 +91,11 @@ insert into t2 values (1,4), (5,4), (5,5); --replace_result www.help.com X www.host.com X www.google.com X select REQ_ID, Group_Concat(URL) as URL from t1, t2 where t2.URL_ID = t1.URL_ID group by REQ_ID; +# check min/max function +--replace_result www.help.com X www.host.com X www.google.com X +select REQ_ID, Group_Concat(URL) as URL, Min(t1.URL_ID) urll, +Max(t1.URL_ID) urlg from t1, t2 where t2.URL_ID = t1.URL_ID group by REQ_ID; + drop table t1; drop table t2; @@ -99,3 +104,19 @@ insert into t1 values (1,'longername'),(1,'evenlongername'); select ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'without distinct: how it should be' from t1; select distinct ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'with distinct: cutoff at length of shortname' from t1; drop table t1; + +# check zero rows +create table t1(id int); +create table t2(id int); +insert into t1 values(0),(1); +select group_concat(t1.id) FROM t1,t2; +drop table t1; +drop table t2; + +# check having +create table t1 (bar varchar(32)); +insert into t1 values('test'),('test2'); +select * from t1 having group_concat(bar)=''; +drop table t1; + + diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 07e62ae35de..814612cfca8 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1460,7 +1460,7 @@ int group_concat_key_cmp_with_distinct(void* arg, byte* key1, for (uint i= 0; i < item->arg_count_field; i++) { Item *field_item= item->args[i]; - Field *field= field_item->real_item()->tmp_table_field(); + Field *field= field_item->real_item()->get_tmp_table_field(); if (field) { uint offset= field->abs_offset; @@ -1491,7 +1491,7 @@ int group_concat_key_cmp_with_order(void* arg, byte* key1, byte* key2) { ORDER *order_item= item->order[i]; Item *item= *order_item->item; - Field *field= item->real_item()->tmp_table_field(); + Field *field= item->real_item()->get_tmp_table_field(); if (field) { uint offset= field->abs_offset; @@ -1542,7 +1542,7 @@ int dump_leaf_key(byte* key, uint32 count __attribute__((unused)), Item *show_item= group_concat_item->args[i]; if (!show_item->const_item()) { - Field *f= show_item->real_item()->tmp_table_field(); + Field *f= show_item->real_item()->get_tmp_table_field(); char *sv= f->ptr; f->ptr= (char *)key + f->abs_offset; String *res= f->val_str(&tmp,&tmp2); @@ -1709,7 +1709,7 @@ bool Item_func_group_concat::add() Item *show_item= args[i]; if (!show_item->const_item()) { - Field *f= show_item->real_item()->tmp_table_field(); + Field *f= show_item->real_item()->get_tmp_table_field(); if (!f->is_null()) { record_is_null= FALSE; diff --git a/sql/item_sum.h b/sql/item_sum.h index 7dca0502cb0..b2377a96833 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -386,8 +386,8 @@ class Item_sum_hybrid :public Item_sum Item_sum_hybrid(THD *thd, Item_sum_hybrid &item): Item_sum(thd, item), value(item.value), tmp_value(item.tmp_value), sum(item.sum), sum_int(item.sum_int), hybrid_type(item.hybrid_type), - cmp_sign(item.cmp_sign), used_table_cache(used_table_cache), - cmp_charset(item.cmp_charset) {} + hybrid_field_type(item.hybrid_field_type),cmp_sign(item.cmp_sign), + used_table_cache(used_table_cache), cmp_charset(item.cmp_charset) {} bool fix_fields(THD *, TABLE_LIST *, Item **); table_map used_tables() const { return used_table_cache; } bool const_item() const { return !used_table_cache; }