diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 91794e061e4..61a8d5af815 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1244,7 +1244,12 @@ void close_thread_tables(THD *thd) table->s->table_name.str, (long) table)); #endif - DEBUG_SYNC(thd, "before_close_thread_tables"); +#if defined(ENABLED_DEBUG_SYNC) + /* debug_sync may not be initialized for some slave threads */ + if (thd->debug_sync_control) + DEBUG_SYNC(thd, "before_close_thread_tables"); +#endif + /* We are assuming here that thd->derived_tables contains ONLY derived tables for this substatement. i.e. instead of approach which uses