When updating a row in a system-versioned table and updating a column's value with the exact current value, a new historical row is written, that has the same ROW_START value as well as the same value for any other column as the previous one, while a ON UPDATE CURRENT_TIMESTAMP() column is not updated on the current row.
I also experienced that issue to not exist when updating a ENUM column with the exact current value, while existing when updating a INT column with the exact current value. However, in the example below the columns all behave the same.
CREATE TABLE Foobar (
|
id INT(11) NOT NULL,
|
a INT(11) NOT NULL,
|
b ENUM('foo', 'bar') NOT NULL,
|
c VARCHAR(255) NOT NULL,
|
ts DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP(),
|
PRIMARY KEY (id)
|
) WITH SYSTEM VERSIONING;
|
INSERT INTO Foobar (id, a, b, c) VALUES (1, 1, 'foo', 'hello');
|
-- 1 row
|
SELECT *, ROW_START, ROW_END FROM Foobar FOR SYSTEM_TIME ALL WHERE id = 1;
|
UPDATE Foobar SET b = 'foo' WHERE id = 1;
|
-- 2 rows with the exact same values except for ROW_END
|
SELECT *, ROW_START, ROW_END FROM Foobar FOR SYSTEM_TIME ALL WHERE id = 1;
|
UPDATE Foobar SET a = 1 WHERE id = 1;
|
-- 3 rows with the exact same values except for ROW_END
|
SELECT *, ROW_START, ROW_END FROM Foobar FOR SYSTEM_TIME ALL WHERE id = 1;
|
SELECT *, ROW_START, ROW_END FROM Foobar FOR SYSTEM_TIME AS OF '<row_start_value>' WHERE id = 1 will also return 3 rows, while I would expect only 1.
I would expect that a historical row is only written when data in the row really change, just like a ON UPDATE column behaves.
{"report":{"fcp":1730.3999998569489,"ttfb":213.19999980926514,"pageVisibility":"visible","entityId":103701,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":16,"apdex":0.5,"journeyId":"d7e0b681-700f-48ea-95fb-1d2220a54df7","navigationType":0,"readyForUser":1841.1999998092651,"redirectCount":0,"resourceLoadedEnd":1200,"resourceLoadedStart":224.89999985694885,"resourceTiming":[{"duration":24,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bsh/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":224.89999985694885,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":224.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":248.89999985694885,"responseStart":0,"secureConnectionStart":0},{"duration":23.300000190734863,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bsh/820016/12ta74/eb142f92e4bd16bd1ef8b08c1b9d5d56/_/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":226.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":226.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":249.5,"responseStart":0,"secureConnectionStart":0},{"duration":539.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/c54b129276d75dc2a3460e1d78f37913-CDN/lu2bsh/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":226.29999995231628,"connectEnd":226.29999995231628,"connectStart":226.29999995231628,"domainLookupEnd":226.29999995231628,"domainLookupStart":226.29999995231628,"fetchStart":226.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":253.19999980926514,"responseEnd":765.7999999523163,"responseStart":374.5,"secureConnectionStart":226.29999995231628},{"duration":973.6000001430511,"initiatorType":"script","name":"https://jira.mariadb.org/s/f867843cd2fdb209d4d1d4f760f86346-CDN/lu2bsh/820016/12ta74/eb142f92e4bd16bd1ef8b08c1b9d5d56/_/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":226.39999985694885,"connectEnd":226.39999985694885,"connectStart":226.39999985694885,"domainLookupEnd":226.39999985694885,"domainLookupStart":226.39999985694885,"fetchStart":226.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":262.7999999523163,"responseEnd":1200,"responseStart":416.69999980926514,"secureConnectionStart":226.39999985694885},{"duration":92.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/ffdb17665775c5b4d6f097f3974ee359-CDN/lu2bsh/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":226.5,"connectEnd":226.5,"connectStart":226.5,"domainLookupEnd":226.5,"domainLookupStart":226.5,"fetchStart":226.5,"redirectEnd":0,"redirectStart":0,"requestStart":265.19999980926514,"responseEnd":319.19999980926514,"responseStart":315,"secureConnectionStart":226.5},{"duration":90.10000014305115,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":226.69999980926514,"connectEnd":226.69999980926514,"connectStart":226.69999980926514,"domainLookupEnd":226.69999980926514,"domainLookupStart":226.69999980926514,"fetchStart":226.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":266.09999990463257,"responseEnd":316.7999999523163,"responseStart":314.19999980926514,"secureConnectionStart":226.69999980926514},{"duration":92.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":226.69999980926514,"connectEnd":226.69999980926514,"connectStart":226.69999980926514,"domainLookupEnd":226.69999980926514,"domainLookupStart":226.69999980926514,"fetchStart":226.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":266.19999980926514,"responseEnd":319.5,"responseStart":317,"secureConnectionStart":226.69999980926514},{"duration":32,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bsh/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":226.79999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":226.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":258.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":197.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":227,"connectEnd":227,"connectStart":227,"domainLookupEnd":227,"domainLookupStart":227,"fetchStart":227,"redirectEnd":0,"redirectStart":0,"requestStart":266.5,"responseEnd":424.59999990463257,"responseStart":423,"secureConnectionStart":227},{"duration":36.299999952316284,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bsh/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":227.29999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":227.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":263.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":102.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/81b5d7c27af3ebc078cc4a36383678ba-CDN/lu2bsh/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":228.09999990463257,"connectEnd":228.09999990463257,"connectStart":228.09999990463257,"domainLookupEnd":228.09999990463257,"domainLookupStart":228.09999990463257,"fetchStart":228.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":266.69999980926514,"responseEnd":330.69999980926514,"responseStart":318,"secureConnectionStart":228.09999990463257},{"duration":954.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":232.09999990463257,"connectEnd":232.09999990463257,"connectStart":232.09999990463257,"domainLookupEnd":232.09999990463257,"domainLookupStart":232.09999990463257,"fetchStart":232.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":349.09999990463257,"responseEnd":1186.5,"responseStart":1164.1999998092651,"secureConnectionStart":232.09999990463257},{"duration":892.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":243.29999995231628,"connectEnd":243.29999995231628,"connectStart":243.29999995231628,"domainLookupEnd":243.29999995231628,"domainLookupStart":243.29999995231628,"fetchStart":243.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":356,"responseEnd":1135.5,"responseStart":1133.1999998092651,"secureConnectionStart":243.29999995231628},{"duration":499.7999999523163,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1033.5,"connectEnd":1033.5,"connectStart":1033.5,"domainLookupEnd":1033.5,"domainLookupStart":1033.5,"fetchStart":1033.5,"redirectEnd":0,"redirectStart":0,"requestStart":1503,"responseEnd":1533.2999999523163,"responseStart":1532.2999999523163,"secureConnectionStart":1033.5},{"duration":457.19999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1656,"connectEnd":1656,"connectStart":1656,"domainLookupEnd":1656,"domainLookupStart":1656,"fetchStart":1656,"redirectEnd":0,"redirectStart":0,"requestStart":2083,"responseEnd":2113.199999809265,"responseStart":2112.5,"secureConnectionStart":1656},{"duration":412.80000019073486,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1722.6999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1722.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2135.5,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":26,"domainLookupEnd":37,"connectStart":37,"connectEnd":57,"secureConnectionStart":46,"requestStart":58,"responseStart":213,"responseEnd":242,"domLoading":218,"domInteractive":2065,"domContentLoadedEventStart":2065,"domContentLoadedEventEnd":2159,"domComplete":2664,"loadEventStart":2664,"loadEventEnd":2665,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2026.3999998569489},{"name":"bigPipe.sidebar-id.end","time":2027.3999998569489},{"name":"bigPipe.activity-panel-pipe-id.start","time":2027.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":2029.0999999046326},{"name":"activityTabFullyLoaded","time":2200}],"measures":[],"correlationId":"97cd65c387e8fc","effectiveType":"4g","downlink":9.1,"rtt":0,"serverDuration":76,"dbReadsTimeInMs":14,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Thank you for reporting the issue!
The decision to insert the historical row even if the row has not changed was intentional (
MDEV-23446), but start_time should be updated accordingly.This is a part of the same bug as
MDEV-26778, so I suggest following the progress in that Jira ticket if you'd like, and to close this one. I added the test case there.I also tried with enum type, the bug was also reproducible:
MariaDB [test]> CREATE or replace TABLE t1 ( id enum('a','b') , ts datetime ON UPDATE current_timestamp()) WITH SYSTEM versioning;
Query OK, 0 rows affected (0.059 sec)
MariaDB [test]> INSERT INTO t1 VALUES ('a',now());
Query OK, 1 row affected (0.005 sec)
MariaDB [test]> UPDATE t1 SET id = 'a' WHERE id = 'a';
Query OK, 0 rows affected (0.004 sec)
Rows matched: 1 Changed: 0 Inserted: 1 Warnings: 0
MariaDB [test]> UPDATE t1 SET id = 'a' WHERE id = 'a';
Query OK, 0 rows affected (0.004 sec)
Rows matched: 1 Changed: 0 Inserted: 1 Warnings: 0
MariaDB [test]> SELECT *, ROW_START, ROW_END FROM t1 FOR SYSTEM_TIME ALL;
+------+---------------------+----------------------------+----------------------------+
| id | ts | ROW_START | ROW_END |
+------+---------------------+----------------------------+----------------------------+
| a | 2021-10-07 18:05:41 | 2021-10-07 18:05:41.476392 | 2038-01-19 04:14:07.999999 |
| a | 2021-10-07 18:05:41 | 2021-10-07 18:05:41.476392 | 2021-10-07 18:05:52.143934 |
| a | 2021-10-07 18:05:41 | 2021-10-07 18:05:41.476392 | 2021-10-07 18:06:25.812918 |
+------+---------------------+----------------------------+----------------------------+
3 rows in set (0.001 sec)