summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorunknown <igor@rurik.mysql.com>2005-10-27 21:37:52 -0700
committerunknown <igor@rurik.mysql.com>2005-10-27 21:37:52 -0700
commitcc57d4ef4e49f78f487a6497949871c0a5e3b158 (patch)
tree77b9cfe2f48b6462eb7de864b5248d396ab8bba6 /sql/item.cc
parenta397d1f7149dcdeac86e9e4870780dcd8e99a908 (diff)
parentcd49e32407dcc88a86a26b4c8720afd9ef99b7dd (diff)
downloadmariadb-git-cc57d4ef4e49f78f487a6497949871c0a5e3b158.tar.gz
Merge rurik.mysql.com:/home/igor/mysql-5.0
into rurik.mysql.com:/home/igor/dev/mysql-5.0-2 sql/item.cc: Auto merged sql/item_func.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_class.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_delete.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_parse.cc: Auto merged sql/sql_prepare.cc: Auto merged sql/sql_select.cc: Auto merged sql/sql_update.cc: Auto merged sql/sql_yacc.yy: Auto merged
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc52
1 files changed, 32 insertions, 20 deletions
diff --git a/sql/item.cc b/sql/item.cc
index 015657e4ac4..e1998f6f7e0 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1048,6 +1048,7 @@ void Item_name_const::print(String *str)
ref_pointer_array Pointer to array of reference fields
fields All fields in select
ref Pointer to item
+ skip_registered <=> the function must skipped for registered SUM items
NOTES
This is from split_sum_func2() for items that should be split
@@ -1060,8 +1061,13 @@ void Item_name_const::print(String *str)
void Item::split_sum_func2(THD *thd, Item **ref_pointer_array,
- List<Item> &fields, Item **ref)
+ List<Item> &fields, Item **ref,
+ bool skip_registered)
{
+ /* An item of type Item_sum is registered <=> ref_by != 0 */
+ if (type() == SUM_FUNC_ITEM && skip_registered &&
+ ((Item_sum *) this)->ref_by)
+ return;
if (type() != SUM_FUNC_ITEM && with_sum_func)
{
/* Will split complicated items and ignore simple ones */
@@ -3193,14 +3199,8 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select)
{
for each outer query Q_k beginning from the inner-most one
{
- if - Q_k is not a group query AND
- - Q_k is not inside an aggregate function
- OR
- - Q_(k-1) is not in a HAVING or SELECT clause of Q_k
- {
- search for a column or derived column named col_ref_i
- [in table T_j] in the FROM clause of Q_k;
- }
+ search for a column or derived column named col_ref_i
+ [in table T_j] in the FROM clause of Q_k;
if such a column is not found
Search for a column or derived column named col_ref_i
@@ -3280,18 +3280,11 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
place= prev_subselect_item->parsing_place;
/*
- Check table fields only if the subquery is used somewhere out of
- HAVING, or the outer SELECT does not use grouping (i.e. tables are
- accessible).
-
In case of a view, find_field_in_tables() writes the pointer to
the found view field into '*reference', in other words, it
substitutes this Item_field with the found expression.
*/
- if ((place != IN_HAVING ||
- (!select->with_sum_func &&
- select->group_list.elements == 0)) &&
- (from_field= find_field_in_tables(thd, this,
+ if ((from_field= find_field_in_tables(thd, this,
outer_context->
first_name_resolution_table,
outer_context->
@@ -3309,6 +3302,21 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
{
prev_subselect_item->used_tables_cache|= from_field->table->map;
prev_subselect_item->const_item_cache= 0;
+ if (thd->lex->in_sum_func &&
+ thd->lex->in_sum_func->nest_level ==
+ thd->lex->current_select->nest_level)
+ {
+ Item::Type type= (*reference)->type();
+ set_if_bigger(thd->lex->in_sum_func->max_arg_level,
+ select->nest_level);
+ set_field(from_field);
+ fixed= 1;
+ mark_as_dependent(thd, last_checked_context->select_lex,
+ context->select_lex, this,
+ ((type == REF_ITEM || type == FIELD_ITEM) ?
+ (Item_ident*) (*reference) : 0));
+ return FALSE;
+ }
}
else
{
@@ -3460,6 +3468,11 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
return FALSE;
set_field(from_field);
+ if (thd->lex->in_sum_func &&
+ thd->lex->in_sum_func->nest_level ==
+ thd->lex->current_select->nest_level)
+ set_if_bigger(thd->lex->in_sum_func->max_arg_level,
+ thd->lex->current_select->nest_level);
}
else if (thd->set_query_id && field->query_id != thd->query_id)
{
@@ -4616,9 +4629,8 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
aggregate function.
*/
if (((*ref)->with_sum_func && name &&
- (depended_from ||
- !(current_sel->linkage != GLOBAL_OPTIONS_TYPE &&
- current_sel->having_fix_field))) ||
+ !(current_sel->linkage != GLOBAL_OPTIONS_TYPE &&
+ current_sel->having_fix_field)) ||
!(*ref)->fixed)
{
my_error(ER_ILLEGAL_REFERENCE, MYF(0),