diff options
author | unknown <sanja@askmonty.org> | 2013-05-03 16:07:13 +0300 |
---|---|---|
committer | unknown <sanja@askmonty.org> | 2013-05-03 16:07:13 +0300 |
commit | 682c8a36ca503f53db50628463424f205b609ab0 (patch) | |
tree | 2d99dc5d2696f3441d0a694f5da8ec9b09cbe9eb /sql/item_sum.cc | |
parent | 1a7c4ac7ae5534381285f501afadae297cff3e4c (diff) | |
download | mariadb-git-682c8a36ca503f53db50628463424f205b609ab0.tar.gz |
MDEV-4290:
Fix agregate function resolution in derived tables (no name resolution over a derived table border)
Diffstat (limited to 'sql/item_sum.cc')
-rw-r--r-- | sql/item_sum.cc | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 3f2020efeb5..489c0f1c23e 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -53,7 +53,15 @@ bool Item_sum::init_sum_func_check(THD *thd) { - if (!thd->lex->allow_sum_func) + SELECT_LEX *curr_sel= thd->lex->current_select; + if (!curr_sel->name_visibility_map) + { + for (SELECT_LEX *sl= curr_sel; sl; sl= sl->context.outer_select()) + { + curr_sel->name_visibility_map|= (1 << sl-> nest_level); + } + } + if (!(thd->lex->allow_sum_func & curr_sel->name_visibility_map)) { my_message(ER_INVALID_GROUP_FUNC_USE, ER(ER_INVALID_GROUP_FUNC_USE), MYF(0)); @@ -124,8 +132,11 @@ bool Item_sum::init_sum_func_check(THD *thd) bool Item_sum::check_sum_func(THD *thd, Item **ref) { + SELECT_LEX *curr_sel= thd->lex->current_select; + nesting_map allow_sum_func= (thd->lex->allow_sum_func & + curr_sel->name_visibility_map); bool invalid= FALSE; - nesting_map allow_sum_func= thd->lex->allow_sum_func; + DBUG_ASSERT(curr_sel->name_visibility_map); // should be set already /* The value of max_arg_level is updated if an argument of the set function contains a column reference resolved against a subquery whose level is @@ -158,7 +169,7 @@ bool Item_sum::check_sum_func(THD *thd, Item **ref) if (!invalid && aggr_level < 0) { aggr_level= nest_level; - aggr_sel= thd->lex->current_select; + aggr_sel= curr_sel; } /* By this moment we either found a subquery where the set function is @@ -295,9 +306,9 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref) { SELECT_LEX *sl; nesting_map allow_sum_func= thd->lex->allow_sum_func; - for (sl= thd->lex->current_select->master_unit()->outer_select() ; + for (sl= thd->lex->current_select->context.outer_select() ; sl && sl->nest_level > max_arg_level; - sl= sl->master_unit()->outer_select() ) + sl= sl->context.outer_select()) { if (aggr_level < 0 && (allow_sum_func & (1 << sl->nest_level))) { |