@@ -2932,9 +2932,6 @@ Item_sp::func_name_cstring(THD *thd, bool is_package_function) const
29322932void
29332933Item_sp::cleanup ()
29342934{
2935- delete sp_result_field;
2936- sp_result_field= NULL ;
2937- sp_result_field_items= Item_args ();
29382935 m_sp= NULL ;
29392936 delete func_ctx;
29402937 func_ctx= NULL ;
@@ -3106,7 +3103,6 @@ Item_sp::init_result_field(THD *thd, uint max_length, uint maybe_null,
31063103 DBUG_ENTER (" Item_sp::init_result_field" );
31073104
31083105 DBUG_ASSERT (m_sp != NULL );
3109- DBUG_ASSERT (sp_result_field == NULL );
31103106
31113107 /*
31123108 A Field needs to be attached to a Table.
@@ -3120,6 +3116,30 @@ Item_sp::init_result_field(THD *thd, uint max_length, uint maybe_null,
31203116 dummy_table->s ->table_name = Lex_ident_table (empty_clex_str);
31213117 dummy_table->maybe_null = maybe_null;
31223118
3119+ if (sp_result_field) // Non-first execution
3120+ {
3121+ if (Field_row *field_row= dynamic_cast <Field_row*>(sp_result_field))
3122+ {
3123+ /*
3124+ At the end of the previous execution cleanup() was called for
3125+ all Item_field instances in sp_result_field_items, which set their
3126+ Item_field::field to nullptr. We need to restore them to pointers
3127+ to the Fields in the virtual table.
3128+ */
3129+ Virtual_tmp_table *tbl= field_row->virtual_tmp_table ();
3130+ DBUG_ASSERT (tbl->s ->fields == sp_result_field_items.argument_count ());
3131+ for (uint i= 0 ; i < tbl->s ->fields ; i++)
3132+ {
3133+ Item *item= sp_result_field_items.arguments ()[i];
3134+ Item_field *item_field= dynamic_cast <Item_field*>(item);
3135+ DBUG_ASSERT (item_field);
3136+ item_field->reset_field (tbl->field [i]);
3137+ }
3138+ }
3139+ DBUG_RETURN (FALSE );
3140+ }
3141+
3142+
31233143 if (m_sp->m_return_field_def .is_column_type_ref ())
31243144 {
31253145 // RETURNS TYPE OF t1.col1
0 commit comments