Bug #99513 | "ALTER TABLE ... ADD ... DEFAULT now()" generates wrong time at first INSERT | ||
---|---|---|---|
Submitted: | 11 May 2020 13:21 | Modified: | 8 Jun 2020 13:22 |
Reporter: | Wim Goedertier | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Data Types | Severity: | S3 (Non-critical) |
Version: | OS: | Any | |
Assigned to: | CPU Architecture: | Any |
[11 May 2020 13:21]
Wim Goedertier
[11 May 2020 13:28]
Wim Goedertier
If I replace now() by sysdate() (and ADD by MODIFY to circumvent bug #99512) the problem doesn't pop up. DROP TABLE IF EXISTS tst1; CREATE TABLE tst1 ( id DECIMAL(3), date1 DATETIME DEFAULT (sysdate()) ); ALTER TABLE tst1 MODIFY date1 DATETIME DEFAULT (sysdate()); SELECT sysdate(), SLEEP(5), sysdate(); INSERT INTO tst1 (id) VALUES (1); SELECT * FROM tst1; DESCRIBE tst1; DROP TABLE IF EXISTS tst1; CREATE TABLE tst1 ( id DECIMAL(3), date1 DATETIME DEFAULT (sysdate()) ); SELECT sysdate(), SLEEP(5), sysdate(); INSERT INTO tst1 (id) VALUES (1); SELECT * FROM tst1; DESCRIBE tst1; DROP TABLE IF EXISTS tst1; CREATE TABLE tst1 ( id DECIMAL(3), date1 DATETIME DEFAULT (sysdate()), date2 DATETIME DEFAULT (sysdate()) ); ALTER TABLE tst1 MODIFY date2 DATETIME DEFAULT (sysdate()); SELECT sysdate(), SLEEP(5), sysdate(); INSERT INTO tst1 (id) VALUES (1); SELECT * FROM tst1; DESCRIBE tst1;
[11 May 2020 14:07]
MySQL Verification Team
Hi Mr. Goedertier, Thank you for your bug report. I have managed to repeat it with 8.0.20, by introducing one minute of sleep between ALTER and INSERT: now() 2020-05-11 17:03:40 Field Type Null Key Default Extra id decimal(3,0) YES NULL mydate datetime YES now() DEFAULT_GENERATED now() 2020-05-11 17:03:40 sleep(60) 0 now() 2020-05-11 17:04:40 id mydate 1 2020-05-11 17:03:40 Verified as reported.
[8 Jun 2020 13:22]
Paul DuBois
Posted by developer: Fixed in 8.0.22. After ALTER TABLE to add an expression default to a column, the first insert inserted a value as if the expression had been evaluated at alter time and not insert time.
[9 Jun 2020 12:10]
MySQL Verification Team
Thank you, Paul.