@@ -257,7 +257,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
257257 */
258258 bool log_on= (thd->options & OPTION_BIN_LOG) ||
259259 (!(thd->security_ctx ->master_access & SUPER_ACL));
260- bool transactional_table;
260+ bool transactional_table, joins_freed= FALSE ;
261261 uint value_count;
262262 ulong counter = 1 ;
263263 ulonglong id;
@@ -513,6 +513,9 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
513513 thd->row_count ++;
514514 }
515515
516+ free_underlaid_joins (thd, &thd->lex ->select_lex );
517+ joins_freed= TRUE ;
518+
516519 /*
517520 Now all rows are inserted. Time to update logs and sends response to
518521 user
@@ -611,7 +614,6 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
611614 thd->row_count_func = info.copied +info.deleted +info.updated ;
612615 ::send_ok (thd, (ulong) thd->row_count_func, id, buff);
613616 }
614- free_underlaid_joins (thd, &thd->lex ->select_lex );
615617 thd->abort_on_warning = 0 ;
616618 DBUG_RETURN (FALSE );
617619
@@ -620,7 +622,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
620622 if (lock_type == TL_WRITE_DELAYED)
621623 end_delayed_insert (thd);
622624#endif
623- free_underlaid_joins (thd, &thd->lex ->select_lex );
625+ if (!joins_freed)
626+ free_underlaid_joins (thd, &thd->lex ->select_lex );
624627 thd->abort_on_warning = 0 ;
625628 DBUG_RETURN (TRUE );
626629}
0 commit comments