diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 12a9cd8965b..e1a28602a44 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -3273,7 +3273,7 @@ sp_instr_stmt::execute(THD *thd, uint *nextp) int res; bool save_enable_slow_log; const CSET_STRING query_backup= thd->query_string; - QUERY_START_TIME_INFO time_info; + Backup_query_start_time time_info; Sub_statement_state backup_state; DBUG_ENTER("sp_instr_stmt::execute"); DBUG_PRINT("info", ("command: %d", m_lex_keeper.sql_command())); @@ -3289,7 +3289,7 @@ sp_instr_stmt::execute(THD *thd, uint *nextp) Save start time info for the CALL statement and overwrite it with the current time for log_slow_statement() to log the individual query timing. */ - thd->backup_query_start_time(&time_info); + time_info.backup(*thd); thd->set_time(); } thd->store_slow_query_state(&backup_state); @@ -3355,9 +3355,6 @@ sp_instr_stmt::execute(THD *thd, uint *nextp) thd->get_stmt_da()->reset_diagnostics_area(); } } - /* Restore the original query start time */ - if (thd->enable_slow_log) - thd->restore_query_start_time(&time_info); DBUG_RETURN(res || thd->is_error()); } diff --git a/sql/sql_class.h b/sql/sql_class.h index 624a5b93446..e9add6af2da 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2085,14 +2085,36 @@ struct QUERY_START_TIME_INFO my_time_t start_time; ulong start_time_sec_part; ulonglong start_utime, utime_after_lock; +}; - void backup_query_start_time(QUERY_START_TIME_INFO *backup) +class Backup_query_start_time : public QUERY_START_TIME_INFO +{ + QUERY_START_TIME_INFO *m_origin; + +public: + Backup_query_start_time() : m_origin(NULL) + {} + Backup_query_start_time(QUERY_START_TIME_INFO &origin) { - *backup= *this; + backup(origin); } - void restore_query_start_time(QUERY_START_TIME_INFO *backup) + ~Backup_query_start_time() { - *this= *backup; + restore(); + } + void backup(QUERY_START_TIME_INFO &origin) + { + m_origin= &origin; + QUERY_START_TIME_INFO *backup_= this; + *backup_= origin; + } + void restore() + { + if (m_origin) + { + *m_origin= *this; + m_origin= NULL; + } } };