summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc54
1 files changed, 41 insertions, 13 deletions
diff --git a/sql/item.cc b/sql/item.cc
index c5b8d7a89ef..9ff1f8c0084 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -3931,9 +3931,9 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
}
if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
goto error;
- else if (!ret)
- return FALSE;
outer_fixed= TRUE;
+ if (!ret)
+ goto mark_non_agg_field;
}
else if (!from_field)
goto error;
@@ -3945,9 +3945,9 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
int ret;
if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
goto error;
- else if (!ret)
- return FALSE;
outer_fixed= 1;
+ if (!ret)
+ goto mark_non_agg_field;
}
/*
@@ -4013,6 +4013,26 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
thd->lex->current_select->non_agg_fields.push_back(this);
marker= thd->lex->current_select->cur_pos_in_select_list;
}
+mark_non_agg_field:
+ if (fixed && thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY)
+ {
+ /*
+ Mark selects according to presence of non aggregated fields.
+ Fields from outer selects added to the aggregate function
+ outer_fields list as its unknown at the moment whether it's
+ aggregated or not.
+ */
+ if (!thd->lex->in_sum_func)
+ cached_table->select_lex->full_group_by_flag|= NON_AGG_FIELD_USED;
+ else
+ {
+ if (outer_fixed)
+ thd->lex->in_sum_func->outer_fields.push_back(this);
+ else if (thd->lex->in_sum_func->nest_level !=
+ thd->lex->current_select->nest_level)
+ cached_table->select_lex->full_group_by_flag|= NON_AGG_FIELD_USED;
+ }
+ }
return FALSE;
error:
@@ -4136,9 +4156,14 @@ static void convert_zerofill_number_to_string(Item **item, Field_num *field)
String tmp(buff,sizeof(buff), field->charset()), *res;
res= (*item)->val_str(&tmp);
- field->prepend_zeros(res);
- pos= (char *) sql_strmake (res->ptr(), res->length());
- *item= new Item_string(pos, res->length(), field->charset());
+ if ((*item)->is_null())
+ *item= new Item_null();
+ else
+ {
+ field->prepend_zeros(res);
+ pos= (char *) sql_strmake (res->ptr(), res->length());
+ *item= new Item_string(pos, res->length(), field->charset());
+ }
}
@@ -5482,13 +5507,16 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
DBUG_ASSERT(*ref);
/*
Check if this is an incorrect reference in a group function or forward
- reference. Do not issue an error if this is an unnamed reference inside an
- aggregate function.
+ reference. Do not issue an error if this is:
+ 1. outer reference (will be fixed later by the fix_inner_refs function);
+ 2. an unnamed reference inside an aggregate function.
*/
- if (((*ref)->with_sum_func && name &&
- !(current_sel->linkage != GLOBAL_OPTIONS_TYPE &&
- current_sel->having_fix_field)) ||
- !(*ref)->fixed)
+ if (!((*ref)->type() == REF_ITEM &&
+ ((Item_ref *)(*ref))->ref_type() == OUTER_REF) &&
+ (((*ref)->with_sum_func && name &&
+ !(current_sel->linkage != GLOBAL_OPTIONS_TYPE &&
+ current_sel->having_fix_field)) ||
+ !(*ref)->fixed))
{
my_error(ER_ILLEGAL_REFERENCE, MYF(0),
name, ((*ref)->with_sum_func?