1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-13727 top-level query timestamp reset at stored func/trigger internal statements

Being executed under slow_log is ON the test revealed a "side-effect"
in MDEV-8305 implementation which inadvertently made the trigger or
stored function statements to reset the top-level query's
THD::start_time et al. (Details of the test failure analysis are footnoted).
Unlike the SP case the SF and Trigger's internal statement should not
do that.

Fixed with revising the MDEV-8305 decision to backup/reset/restore
the session timestamp inside sp_instr_stmt::execute(). The timestamp
actually remains reset in the SP case by its caller per statement basis by ever
existing logics.

Timestamps related tests are extended to cover the trigger and stored function case.

Note, commit 3395ab7324 is reverted as its struct QUERY_START_TIME_INFO
declaration is not in use anymore after this patch.

Footnote:
--------
Specifically to the failing test, a query on the master was logged
okay with a timestamp of the query's top-level statement but its post
update trigger managed to compute one more (later) timestamp which got
inserted into another table. The latter table master-vs-slave
no fractional part timestamp discrepancy became evident
thanks to different execution time of the trigger combined with the
fact of the logged with micro-second fractional part master timestamp
was truncated on the slave. On master when the fractional part was
close to 1 the trigger execution added up its own latency to overflow
to next second value. That's how the master timestamp surprisingly
turned out to bigger than the slave's one.
This commit is contained in:
Andrei Elkin
2018-05-22 20:19:13 +03:00
parent 83ec8c88c6
commit 3bbc30c73b
4 changed files with 89 additions and 36 deletions

View File

@@ -2077,3 +2077,61 @@ EXPLAIN EXTENDED SELECT
TIMESTAMP'2001-01-01 10:20:30' + INTERVAL '10' YEAR AS c1,
INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2,
+INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c3;
############
# MDEV-13727
# Current timestamp functions inside stored functions must return the
# value of the top-level statement's timestamp (its start time).
# This must hold regardless of @@slow_query_log option.
#
CREATE TABLE t_ts (a timestamp(6));
CREATE TABLE t_trig (a timestamp(6));
delimiter //;
CREATE FUNCTION fn_sleep_before_now() returns int
BEGIN
INSERT INTO t_ts SET a= current_timestamp(6);
RETURN 0;
END//
CREATE TRIGGER trg_insert_t_ts after INSERT on t_ts for each row
BEGIN
INSERT into t_trig set a= current_timestamp(6);
END//
delimiter ;//
SET @sav_slow_query_log= @@session.slow_query_log;
# @@slow_query_log ON check
SET @@session.slow_query_log= ON;
SELECT current_timestamp(6),fn_sleep_before_now() INTO @ts_cur, @ts_func;
SELECT a FROM t_ts LIMIT 1 into @ts_func;
SELECT a FROM t_trig LIMIT 1 into @ts_trig;
if (!`SELECT @ts_cur = @ts_func and @ts_func = @ts_trig`)
{
SELECT @ts_cur, @ts_func, @ts_trig;
--die Error: timestamps must be equal but they diverge
}
DELETE FROM t_ts;
DELETE FROM t_trig;
# @@slow_query_log OFF check
SET @@session.slow_query_log= OFF;
SELECT current_timestamp(6),fn_sleep_before_now() INTO @ts_cur, @func_ts;
SELECT a FROM t_ts LIMIT 1 into @ts_func;
SELECT a FROM t_trig LIMIT 1 into @ts_trig;
if (!`SELECT @ts_cur = @ts_func and @ts_func = @ts_trig`)
{
SELECT @ts_cur, @ts_func, @ts_trig;
--die Error: timestamps must be equal but they diverge
}
# Cleanup
SET @@session.slow_query_log= @sav_slow_query_log;
DROP FUNCTION fn_sleep_before_now;
DROP TRIGGER trg_insert_t_ts;
DROP TABLE t_ts, t_trig;
#
# End of MDEV-13727
###################