From d99370dd1b2d5e85c36ed45a9f7758c3d2ebb35c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Mar 2003 22:52:46 +0200 Subject: [PATCH] A fix for bug #176 code cleanup mysql-test/r/having.result: A test for the bug fix for bug #176 mysql-test/t/having.test: A test for the bug fix for bug #176 sql/item.cc: A for the bug #176 sql/item_func.cc: Code cleanup --- mysql-test/r/having.result | 7 +++++++ mysql-test/t/having.test | 4 ++++ sql/item.cc | 1 + sql/item_func.cc | 37 ++++++++++++++++++++----------------- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/mysql-test/r/having.result b/mysql-test/r/having.result index a33ce457176..f113eb6ed49 100644 --- a/mysql-test/r/having.result +++ b/mysql-test/r/having.result @@ -63,3 +63,10 @@ Fld1 max(Fld2) 1 20 3 50 drop table t1; +create table t1 (id int not null, qty int not null); +insert into t1 values (1,2),(1,3),(2,4),(2,5); +select id, sum(qty) as sqty from t1 group by id having sqty>2; +id sqty +1 5 +2 9 +drop table t1; diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test index 8dd7606d82b..fd972fea1ad 100644 --- a/mysql-test/t/having.test +++ b/mysql-test/t/having.test @@ -60,3 +60,7 @@ select Fld1, max(Fld2) from t1 group by Fld1 having max(Fld2) is not null; select Fld1, max(Fld2) from t1 group by Fld1 having avg(Fld2) is not null; select Fld1, max(Fld2) from t1 group by Fld1 having std(Fld2) is not null; drop table t1; +create table t1 (id int not null, qty int not null); +insert into t1 values (1,2),(1,3),(2,4),(2,5); +select id, sum(qty) as sqty from t1 group by id having sqty>2; +drop table t1; diff --git a/sql/item.cc b/sql/item.cc index 0046f53c6fb..4fefae7358f 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -665,6 +665,7 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables) maybe_null= (*ref)->maybe_null; decimals= (*ref)->decimals; binary= (*ref)->binary; + with_sum_func= (*ref)->with_sum_func; } return 0; } diff --git a/sql/item_func.cc b/sql/item_func.cc index 15018085146..6c23b0aa424 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -70,15 +70,16 @@ Item_func::fix_fields(THD *thd,TABLE_LIST *tables) { // Print purify happy for (arg=args, arg_end=args+arg_count; arg != arg_end ; arg++) { - if ((*arg)->fix_fields(thd,tables)) + Item *item=*arg; + if (item->fix_fields(thd,tables)) return 1; /* purecov: inspected */ - if ((*arg)->maybe_null) + if (item->maybe_null) maybe_null=1; - if ((*arg)->binary) + if (item->binary) binary=1; - with_sum_func= with_sum_func || (*arg)->with_sum_func; - used_tables_cache|=(*arg)->used_tables(); - const_item_cache&= (*arg)->const_item(); + with_sum_func= with_sum_func || item->with_sum_func; + used_tables_cache|=item->used_tables(); + const_item_cache&= item->const_item(); } } fix_length_and_dec(); @@ -91,12 +92,13 @@ void Item_func::split_sum_func(List &fields) Item **arg,**arg_end; for (arg=args, arg_end=args+arg_count; arg != arg_end ; arg++) { - if ((*arg)->with_sum_func && (*arg)->type() != SUM_FUNC_ITEM) - (*arg)->split_sum_func(fields); - else if ((*arg)->used_tables() || (*arg)->type() == SUM_FUNC_ITEM) + Item *item=*arg; + if (item->with_sum_func && item->type() != SUM_FUNC_ITEM) + item->split_sum_func(fields); + else if (item->used_tables() || item->type() == SUM_FUNC_ITEM) { fields.push_front(*arg); - *arg=new Item_ref((Item**) fields.head_ref(),0,(*arg)->name); + *arg=new Item_ref((Item**) fields.head_ref(),0,item->name); } } } @@ -1231,16 +1233,17 @@ udf_handler::fix_fields(THD *thd,TABLE_LIST *tables,Item_result_field *func, arg != arg_end ; arg++,i++) { - if ((*arg)->fix_fields(thd,tables)) + Item *item=*arg; + if (item->fix_fields(thd,tables)) return 1; - if ((*arg)->binary) + if (item->binary) func->binary=1; - if ((*arg)->maybe_null) + if (item->maybe_null) func->maybe_null=1; - func->with_sum_func= func->with_sum_func || (*arg)->with_sum_func; - used_tables_cache|=(*arg)->used_tables(); - const_item_cache&=(*arg)->const_item(); - f_args.arg_type[i]=(*arg)->result_type(); + func->with_sum_func= func->with_sum_func || item->with_sum_func; + used_tables_cache|=item->used_tables(); + const_item_cache&=item->const_item(); + f_args.arg_type[i]=item->result_type(); } if (!(buffers=new String[arg_count]) || !(f_args.args= (char**) sql_alloc(arg_count * sizeof(char *))) ||