diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index a69c048a918..0eb95f1cf64 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1424,6 +1424,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, } case COM_EXECUTE: { + thd->free_list= NULL; mysql_stmt_execute(thd, packet, packet_length); break; } diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 4630380967e..b633687b07f 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -1485,9 +1485,7 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) thd->stmt_backup.set_statement(thd); thd->set_statement(stmt); - reset_stmt_for_execute(stmt); - #ifndef EMBEDDED_LIBRARY if (stmt->param_count) { @@ -1526,6 +1524,11 @@ void mysql_stmt_execute(THD *thd, char *packet, uint packet_length) cleanup_items(stmt->free_list); close_thread_tables(thd); // to close derived tables thd->set_statement(&thd->stmt_backup); + /* + Free Items that were created during this execution of the PS by query + optimizer. + */ + free_items(thd->free_list); DBUG_VOID_RETURN; set_params_data_err: