summaryrefslogtreecommitdiff
path: root/sql/item_sum.cc
diff options
context:
space:
mode:
authorTor Didriksen <tor.didriksen@sun.com>2009-10-28 11:07:30 +0100
committerTor Didriksen <tor.didriksen@sun.com>2009-10-28 11:07:30 +0100
commitb2baeed4a7a19ee498e963fe374cf254d230d2bc (patch)
tree569cf4691c918df46c9d933b2e5ef9f56a1217b4 /sql/item_sum.cc
parent55b8f07a9922f26cc64dbeac2f1cb78519621f16 (diff)
downloadmariadb-git-b2baeed4a7a19ee498e963fe374cf254d230d2bc.tar.gz
Bug#48060 Memory leak - Item::val_bool() (item.cc:184) from optimizer_subquery grammar
Item_sum::set_aggregator() may be called multiple times during query preparation. On subsequent calls: verify that the aggregator type is the same, and re-use the existing Aggregator. sql/item_sum.cc: In Item_sum::set_aggregator(): re-use existing Aggregator if already set. Remove some friend declarations, add some accessor functions. Cleanup some DBUG_ENTER and DBUG_RETURN code. sql/item_sum.h: Make some member fields private, add accessors instead. Remove some un-necessary friend declarations. Remove some default arguments from constructors. sql/opt_sum.cc: Use accessor functions in Item_sum. sql/sql_select.cc: Fix mis-spelled DBUG_ENTER text. Use accessor functions in Item_sum. sql/sql_yacc.yy: Use explicit true/false rather than default arguments when constructing Item_sum_xxx objects.
Diffstat (limited to 'sql/item_sum.cc')
-rw-r--r--sql/item_sum.cc25
1 files changed, 15 insertions, 10 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index c8576722c69..273e996a6a0 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -564,6 +564,11 @@ Item *Item_sum::set_arg(uint i, THD *thd, Item *new_val)
int Item_sum::set_aggregator(Aggregator::Aggregator_type aggregator)
{
+ if (aggr)
+ {
+ DBUG_ASSERT(aggregator == aggr->Aggrtype());
+ return FALSE;
+ }
switch (aggregator)
{
case Aggregator::DISTINCT_AGGREGATOR:
@@ -736,12 +741,12 @@ bool Aggregator_distinct::setup(THD *thd)
if (list.push_back(item))
return TRUE; // End of memory
if (item->const_item() && item->is_null())
- always_null=1;
+ always_null= true;
}
if (always_null)
return FALSE;
- count_field_types(select_lex,tmp_table_param,list,0);
- tmp_table_param->force_copy_fields= item_sum->force_copy_fields;
+ count_field_types(select_lex, tmp_table_param, list, 0);
+ tmp_table_param->force_copy_fields= item_sum->has_force_copy_fields();
DBUG_ASSERT(table == 0);
/*
Make create_tmp_table() convert BIT columns to BIGINT.
@@ -844,10 +849,10 @@ bool Aggregator_distinct::setup(THD *thd)
List<Create_field> field_list;
Create_field field_def; /* field definition */
Item *arg;
- DBUG_ENTER("Item_sum_distinct::setup");
+ DBUG_ENTER("Aggregator_distinct::setup");
/* It's legal to call setup() more than once when in a subquery */
if (tree)
- return FALSE;
+ DBUG_RETURN(FALSE);
/*
Virtual table and the tree are created anew on each re-execution of
@@ -855,23 +860,23 @@ bool Aggregator_distinct::setup(THD *thd)
mem_root.
*/
if (field_list.push_back(&field_def))
- return TRUE;
+ DBUG_RETURN(TRUE);
item_sum->null_value= item_sum->maybe_null= 1;
item_sum->quick_group= 0;
DBUG_ASSERT(item_sum->get_arg(0)->fixed);
- arg = item_sum->get_arg(0);
+ arg= item_sum->get_arg(0);
if (arg->const_item())
{
(void) arg->val_int();
if (arg->null_value)
- always_null=1;
+ always_null= true;
}
if (always_null)
- return FALSE;
+ DBUG_RETURN(FALSE);
enum enum_field_types field_type;
@@ -884,7 +889,7 @@ bool Aggregator_distinct::setup(THD *thd)
arg->unsigned_flag);
if (! (table= create_virtual_tmp_table(thd, field_list)))
- return TRUE;
+ DBUG_RETURN(TRUE);
/* XXX: check that the case of CHAR(0) works OK */
tree_key_length= table->s->reclength - table->s->null_bytes;