From a3ccad0f21e48e30c98f91528e3fcbbf2c1d509a Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 12 Feb 2019 15:38:01 +1100 Subject: [PATCH] Aggregate functions: only create list if args exist Also always empty list rather than only if there is no error. --- sql/item_func.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sql/item_func.cc b/sql/item_func.cc index 72cfd284606..da0e669ae9d 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -6515,17 +6515,20 @@ Item_func_sp::fix_fields(THD *thd, Item **ref) if (m_sp->agg_type() == GROUP_AGGREGATE) { - List list; - list.empty(); - for (uint i=0; i < arg_count; i++) - list.push_back(*(args+i)); - Item_sum_sp *item_sp; Query_arena *arena, backup; arena= thd->activate_stmt_arena_if_needed(&backup); if (arg_count) + { + List list; + list.empty(); + for (uint i=0; i < arg_count; i++) + list.push_back(*(args+i)); + item_sp= new (thd->mem_root) Item_sum_sp(thd, context, m_name, sp, list); + list.empty(); + } else item_sp= new (thd->mem_root) Item_sum_sp(thd, context, m_name, sp); @@ -6539,7 +6542,6 @@ Item_func_sp::fix_fields(THD *thd, Item **ref) if (err) DBUG_RETURN(TRUE); - list.empty(); DBUG_RETURN(FALSE); }