When I tried to use a trigger to log the modification of a write statement, I found an unexpected behavior.
As in the example below, I defined a trigger of type AFTER. In my opinion, it should be executed after the write statement is executed. However, when this statement is blocked in the transaction, this statement is logged earlier than the actual execution time of this statement. Because, the statement (update) that was executed before it , recorded a later time than this statement.
Is this the reason for the function ( CURRENT_TIMESTAMP(6) ) that gets the time? What should I do if I want to record the actual execution time and modifications?
--- init
|
CREATE TABLE tNqrncdI (ID INT, VAL INT, c0 BOOLEAN , c1 DOUBLE , c2 BOOLEAN);
|
CREATE TABLE tNqrncdI_log (ID INT, VAL INT, c0 BOOLEAN , c1 DOUBLE , c2 BOOLEAN);
|
ALTER TABLE tNqrncdI_log
|
ADD COLUMN operation_type VARCHAR(6),
|
ADD COLUMN session_id VARCHAR(50),
|
ADD COLUMN time TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6);
|
|
INSERT INTO tNqrncdI (ID, VAL, c0, c1, c2) VALUES (3771, 4229, 1, -20.0, 0);
|
INSERT INTO tNqrncdI (ID, VAL, c0, c1, c2) VALUES (3772, 4230, 1, -20.0, 0);
|
SET GLOBAL lock_wait_timeout = 10;
|
SET GLOBAL innodb_lock_wait_timeout = 10;
|
|
DELIMITER $$
|
CREATE TRIGGER tri_update_tNqrncdI
|
AFTER UPDATE ON tNqrncdI
|
FOR EACH ROW
|
BEGIN
|
INSERT INTO tNqrncdI_log (operation_type, session_id, id, val, c0, c1, c2)
|
VALUES ('UPDATE', CONNECTION_ID(), NEW.ID, NEW.VAL, OLD.c0, OLD.c1, OLD.c2);
|
END;
|
CREATE TRIGGER tri_delete_tNqrncdI
|
AFTER DELETE ON tNqrncdI
|
FOR EACH ROW
|
BEGIN
|
INSERT INTO tNqrncdI_log (operation_type, session_id, id, val, c0, c1, c2)
|
VALUES ('DELETE', CONNECTION_ID(), OLD.ID, -1, OLD.c0, OLD.c1, OLD.c2);
|
END;
|
$$
|
DELIMITER ;
|
--- session 1
|
BEGIN;
|
UPDATE tNqrncdI SET VAL = 4231 WHERE ( tNqrncdI.c2 = 0 );
|
--- session 2
|
BEGIN;
|
DELETE tNqrncdI FROM tNqrncdI WHERE ( tNqrncdI.c2 = 0 );
|
--- session 1
|
UPDATE tNqrncdI SET VAL = 4232, tNqrncdI.c2 = 0;
|
--- session 1
|
COMMIT;
|
--- session 2
|
COMMIT;
|
--- session 1
|
SELECT * from tNqrncdI_log;
|
+------+------+------+------+------+----------------+------------+----------------------------+
|
| ID | VAL | c0 | c1 | c2 | operation_type | session_id | time |
|
+------+------+------+------+------+----------------+------------+----------------------------+
|
| 3771 | 4231 | 1 | -20 | 0 | UPDATE | 5321 | 2025-02-19 15:03:06.311373 |
|
| 3772 | 4231 | 1 | -20 | 0 | UPDATE | 5321 | 2025-02-19 15:03:06.311373 |
|
| 3771 | 4232 | 1 | -20 | 0 | UPDATE | 5321 | 2025-02-19 15:03:16.789257 |
|
| 3772 | 4232 | 1 | -20 | 0 | UPDATE | 5321 | 2025-02-19 15:03:16.789257 |
|
*| 3771 | -1 | 1 | -20 | 0 | DELETE | 5322 | 2025-02-19 15:03:13.481262 |
|
| 3772 | -1 | 1 | -20 | 0 | DELETE | 5322 | 2025-02-19 15:03:13.481262 |*
|
+------+------+------+------+------+----------------+------------+----------------------------+
|
6 rows in set (0.00 sec)
|
{"report":{"fcp":912.9000000059605,"ttfb":177.59999999403954,"pageVisibility":"visible","entityId":132899,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"12ffa659-a8b0-46a7-8216-ae895211af0a","navigationType":0,"readyForUser":994.3000000119209,"redirectCount":0,"resourceLoadedEnd":1025.800000011921,"resourceLoadedStart":182.19999998807907,"resourceTiming":[{"duration":141.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":182.19999998807907,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":182.19999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":323.69999998807907,"responseStart":0,"secureConnectionStart":0},{"duration":141.40000000596046,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":182.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":182.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":323.90000000596046,"responseStart":0,"secureConnectionStart":0},{"duration":149.90000000596046,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":182.59999999403954,"connectEnd":182.59999999403954,"connectStart":182.59999999403954,"domainLookupEnd":182.59999999403954,"domainLookupStart":182.59999999403954,"fetchStart":182.59999999403954,"redirectEnd":0,"redirectStart":0,"requestStart":182.59999999403954,"responseEnd":332.5,"responseStart":332.5,"secureConnectionStart":182.59999999403954},{"duration":381.90000000596046,"initiatorType":"script","name":"https://jira.mariadb.org/s/c32eb0da7ad9831253f8397e6cc26afd-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":182.69999998807907,"connectEnd":182.69999998807907,"connectStart":182.69999998807907,"domainLookupEnd":182.69999998807907,"domainLookupStart":182.69999998807907,"fetchStart":182.69999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":182.69999998807907,"responseEnd":564.5999999940395,"responseStart":564.5999999940395,"secureConnectionStart":182.69999998807907},{"duration":385.09999999403954,"initiatorType":"script","name":"https://jira.mariadb.org/s/bc0bcb146314416123c992714ee00ff7-CDN/lu2bv2/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":182.90000000596046,"connectEnd":182.90000000596046,"connectStart":182.90000000596046,"domainLookupEnd":182.90000000596046,"domainLookupStart":182.90000000596046,"fetchStart":182.90000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":182.90000000596046,"responseEnd":568,"responseStart":568,"secureConnectionStart":182.90000000596046},{"duration":385.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":183.19999998807907,"connectEnd":183.19999998807907,"connectStart":183.19999998807907,"domainLookupEnd":183.19999998807907,"domainLookupStart":183.19999998807907,"fetchStart":183.19999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":183.19999998807907,"responseEnd":568.6999999880791,"responseStart":568.6999999880791,"secureConnectionStart":183.19999998807907},{"duration":385.69999998807907,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":183.30000001192093,"connectEnd":183.30000001192093,"connectStart":183.30000001192093,"domainLookupEnd":183.30000001192093,"domainLookupStart":183.30000001192093,"fetchStart":183.30000001192093,"redirectEnd":0,"redirectStart":0,"requestStart":183.30000001192093,"responseEnd":569,"responseStart":569,"secureConnectionStart":183.30000001192093},{"duration":386.40000000596046,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bv2/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":183.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":183.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":569.9000000059605,"responseStart":0,"secureConnectionStart":0},{"duration":385.90000000596046,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":183.69999998807907,"connectEnd":183.69999998807907,"connectStart":183.69999998807907,"domainLookupEnd":183.69999998807907,"domainLookupStart":183.69999998807907,"fetchStart":183.69999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":183.69999998807907,"responseEnd":569.5999999940395,"responseStart":569.5999999940395,"secureConnectionStart":183.69999998807907},{"duration":386.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bv2/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":183.90000000596046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":183.90000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":570.4000000059605,"responseStart":0,"secureConnectionStart":0},{"duration":386.19999998807907,"initiatorType":"script","name":"https://jira.mariadb.org/s/719848dd97ebe0663199f49a3936487a-CDN/lu2bv2/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":184,"connectEnd":184,"connectStart":184,"domainLookupEnd":184,"domainLookupStart":184,"fetchStart":184,"redirectEnd":0,"redirectStart":0,"requestStart":184,"responseEnd":570.1999999880791,"responseStart":570.1999999880791,"secureConnectionStart":184},{"duration":814.4000000059605,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":189,"connectEnd":189,"connectStart":189,"domainLookupEnd":189,"domainLookupStart":189,"fetchStart":189,"redirectEnd":0,"redirectStart":0,"requestStart":189,"responseEnd":1003.4000000059605,"responseStart":1003.4000000059605,"secureConnectionStart":189},{"duration":814.8000000119209,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":189,"connectEnd":189,"connectStart":189,"domainLookupEnd":189,"domainLookupStart":189,"fetchStart":189,"redirectEnd":0,"redirectStart":0,"requestStart":189,"responseEnd":1003.8000000119209,"responseStart":1003.8000000119209,"secureConnectionStart":189},{"duration":273.40000000596046,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":471.19999998807907,"connectEnd":471.19999998807907,"connectStart":471.19999998807907,"domainLookupEnd":471.19999998807907,"domainLookupStart":471.19999998807907,"fetchStart":471.19999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":471.19999998807907,"responseEnd":744.5999999940395,"responseStart":744.5999999940395,"secureConnectionStart":471.19999998807907},{"duration":203.10000002384186,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bv2/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":822.6999999880791,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":822.6999999880791,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1025.800000011921,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":13,"responseStart":177,"responseEnd":182,"domLoading":180,"domInteractive":1054,"domContentLoadedEventStart":1054,"domContentLoadedEventEnd":1097,"domComplete":1800,"loadEventStart":1800,"loadEventEnd":1802,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1039.699999988079},{"name":"bigPipe.sidebar-id.end","time":1040.300000011921},{"name":"bigPipe.activity-panel-pipe-id.start","time":1040.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":1042.699999988079},{"name":"activityTabFullyLoaded","time":1107.5999999940395}],"measures":[],"correlationId":"134ef6aadd99a3","effectiveType":"4g","downlink":9.7,"rtt":0,"serverDuration":92,"dbReadsTimeInMs":8,"dbConnsTimeInMs":15,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}