diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 114ff0d451a..31c6075b590 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -681,6 +681,8 @@ sp_head::execute_procedure(THD *thd, List *args) nctx->set_oindex(i, static_cast(it)->get_offset()); } } + // Clean up the joins before closing the tables. + thd->lex->unit.cleanup(); // Close tables opened for subselect in argument list close_thread_tables(thd);