mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
MDEV-452 Add full support for auto-initialized/updated timestamp and datetime
Generalized support for auto-updated and/or auto-initialized timestamp and datetime columns. This patch is a reimplementation of MySQL's "WL#5874: CURRENT_TIMESTAMP as DEFAULT for DATETIME columns". In order to ease future merges, this implementation reused few function and variable names from MySQL's patch, however the implementation is quite different. TODO: The only unresolved problem in this patch is the semantics of LOAD DATA for TIMESTAMP and DATETIME columns in the cases when there are missing or NULL columns. I couldn't fully comprehend the logic behind MySQL's behavior and its relationship with their own documentation, so I left the results to be more consistent with all other LOAD cases. The problematic test cases can be seen by running the test file function_defaults, and observing the test case differences. Those were left on purpose for discussion.
This commit is contained in:
93
mysql-test/suite/rpl/t/rpl_function_defaults.test
Normal file
93
mysql-test/suite/rpl/t/rpl_function_defaults.test
Normal file
@@ -0,0 +1,93 @@
|
||||
--echo #
|
||||
--echo # Test of function defaults on replicated tables.
|
||||
--echo #
|
||||
|
||||
source include/master-slave.inc;
|
||||
|
||||
--echo connection master
|
||||
connection master;
|
||||
SET TIME_ZONE="+10:30";
|
||||
SET TIMESTAMP=123456.789123;
|
||||
SELECT CURRENT_TIMESTAMP;
|
||||
|
||||
--echo connection slave
|
||||
connection slave;
|
||||
SET TIME_ZONE="+00:00";
|
||||
SET TIMESTAMP=987654321.123456;
|
||||
SELECT CURRENT_TIMESTAMP;
|
||||
|
||||
--echo connection master
|
||||
connection master;
|
||||
CREATE TABLE t1 (
|
||||
a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
b TIMESTAMP(1) NOT NULL DEFAULT CURRENT_TIMESTAMP(1),
|
||||
c TIMESTAMP(2) NOT NULL DEFAULT CURRENT_TIMESTAMP(2),
|
||||
d TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
e TIMESTAMP(4) NOT NULL DEFAULT CURRENT_TIMESTAMP(4),
|
||||
f TIMESTAMP(5) NOT NULL DEFAULT CURRENT_TIMESTAMP(5),
|
||||
g TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
|
||||
h DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
i DATETIME(1) DEFAULT CURRENT_TIMESTAMP(1),
|
||||
j DATETIME(2) DEFAULT CURRENT_TIMESTAMP(2),
|
||||
k DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3),
|
||||
l DATETIME(4) DEFAULT CURRENT_TIMESTAMP(4),
|
||||
m DATETIME(5) DEFAULT CURRENT_TIMESTAMP(5),
|
||||
n DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6),
|
||||
o INT
|
||||
);
|
||||
|
||||
INSERT INTO t1 ( o ) VALUES ( 1 );
|
||||
|
||||
CREATE TABLE t2 (
|
||||
a TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
|
||||
b TIMESTAMP(1) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(1),
|
||||
c TIMESTAMP(2) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(2),
|
||||
d TIMESTAMP(3) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
e TIMESTAMP(4) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(4),
|
||||
f TIMESTAMP(5) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(5),
|
||||
g TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6),
|
||||
h DATETIME ON UPDATE CURRENT_TIMESTAMP,
|
||||
i DATETIME(1) ON UPDATE CURRENT_TIMESTAMP(1),
|
||||
j DATETIME(2) ON UPDATE CURRENT_TIMESTAMP(2),
|
||||
k DATETIME(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
l DATETIME(4) ON UPDATE CURRENT_TIMESTAMP(4),
|
||||
m DATETIME(5) ON UPDATE CURRENT_TIMESTAMP(5),
|
||||
n DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||||
o INT
|
||||
);
|
||||
|
||||
INSERT INTO t2 ( o ) VALUES ( 1 );
|
||||
|
||||
--echo sync_slave_with_master
|
||||
sync_slave_with_master;
|
||||
|
||||
--echo connection slave
|
||||
connection slave;
|
||||
|
||||
query_vertical SELECT * FROM t1;
|
||||
query_vertical SELECT * FROM t2;
|
||||
|
||||
--echo connection master
|
||||
connection master;
|
||||
|
||||
SET TIMESTAMP=1234567890.123456;
|
||||
SELECT CURRENT_TIMESTAMP;
|
||||
|
||||
UPDATE t1 SET o = 2;
|
||||
UPDATE t2 SET o = 2;
|
||||
|
||||
--echo sync_slave_with_master
|
||||
sync_slave_with_master;
|
||||
|
||||
--echo connection slave
|
||||
connection slave;
|
||||
|
||||
query_vertical SELECT * FROM t1;
|
||||
query_vertical SELECT * FROM t2;
|
||||
|
||||
--echo connection master
|
||||
connection master;
|
||||
|
||||
DROP TABLE t1, t2;
|
||||
|
||||
--source include/rpl_end.inc
|
Reference in New Issue
Block a user