Remove the side effect of setting m_sp from Item_sp::init_result_field

Item_sp::init_result_field no longer takes sp_head* parameter. It
expects the m_sp member to be already set to something valid.
This commit is contained in:
Vicențiu Ciorbaru 2017-12-02 22:30:48 +02:00 committed by Vicențiu Ciorbaru
parent c12d1ed48e
commit 7448b01bb5
3 changed files with 23 additions and 14 deletions

View File

@ -2915,21 +2915,14 @@ Item_sp::execute_impl(THD *thd, Item **args, uint arg_count)
*/ */
bool bool
Item_sp::init_result_field(THD *thd, sp_head *sp, uint max_length, Item_sp::init_result_field(THD *thd, uint max_length, uint maybe_null,
uint maybe_null, bool *null_value, LEX_CSTRING *name) bool *null_value, LEX_CSTRING *name)
{ {
DBUG_ENTER("Item_sp::init_result_field"); DBUG_ENTER("Item_sp::init_result_field");
DBUG_ASSERT(m_sp == NULL); DBUG_ASSERT(m_sp != NULL);
DBUG_ASSERT(sp_result_field == 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. A Field needs to be attached to a Table.
Below we "create" a dummy table by initializing Below we "create" a dummy table by initializing

View File

@ -4496,8 +4496,8 @@ public:
bool sp_check_access(THD *thd); bool sp_check_access(THD *thd);
bool execute(THD *thd, bool *null_value, Item **args, uint arg_count); bool execute(THD *thd, bool *null_value, Item **args, uint arg_count);
bool execute_impl(THD *thd, 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, bool init_result_field(THD *thd, uint max_length, uint maybe_null,
uint maybe_null, bool *null_value, LEX_CSTRING *name); bool *null_value, LEX_CSTRING *name);
}; };
class Item_ref :public Item_ident class Item_ref :public Item_ident

View File

@ -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(), to make m_sp and result_field members available to fix_length_and_dec(),
which is called from Item_func::fix_fields(). 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) if (res)
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);