Elena Stepanova
added a comment - A few examples to remind of the oddities caused by the current default behavior (with explicit_defaults_for_timestamp=OFF).
Only the first TIMESTAMP column gets the CURRENT_TIMESTAMP, but all TIMESTAMP columns get implicit NOT NULL and some default:
MariaDB [test]> create table t (a timestamp , b int , c timestamp );
Query OK, 0 rows affected (0.037 sec)
MariaDB [test]> show create table t \G
*************************** 1. row ***************************
Table : t
Create Table : CREATE TABLE `t` (
`a` timestamp NOT NULL DEFAULT current_timestamp () ON UPDATE current_timestamp (),
`b` int (11) DEFAULT NULL ,
`c` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.001 sec)
If you add a new column before the first TIMESTAMP, you get two CURRENT_TIMESTAMP columns:
MariaDB [test]> alter table t add d timestamp first ;
Query OK, 0 rows affected (0.037 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [test]> show create table t \G
*************************** 1. row ***************************
Table : t
Create Table : CREATE TABLE `t` (
`d` timestamp NOT NULL DEFAULT current_timestamp () ON UPDATE current_timestamp (),
`a` timestamp NOT NULL DEFAULT current_timestamp () ON UPDATE current_timestamp (),
`b` int (11) DEFAULT NULL ,
`c` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.001 sec)
But if you add a new column after an existing TIMESTAMP, you won't:
MariaDB [test]> alter table t add e timestamp after a;
Query OK, 0 rows affected (0.041 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [test]> show create table t \G
*************************** 1. row ***************************
Table : t
Create Table : CREATE TABLE `t` (
`d` timestamp NOT NULL DEFAULT current_timestamp () ON UPDATE current_timestamp (),
`a` timestamp NOT NULL DEFAULT current_timestamp () ON UPDATE current_timestamp (),
`e` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ,
`b` int (11) DEFAULT NULL ,
`c` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.001 sec)
If you "modify" the first timestamp, it will remain as it is:
MariaDB [test]> alter table t modify d timestamp ;
Query OK, 0 rows affected (0.033 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [test]> show create table t \G
*************************** 1. row ***************************
Table : t
Create Table : CREATE TABLE `t` (
`d` timestamp NOT NULL DEFAULT current_timestamp () ON UPDATE current_timestamp (),
`a` timestamp NOT NULL DEFAULT current_timestamp () ON UPDATE current_timestamp (),
`e` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ,
`b` int (11) DEFAULT NULL ,
`c` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.001 sec)
If you modify another timestamp, it will lose CURRENT_TIMESTAMP properties:
MariaDB [test]> alter table t modify a timestamp ;
Query OK, 0 rows affected (0.033 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [test]> show create table t \G
*************************** 1. row ***************************
Table : t
Create Table : CREATE TABLE `t` (
`d` timestamp NOT NULL DEFAULT current_timestamp () ON UPDATE current_timestamp (),
`a` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ,
`e` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ,
`b` int (11) DEFAULT NULL ,
`c` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.001 sec)
In the current implementation, I only see the change of the default, but the scope and read-only-ness remained as they were, and there seems to be no activity on MDEV-8455.
I don't think it is sufficient.
It is clear from the MySQL history that users don't accept the change in this form, because it breaks OM => NS upgrade. There had been multiple complaints about it (example1, example2) which made MySQL start writing it in the binary log, and for this, it was changed to dynamic and session-level. And it was done not only in 8.0 where the default was changed, but in 5.7, to facilitate the rolling upgrade.
I think we have to do the same, in as early versions as possible and as soon as possible.
While it won't eliminate the OM => NS problem entirely (there will still be ancient pre-change installations and binary logs), it will at least minimize the issue.
Elena Stepanova
added a comment - - edited serg , ralf.gebhardt ,
In the current implementation, I only see the change of the default, but the scope and read-only-ness remained as they were, and there seems to be no activity on MDEV-8455 .
I don't think it is sufficient.
It is clear from the MySQL history that users don't accept the change in this form, because it breaks OM => NS upgrade. There had been multiple complaints about it ( example1 , example2 ) which made MySQL start writing it in the binary log , and for this, it was changed to dynamic and session-level. And it was done not only in 8.0 where the default was changed, but in 5.7, to facilitate the rolling upgrade.
I think we have to do the same, in as early versions as possible and as soon as possible.
While it won't eliminate the OM => NS problem entirely (there will still be ancient pre-change installations and binary logs), it will at least minimize the issue.
The last branch in my testing was bb-10.10-MDEV-28632 of a48739e6ee, with a patch similar to 387c9d1707 applied locally. Testing didn't reveal any relevant issues.
I think the change should be pushed into the target branches.
It is not what will be merged into 10.10 main though; the most part of the patch will go to 10.5+ and will be merged up, and only s smaller change will be pushed directly into 10.10.
The change which old versions need to facilitate smooth(er) rolling upgrades turned out to be much more intrusive than I originally expected; it is worrisome, but I still believe it is the right thing to do: odd legacy behavior of timestamps has to be eventually abandoned, and given our release model, there is no way to do it other than accompanying it by a change in older post-GA versions.
Documentation-wise, I don't think that the switch from read-only to dynamic variable should be anyhow advertised, neither for old versions nor for 10.10; while it is done on technical reasons, we do not actually want users to start changing it at runtime. It is never needed, whatever users want to achieve by changing the variable at runtime, they can do instead by creating a table in a proper manner.
What should probably be highlighted for old GAs is that the default value of the variable will change in upcoming versions, so users are advised to start switching their instances to ON value as soon as possible globally, by setting it in the config file.
For 10.10, the focus should be on the change of the default, users need to be aware if they rely on the old behavior in their applications.
Galera users should pay special attention to it, since unlike for the traditional replication, nothing can be done to smoothen Galera rolling upgrades, users will have to handle the difference themselves.
Elena Stepanova
added a comment - - edited The last branch in my testing was bb-10.10- MDEV-28632 of a48739e6ee , with a patch similar to 387c9d1707 applied locally. Testing didn't reveal any relevant issues.
I think the change should be pushed into the target branches.
It is not what will be merged into 10.10 main though; the most part of the patch will go to 10.5+ and will be merged up, and only s smaller change will be pushed directly into 10.10.
The change which old versions need to facilitate smooth(er) rolling upgrades turned out to be much more intrusive than I originally expected; it is worrisome, but I still believe it is the right thing to do: odd legacy behavior of timestamps has to be eventually abandoned, and given our release model, there is no way to do it other than accompanying it by a change in older post-GA versions.
Documentation-wise, I don't think that the switch from read-only to dynamic variable should be anyhow advertised, neither for old versions nor for 10.10; while it is done on technical reasons, we do not actually want users to start changing it at runtime. It is never needed, whatever users want to achieve by changing the variable at runtime, they can do instead by creating a table in a proper manner.
What should probably be highlighted for old GAs is that the default value of the variable will change in upcoming versions, so users are advised to start switching their instances to ON value as soon as possible globally , by setting it in the config file.
For 10.10, the focus should be on the change of the default, users need to be aware if they rely on the old behavior in their applications.
Galera users should pay special attention to it, since unlike for the traditional replication, nothing can be done to smoothen Galera rolling upgrades, users will have to handle the difference themselves.
I think that the variable "explicit_defaults_for_timestamp" has a bad name. I cannot by just looking at:
explicit_defaults_for_timestamp=OFF
understand what it will do.
First, the variable does affect CREATE TABLE, not defaults for existing timestamps.
Why does setting the variable to ON mean that there are are no defaults?
A better name would be something like
timestamp_in_create_table_has_current_time_as_default.
Note also that if we change timestamp to be NULL, it means it will take more storage space and if the user puts an index on the timestamp column, the performance for that index will be about 3-4 times slower (as the index will not anymore be fixed length)
Michael Widenius
added a comment - Just a few comments.
I think that the variable "explicit_defaults_for_timestamp" has a bad name. I cannot by just looking at:
explicit_defaults_for_timestamp=OFF
understand what it will do.
First, the variable does affect CREATE TABLE, not defaults for existing timestamps.
Why does setting the variable to ON mean that there are are no defaults?
A better name would be something like
timestamp_in_create_table_has_current_time_as_default.
Note also that if we change timestamp to be NULL, it means it will take more storage space and if the user puts an index on the timestamp column, the performance for that index will be about 3-4 times slower (as the index will not anymore be fixed length)
People
Sergei Golubchik
Ralf Gebhardt
Votes:
3Vote for this issue
Watchers:
7Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":1581.0999999046326,"ttfb":288,"pageVisibility":"visible","entityId":111174,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"b861a120-d129-4bb4-a5f2-4a91c57cda36","navigationType":0,"readyForUser":1646.2000002861023,"redirectCount":0,"resourceLoadedEnd":1242.5999999046326,"resourceLoadedStart":306.90000009536743,"resourceTiming":[{"duration":17.800000190734863,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":306.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":306.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":324.7000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":17.699999809265137,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":307.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":307.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":325,"responseStart":0,"secureConnectionStart":0},{"duration":613.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":307.40000009536743,"connectEnd":307.40000009536743,"connectStart":307.40000009536743,"domainLookupEnd":307.40000009536743,"domainLookupStart":307.40000009536743,"fetchStart":307.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":327.90000009536743,"responseEnd":920.5,"responseStart":370.30000019073486,"secureConnectionStart":307.40000009536743},{"duration":934,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":308.59999990463257,"connectEnd":308.59999990463257,"connectStart":308.59999990463257,"domainLookupEnd":308.59999990463257,"domainLookupStart":308.59999990463257,"fetchStart":308.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":328.5,"responseEnd":1242.5999999046326,"responseStart":439.90000009536743,"secureConnectionStart":308.59999990463257},{"duration":81.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":308.80000019073486,"connectEnd":308.80000019073486,"connectStart":308.80000019073486,"domainLookupEnd":308.80000019073486,"domainLookupStart":308.80000019073486,"fetchStart":308.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":329,"responseEnd":390,"responseStart":386.2000002861023,"secureConnectionStart":308.80000019073486},{"duration":82.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":308.90000009536743,"connectEnd":308.90000009536743,"connectStart":308.90000009536743,"domainLookupEnd":308.90000009536743,"domainLookupStart":308.90000009536743,"fetchStart":308.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":334,"responseEnd":391.5,"responseStart":390.30000019073486,"secureConnectionStart":308.90000009536743},{"duration":128.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":309.2000002861023,"connectEnd":309.2000002861023,"connectStart":309.2000002861023,"domainLookupEnd":309.2000002861023,"domainLookupStart":309.2000002861023,"fetchStart":309.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":334.59999990463257,"responseEnd":437.30000019073486,"responseStart":399.59999990463257,"secureConnectionStart":309.2000002861023},{"duration":19.09999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":309.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":309.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":328.5,"responseStart":0,"secureConnectionStart":0},{"duration":128,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":309.5,"connectEnd":309.5,"connectStart":309.5,"domainLookupEnd":309.5,"domainLookupStart":309.5,"fetchStart":309.5,"redirectEnd":0,"redirectStart":0,"requestStart":334.80000019073486,"responseEnd":437.5,"responseStart":406.2000002861023,"secureConnectionStart":309.5},{"duration":23.199999809265137,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/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":309.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":309.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":332.90000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":167.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/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":309.80000019073486,"connectEnd":309.80000019073486,"connectStart":309.80000019073486,"domainLookupEnd":309.80000019073486,"domainLookupStart":309.80000019073486,"fetchStart":309.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":335,"responseEnd":477.40000009536743,"responseStart":430.59999990463257,"secureConnectionStart":309.80000019073486},{"duration":903.1000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":337.59999990463257,"connectEnd":337.59999990463257,"connectStart":337.59999990463257,"domainLookupEnd":337.59999990463257,"domainLookupStart":337.59999990463257,"fetchStart":337.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":351,"responseEnd":1240.7000002861023,"responseStart":1166.2000002861023,"secureConnectionStart":337.59999990463257},{"duration":896.7999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":344.30000019073486,"connectEnd":344.30000019073486,"connectStart":344.30000019073486,"domainLookupEnd":344.30000019073486,"domainLookupStart":344.30000019073486,"fetchStart":344.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":370.2000002861023,"responseEnd":1241.0999999046326,"responseStart":1167.0999999046326,"secureConnectionStart":344.30000019073486},{"duration":285.09999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1064.7000002861023,"connectEnd":1064.7000002861023,"connectStart":1064.7000002861023,"domainLookupEnd":1064.7000002861023,"domainLookupStart":1064.7000002861023,"fetchStart":1064.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":1240.4000000953674,"responseEnd":1349.8000001907349,"responseStart":1338.8000001907349,"secureConnectionStart":1064.7000002861023}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":58,"responseStart":288,"responseEnd":344,"domLoading":296,"domInteractive":1738,"domContentLoadedEventStart":1738,"domContentLoadedEventEnd":1801,"domComplete":2281,"loadEventStart":2281,"loadEventEnd":2281,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1702.9000000953674},{"name":"bigPipe.sidebar-id.end","time":1703.8000001907349},{"name":"bigPipe.activity-panel-pipe-id.start","time":1704},{"name":"bigPipe.activity-panel-pipe-id.end","time":1709.4000000953674},{"name":"activityTabFullyLoaded","time":1833.5}],"measures":[],"correlationId":"acb3e3b16cdb71","effectiveType":"4g","downlink":9.2,"rtt":0,"serverDuration":128,"dbReadsTimeInMs":18,"dbConnsTimeInMs":28,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
A few examples to remind of the oddities caused by the current default behavior (with explicit_defaults_for_timestamp=OFF).
Only the first TIMESTAMP column gets the CURRENT_TIMESTAMP, but all TIMESTAMP columns get implicit NOT NULL and some default:
*************************** 1. row ***************************
If you add a new column before the first TIMESTAMP, you get two CURRENT_TIMESTAMP columns:
Records: 0 Duplicates: 0 Warnings: 0
*************************** 1. row ***************************
But if you add a new column after an existing TIMESTAMP, you won't:
Records: 0 Duplicates: 0 Warnings: 0
*************************** 1. row ***************************
If you "modify" the first timestamp, it will remain as it is:
Records: 0 Duplicates: 0 Warnings: 0
*************************** 1. row ***************************
If you modify another timestamp, it will lose CURRENT_TIMESTAMP properties:
Records: 0 Duplicates: 0 Warnings: 0
*************************** 1. row ***************************