summaryrefslogtreecommitdiff
path: root/sql/item_sum.cc
diff options
context:
space:
mode:
authorunknown <gkodinov/kgeorge@magare.gmz>2007-03-26 17:03:57 +0300
committerunknown <gkodinov/kgeorge@magare.gmz>2007-03-26 17:03:57 +0300
commit9887430fc0220b60f2db33d611e90aa939923811 (patch)
tree6d00e687736fd42c31993c71c3b97e223e0f46ae /sql/item_sum.cc
parenta88dac081ec84e28d5143e9e7ac5b5bfa3ddfb02 (diff)
parentec5051fff447914216c87378930d6234735da3a7 (diff)
downloadmariadb-git-9887430fc0220b60f2db33d611e90aa939923811.tar.gz
Merge magare.gmz:/home/kgeorge/mysql/work/WL3527-5.0-opt
into magare.gmz:/home/kgeorge/mysql/work/WL3527-5.1-opt mysql-test/r/gis.result: Auto merged mysql-test/t/gis.test: Auto merged sql/field.h: Auto merged sql/item.cc: Auto merged sql/item_sum.cc: Auto merged sql/item_sum.h: Auto merged sql/sql_class.h: Auto merged sql/sql_delete.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_select.cc: Auto merged mysql-test/r/subselect.result: merge 5.0-opt -> 5.1-opt mysql-test/t/subselect.test: merge 5.0-opt -> 5.1-opt sql/sql_base.cc: merge 5.0-opt -> 5.1-opt
Diffstat (limited to 'sql/item_sum.cc')
-rw-r--r--sql/item_sum.cc34
1 files changed, 18 insertions, 16 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index cd67f83af17..8965a5a8f8c 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -61,9 +61,9 @@ bool Item_sum::init_sum_func_check(THD *thd)
/* Save a pointer to object to be used in items for nested set functions */
thd->lex->in_sum_func= this;
nest_level= thd->lex->current_select->nest_level;
- nest_level_tables_count= thd->lex->current_select->join->tables;
ref_by= 0;
aggr_level= -1;
+ aggr_sel= NULL;
max_arg_level= -1;
max_sum_func_level= -1;
return FALSE;
@@ -151,7 +151,10 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref)
invalid= aggr_level < 0 && !(allow_sum_func & (1 << nest_level));
}
if (!invalid && aggr_level < 0)
+ {
aggr_level= nest_level;
+ aggr_sel= thd->lex->current_select;
+ }
/*
By this moment we either found a subquery where the set function is
to be aggregated and assigned a value that is >= 0 to aggr_level,
@@ -212,7 +215,6 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref)
bool Item_sum::register_sum_func(THD *thd, Item **ref)
{
SELECT_LEX *sl;
- SELECT_LEX *aggr_sl= NULL;
nesting_map allow_sum_func= thd->lex->allow_sum_func;
for (sl= thd->lex->current_select->master_unit()->outer_select() ;
sl && sl->nest_level > max_arg_level;
@@ -222,7 +224,7 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref)
{
/* Found the most nested subquery where the function can be aggregated */
aggr_level= sl->nest_level;
- aggr_sl= sl;
+ aggr_sel= sl;
}
}
if (sl && (allow_sum_func & (1 << sl->nest_level)))
@@ -233,21 +235,22 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref)
The set function will be aggregated in this subquery.
*/
aggr_level= sl->nest_level;
- aggr_sl= sl;
+ aggr_sel= sl;
+
}
if (aggr_level >= 0)
{
ref_by= ref;
- /* Add the object to the list of registered objects assigned to aggr_sl */
- if (!aggr_sl->inner_sum_func_list)
+ /* Add the object to the list of registered objects assigned to aggr_sel */
+ if (!aggr_sel->inner_sum_func_list)
next= this;
else
{
- next= aggr_sl->inner_sum_func_list->next;
- aggr_sl->inner_sum_func_list->next= this;
+ next= aggr_sel->inner_sum_func_list->next;
+ aggr_sel->inner_sum_func_list->next= this;
}
- aggr_sl->inner_sum_func_list= this;
- aggr_sl->with_sum_func= 1;
+ aggr_sel->inner_sum_func_list= this;
+ aggr_sel->with_sum_func= 1;
/*
Mark Item_subselect(s) as containing aggregate function all the way up
@@ -265,11 +268,11 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref)
has aggregate functions directly referenced (i.e. not through a sub-select).
*/
for (sl= thd->lex->current_select;
- sl && sl != aggr_sl && sl->master_unit()->item;
+ sl && sl != aggr_sel && sl->master_unit()->item;
sl= sl->master_unit()->outer_select() )
sl->master_unit()->item->with_sum_func= 1;
}
- thd->lex->current_select->mark_as_dependent(aggr_sl);
+ thd->lex->current_select->mark_as_dependent(aggr_sel);
return FALSE;
}
@@ -299,10 +302,10 @@ Item_sum::Item_sum(List<Item> &list) :arg_count(list.elements),
Item_sum::Item_sum(THD *thd, Item_sum *item):
Item_result_field(thd, item), arg_count(item->arg_count),
+ aggr_sel(item->aggr_sel),
nest_level(item->nest_level), aggr_level(item->aggr_level),
quick_group(item->quick_group), used_tables_cache(item->used_tables_cache),
- forced_const(item->forced_const),
- nest_level_tables_count(item->nest_level_tables_count)
+ forced_const(item->forced_const)
{
if (arg_count <= 2)
args=tmp_args;
@@ -449,8 +452,7 @@ void Item_sum::update_used_tables ()
used_tables_cache&= PSEUDO_TABLE_BITS;
/* the aggregate function is aggregated into its local context */
- if (aggr_level == nest_level)
- used_tables_cache |= (1 << nest_level_tables_count) - 1;
+ used_tables_cache |= (1 << aggr_sel->join->tables) - 1;
}
}