diff --git a/sql/item.cc b/sql/item.cc index 250f6707d4e..c01a8ec29ad 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -2915,21 +2915,14 @@ Item_sp::execute_impl(THD *thd, Item **args, uint arg_count) */ bool -Item_sp::init_result_field(THD *thd, sp_head *sp, uint max_length, - uint maybe_null, bool *null_value, LEX_CSTRING *name) +Item_sp::init_result_field(THD *thd, uint max_length, uint maybe_null, + bool *null_value, LEX_CSTRING *name) { DBUG_ENTER("Item_sp::init_result_field"); - DBUG_ASSERT(m_sp == NULL); + DBUG_ASSERT(m_sp != NULL); DBUG_ASSERT(sp_result_field == NULL); - if (!(m_sp= sp)) - { - my_missing_function_error (m_name->m_name, ErrConvDQName(m_name).ptr()); - context->process_error(thd); - DBUG_RETURN(TRUE); - } - /* A Field needs to be attached to a Table. Below we "create" a dummy table by initializing diff --git a/sql/item.h b/sql/item.h index 574680bc86d..cbbfac92bc1 100644 --- a/sql/item.h +++ b/sql/item.h @@ -4496,8 +4496,8 @@ public: bool sp_check_access(THD *thd); bool execute(THD *thd, bool *null_value, Item **args, uint arg_count); bool execute_impl(THD *thd, Item **args, uint arg_count); - bool init_result_field(THD *thd, sp_head *sp, uint max_length, - uint maybe_null, bool *null_value, LEX_CSTRING *name); + bool init_result_field(THD *thd, uint max_length, uint maybe_null, + bool *null_value, LEX_CSTRING *name); }; class Item_ref :public Item_ident diff --git a/sql/item_func.cc b/sql/item_func.cc index d851b508daf..c0021d1a2be 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -6415,12 +6415,28 @@ Item_func_sp::fix_fields(THD *thd, Item **ref) } } + + /* Custom aggregates are transformed into an Item_sum_sp. We can not do this + earlier as we have no way of knowing what kind of Item we should create + when parsing the query. + + TODO(cvicentiu): See if this limitation can be lifted. + */ + + DBUG_ASSERT(m_sp == NULL); + if (!(m_sp= sp)) + { + my_missing_function_error(m_name->m_name, ErrConvDQName(m_name).ptr()); + context->process_error(thd); + DBUG_RETURN(TRUE); + } + /* - We must call init_result_field before Item_func::fix_fields() + We must call init_result_field before Item_func::fix_fields() to make m_sp and result_field members available to fix_length_and_dec(), which is called from Item_func::fix_fields(). */ - res= init_result_field(thd, sp, max_length, maybe_null, &null_value, &name); + res= init_result_field(thd, max_length, maybe_null, &null_value, &name); if (res) DBUG_RETURN(TRUE);