mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 13:02:28 +01:00
Bug #47905 stored procedures with conditional statements not
being logged to slow query log The problem is that the execution time for a multi-statement stored procedure as a whole may not be accurate, and thus not be entered into the slow query log even if the total time exceeds long_query_time. The reason for this is that THD::utime_after_lock used for time calculation may be reset at the start of each new statement, possibly leaving the total SP execution equal to the time spent executing the last statement in the SP. This patch stores the utime on start of SP execution, and restores it on exit of SP execution. A test is added.
This commit is contained in:
parent
83b40ad9e4
commit
c1a6dc5084
3 changed files with 40 additions and 0 deletions
|
@ -20,5 +20,21 @@ sleep(2)
|
|||
SELECT count(*) > 0 FROM mysql.slow_log;
|
||||
count(*) > 0
|
||||
1
|
||||
'Bug#47905 stored procedures not logged correctly to slow query log'
|
||||
TRUNCATE mysql.slow_log;
|
||||
CREATE PROCEDURE p_test()
|
||||
BEGIN
|
||||
select sleep(2);
|
||||
select 1;
|
||||
END//
|
||||
CALL p_test();
|
||||
sleep(2)
|
||||
0
|
||||
1
|
||||
1
|
||||
SELECT count(*) > 0 FROM mysql.slow_log;
|
||||
count(*) > 0
|
||||
1
|
||||
DROP PROCEDURE p_test;
|
||||
SET @@global.log_output = @global_log_output;
|
||||
SET @global.slow_query_log = @global_slow_query_log;
|
||||
|
|
|
@ -31,6 +31,27 @@ SELECT sleep(2);
|
|||
|
||||
SELECT count(*) > 0 FROM mysql.slow_log;
|
||||
|
||||
|
||||
#==========================================================================
|
||||
--echo 'Bug#47905 stored procedures not logged correctly to slow query log'
|
||||
#==========================================================================
|
||||
# assumes logging to table turned on with long_query_time=1 as above
|
||||
|
||||
TRUNCATE mysql.slow_log;
|
||||
|
||||
DELIMITER //;
|
||||
CREATE PROCEDURE p_test()
|
||||
BEGIN
|
||||
select sleep(2);
|
||||
select 1;
|
||||
END//
|
||||
DELIMITER ;//
|
||||
|
||||
CALL p_test();
|
||||
SELECT count(*) > 0 FROM mysql.slow_log;
|
||||
DROP PROCEDURE p_test;
|
||||
|
||||
|
||||
#restore
|
||||
SET @@global.log_output = @global_log_output;
|
||||
SET @global.slow_query_log = @global_slow_query_log;
|
||||
|
|
|
@ -1848,6 +1848,8 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
|
|||
{
|
||||
bool err_status= FALSE;
|
||||
uint params = m_pcont->context_var_count();
|
||||
/* Query start time may be reset in a multi-stmt SP; keep this for later. */
|
||||
ulonglong utime_before_sp_exec= thd->utime_after_lock;
|
||||
sp_rcontext *save_spcont, *octx;
|
||||
sp_rcontext *nctx = NULL;
|
||||
bool save_enable_slow_log= false;
|
||||
|
@ -2040,6 +2042,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
|
|||
|
||||
delete nctx;
|
||||
thd->spcont= save_spcont;
|
||||
thd->utime_after_lock= utime_before_sp_exec;
|
||||
|
||||
DBUG_RETURN(err_status);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue