1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +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:
unknown
2012-10-17 15:43:56 +03:00
parent 620d14f8c3
commit bc4a456758
61 changed files with 5375 additions and 540 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,94 @@
SET TIME_ZONE = "+00:00";
--echo #
--echo # Test of INSERT DELAYED ... SET ...
--echo #
--echo # 2011-04-19 08:02:40 UTC
SET TIMESTAMP = 1303200160.123456;
eval CREATE TABLE t1 ( a INT, b $timestamp NOT NULL DEFAULT CURRENT_$timestamp ON UPDATE CURRENT_$timestamp);
INSERT DELAYED INTO t1 SET a = 1;
FLUSH TABLE t1;
SELECT * FROM t1;
SELECT * FROM t1 WHERE b = 0;
INSERT DELAYED INTO t1 SET a = 2, b = '1980-01-02 10:20:30.405060';
FLUSH TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Test of INSERT DELAYED ... VALUES ...
--echo #
--echo # 2011-04-19 08:04:01 UTC
SET TIMESTAMP = 1303200241.234567;
eval CREATE TABLE t1 ( a INT, b $timestamp NOT NULL DEFAULT CURRENT_$timestamp ON UPDATE CURRENT_$timestamp);
INSERT DELAYED INTO t1 ( a ) VALUES (1);
FLUSH TABLE t1;
SELECT * FROM t1;
INSERT DELAYED INTO t1 VALUES (2, '1977-12-19 12:34:56.789123');
FLUSH TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Test of a delayed insert handler servicing two insert operations
--echo # with different sets of active defaults.
--echo #
eval CREATE TABLE t1 ( a INT, b $timestamp NOT NULL DEFAULT CURRENT_$timestamp ON UPDATE CURRENT_$timestamp);
--connect(con1, localhost, root,,)
--echo # 2011-04-19 08:04:01 UTC
SET TIMESTAMP = 1303200241.345678;
SET debug_sync = 'before_write_delayed SIGNAL parked WAIT_FOR go';
--send INSERT DELAYED INTO t1 ( a ) VALUES (1), (2), (3)
--connection default
SET debug_sync = 'now WAIT_FOR parked';
--connect(con2, localhost, root,,)
--echo # 2011-04-19 08:04:01 UTC
SET TIME_ZONE="+03:00";
SET TIMESTAMP = 1303200241.456789;
--send INSERT DELAYED INTO t1 ( a, b ) VALUES (4, '1977-12-19 12:34:56.789123'), (5, '1977-12-19 12:34:57.891234'), (6, '1977-12-19 12:34:58.912345')
--connection default
SET debug_sync = 'now SIGNAL go';
--let $wait_condition= SELECT COUNT(*) = 6 FROM t1
--source include/wait_condition.inc
--sorted_result
SELECT * FROM t1;
--disconnect con1
--disconnect con2
DROP TABLE t1;
--echo #
--echo # Test of early activation of function defaults.
--echo #
eval CREATE TABLE t1 ( a INT, b $timestamp NOT NULL DEFAULT CURRENT_$timestamp ON UPDATE CURRENT_$timestamp);
SET TIMESTAMP = 1317235172.987654; # 2011-09-28 18:39:32 UTC
INSERT DELAYED INTO t1 ( a ) VALUES (1), (2), (3);
SET TIMESTAMP = 385503754.876543; # 1982-03-20 20:22:34 UTC
INSERT DELAYED INTO t1 ( a ) VALUES (4), (5), (6);
FLUSH TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;

View File

@ -55,9 +55,9 @@ ERROR 42000: Incorrect table name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
create table a (`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` int);
ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long
create table t1 (a datetime default now());
ERROR 42000: Invalid default value for 'a'
drop table t1;
create table t1 (a datetime on update now());
ERROR HY000: Invalid ON UPDATE clause for 'a' column
drop table t1;
create table t1 (a int default 100 auto_increment);
ERROR 42000: Invalid default value for 'a'
create table t1 (a tinyint default 1000);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,171 @@
#
# Test of function defaults for non-embedded server.
#
#
# Function defaults run 1. No microsecond precision.
#
SET TIME_ZONE = "+00:00";
#
# Test of INSERT DELAYED ... SET ...
#
# 2011-04-19 08:02:40 UTC
SET TIMESTAMP = 1303200160.123456;
CREATE TABLE t1 ( a INT, b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
INSERT DELAYED INTO t1 SET a = 1;
FLUSH TABLE t1;
SELECT * FROM t1;
a b
1 2011-04-19 08:02:40
SELECT * FROM t1 WHERE b = 0;
a b
INSERT DELAYED INTO t1 SET a = 2, b = '1980-01-02 10:20:30.405060';
FLUSH TABLE t1;
SELECT * FROM t1;
a b
1 2011-04-19 08:02:40
2 1980-01-02 10:20:30
DROP TABLE t1;
#
# Test of INSERT DELAYED ... VALUES ...
#
# 2011-04-19 08:04:01 UTC
SET TIMESTAMP = 1303200241.234567;
CREATE TABLE t1 ( a INT, b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
INSERT DELAYED INTO t1 ( a ) VALUES (1);
FLUSH TABLE t1;
SELECT * FROM t1;
a b
1 2011-04-19 08:04:01
INSERT DELAYED INTO t1 VALUES (2, '1977-12-19 12:34:56.789123');
FLUSH TABLE t1;
SELECT * FROM t1;
a b
1 2011-04-19 08:04:01
2 1977-12-19 12:34:56
DROP TABLE t1;
#
# Test of a delayed insert handler servicing two insert operations
# with different sets of active defaults.
#
CREATE TABLE t1 ( a INT, b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
# 2011-04-19 08:04:01 UTC
SET TIMESTAMP = 1303200241.345678;
SET debug_sync = 'before_write_delayed SIGNAL parked WAIT_FOR go';
INSERT DELAYED INTO t1 ( a ) VALUES (1), (2), (3);
SET debug_sync = 'now WAIT_FOR parked';
# 2011-04-19 08:04:01 UTC
SET TIME_ZONE="+03:00";
SET TIMESTAMP = 1303200241.456789;
INSERT DELAYED INTO t1 ( a, b ) VALUES (4, '1977-12-19 12:34:56.789123'), (5, '1977-12-19 12:34:57.891234'), (6, '1977-12-19 12:34:58.912345');
SET debug_sync = 'now SIGNAL go';
SELECT * FROM t1;
a b
1 2011-04-19 08:04:01
2 2011-04-19 08:04:01
3 2011-04-19 08:04:01
4 1977-12-19 09:34:56
5 1977-12-19 09:34:57
6 1977-12-19 09:34:58
DROP TABLE t1;
#
# Test of early activation of function defaults.
#
CREATE TABLE t1 ( a INT, b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
SET TIMESTAMP = 1317235172.987654;
INSERT DELAYED INTO t1 ( a ) VALUES (1), (2), (3);
SET TIMESTAMP = 385503754.876543;
INSERT DELAYED INTO t1 ( a ) VALUES (4), (5), (6);
FLUSH TABLE t1;
SELECT * FROM t1;
a b
1 2011-09-28 18:39:32
2 2011-09-28 18:39:32
3 2011-09-28 18:39:32
4 1982-03-20 20:22:34
5 1982-03-20 20:22:34
6 1982-03-20 20:22:34
DROP TABLE t1;
#
# Function defaults run 2. Six digits scale on seconds precision.
#
SET TIME_ZONE = "+00:00";
#
# Test of INSERT DELAYED ... SET ...
#
# 2011-04-19 08:02:40 UTC
SET TIMESTAMP = 1303200160.123456;
CREATE TABLE t1 ( a INT, b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6));
INSERT DELAYED INTO t1 SET a = 1;
FLUSH TABLE t1;
SELECT * FROM t1;
a b
1 2011-04-19 08:02:40.123456
SELECT * FROM t1 WHERE b = 0;
a b
INSERT DELAYED INTO t1 SET a = 2, b = '1980-01-02 10:20:30.405060';
FLUSH TABLE t1;
SELECT * FROM t1;
a b
1 2011-04-19 08:02:40.123456
2 1980-01-02 10:20:30.405060
DROP TABLE t1;
#
# Test of INSERT DELAYED ... VALUES ...
#
# 2011-04-19 08:04:01 UTC
SET TIMESTAMP = 1303200241.234567;
CREATE TABLE t1 ( a INT, b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6));
INSERT DELAYED INTO t1 ( a ) VALUES (1);
FLUSH TABLE t1;
SELECT * FROM t1;
a b
1 2011-04-19 08:04:01.234567
INSERT DELAYED INTO t1 VALUES (2, '1977-12-19 12:34:56.789123');
FLUSH TABLE t1;
SELECT * FROM t1;
a b
1 2011-04-19 08:04:01.234567
2 1977-12-19 12:34:56.789123
DROP TABLE t1;
#
# Test of a delayed insert handler servicing two insert operations
# with different sets of active defaults.
#
CREATE TABLE t1 ( a INT, b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6));
# 2011-04-19 08:04:01 UTC
SET TIMESTAMP = 1303200241.345678;
SET debug_sync = 'before_write_delayed SIGNAL parked WAIT_FOR go';
INSERT DELAYED INTO t1 ( a ) VALUES (1), (2), (3);
SET debug_sync = 'now WAIT_FOR parked';
# 2011-04-19 08:04:01 UTC
SET TIME_ZONE="+03:00";
SET TIMESTAMP = 1303200241.456789;
INSERT DELAYED INTO t1 ( a, b ) VALUES (4, '1977-12-19 12:34:56.789123'), (5, '1977-12-19 12:34:57.891234'), (6, '1977-12-19 12:34:58.912345');
SET debug_sync = 'now SIGNAL go';
SELECT * FROM t1;
a b
1 2011-04-19 08:04:01.345678
2 2011-04-19 08:04:01.345678
3 2011-04-19 08:04:01.345678
4 1977-12-19 09:34:56.789123
5 1977-12-19 09:34:57.891234
6 1977-12-19 09:34:58.912345
DROP TABLE t1;
#
# Test of early activation of function defaults.
#
CREATE TABLE t1 ( a INT, b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6));
SET TIMESTAMP = 1317235172.987654;
INSERT DELAYED INTO t1 ( a ) VALUES (1), (2), (3);
SET TIMESTAMP = 385503754.876543;
INSERT DELAYED INTO t1 ( a ) VALUES (4), (5), (6);
FLUSH TABLE t1;
SELECT * FROM t1;
a b
1 2011-09-28 18:39:32.987654
2 2011-09-28 18:39:32.987654
3 2011-09-28 18:39:32.987654
4 1982-03-20 20:22:34.876543
5 1982-03-20 20:22:34.876543
6 1982-03-20 20:22:34.876543
DROP TABLE t1;

View File

@ -44,7 +44,7 @@ select @@log_slow_verbosity;
innodb
show fields from mysql.slow_log;
Field Type Null Key Default Extra
start_time timestamp(6) NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
start_time timestamp(6) NO CURRENT_TIMESTAMP(6) on update CURRENT_TIMESTAMP
user_host mediumtext NO NULL
query_time time(6) NO NULL
lock_time time(6) NO NULL

View File

@ -53,7 +53,7 @@ ERROR HY000: You can't use locks with log tables.
show create table mysql.general_log;
Table Create Table
general_log CREATE TABLE `general_log` (
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`thread_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
@ -62,7 +62,7 @@ general_log CREATE TABLE `general_log` (
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='General log'
show fields from mysql.general_log;
Field Type Null Key Default Extra
event_time timestamp(6) NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
event_time timestamp(6) NO CURRENT_TIMESTAMP(6) on update CURRENT_TIMESTAMP
user_host mediumtext NO NULL
thread_id int(11) NO NULL
server_id int(10) unsigned NO NULL
@ -71,7 +71,7 @@ argument mediumtext NO NULL
show create table mysql.slow_log;
Table Create Table
slow_log CREATE TABLE `slow_log` (
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`query_time` time(6) NOT NULL,
`lock_time` time(6) NOT NULL,
@ -85,7 +85,7 @@ slow_log CREATE TABLE `slow_log` (
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log'
show fields from mysql.slow_log;
Field Type Null Key Default Extra
start_time timestamp(6) NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
start_time timestamp(6) NO CURRENT_TIMESTAMP(6) on update CURRENT_TIMESTAMP
user_host mediumtext NO NULL
query_time time(6) NO NULL
lock_time time(6) NO NULL
@ -164,7 +164,7 @@ set global slow_query_log='OFF';
show create table mysql.general_log;
Table Create Table
general_log CREATE TABLE `general_log` (
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`thread_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
@ -174,7 +174,7 @@ general_log CREATE TABLE `general_log` (
show create table mysql.slow_log;
Table Create Table
slow_log CREATE TABLE `slow_log` (
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`query_time` time(6) NOT NULL,
`lock_time` time(6) NOT NULL,
@ -191,7 +191,7 @@ alter table mysql.slow_log engine=myisam;
show create table mysql.general_log;
Table Create Table
general_log CREATE TABLE `general_log` (
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`thread_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
@ -201,7 +201,7 @@ general_log CREATE TABLE `general_log` (
show create table mysql.slow_log;
Table Create Table
slow_log CREATE TABLE `slow_log` (
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`query_time` time(6) NOT NULL,
`lock_time` time(6) NOT NULL,

View File

@ -5239,7 +5239,7 @@ Error 1146 Table 'mysql.event' doesn't exist
SHOW CREATE TABLE mysql.general_log;
Table Create Table
general_log CREATE TABLE `general_log` (
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`thread_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
@ -5249,7 +5249,7 @@ general_log CREATE TABLE `general_log` (
SHOW CREATE TABLE mysql.slow_log;
Table Create Table
slow_log CREATE TABLE `slow_log` (
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`query_time` time(6) NOT NULL,
`lock_time` time(6) NOT NULL,

View File

@ -242,7 +242,7 @@ event CREATE TABLE `event` (
show create table general_log;
Table Create Table
general_log CREATE TABLE `general_log` (
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`thread_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
@ -252,7 +252,7 @@ general_log CREATE TABLE `general_log` (
show create table slow_log;
Table Create Table
slow_log CREATE TABLE `slow_log` (
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`query_time` time(6) NOT NULL,
`lock_time` time(6) NOT NULL,

View File

@ -242,7 +242,7 @@ event CREATE TABLE `event` (
show create table general_log;
Table Create Table
general_log CREATE TABLE `general_log` (
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`thread_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
@ -252,7 +252,7 @@ general_log CREATE TABLE `general_log` (
show create table slow_log;
Table Create Table
slow_log CREATE TABLE `slow_log` (
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`query_time` time(6) NOT NULL,
`lock_time` time(6) NOT NULL,

View File

@ -242,7 +242,7 @@ event CREATE TABLE `event` (
show create table general_log;
Table Create Table
general_log CREATE TABLE `general_log` (
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`thread_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
@ -252,7 +252,7 @@ general_log CREATE TABLE `general_log` (
show create table slow_log;
Table Create Table
slow_log CREATE TABLE `slow_log` (
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`query_time` time(6) NOT NULL,
`lock_time` time(6) NOT NULL,

View File

@ -242,7 +242,7 @@ event CREATE TABLE `event` (
show create table general_log;
Table Create Table
general_log CREATE TABLE `general_log` (
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`thread_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
@ -252,7 +252,7 @@ general_log CREATE TABLE `general_log` (
show create table slow_log;
Table Create Table
slow_log CREATE TABLE `slow_log` (
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`user_host` mediumtext NOT NULL,
`query_time` time(6) NOT NULL,
`lock_time` time(6) NOT NULL,

View File

@ -148,15 +148,15 @@ ix+0
20030101000000
drop table t1;
create table t1 (t1 timestamp, t2 timestamp default now());
ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
drop table t1;
create table t1 (t1 timestamp, t2 timestamp on update now());
ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
drop table t1;
create table t1 (t1 timestamp, t2 timestamp default now() on update now());
ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
drop table t1;
create table t1 (t1 timestamp default now(), t2 timestamp on update now());
ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
drop table t1;
create table t1 (t1 timestamp on update now(), t2 timestamp default now() on update now());
ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
drop table t1;
create table t1 (t1 timestamp default '2003-01-01 00:00:00', t2 datetime, t3 timestamp);
SET TIMESTAMP=1000000000;
insert into t1 values ();

View File

@ -63,15 +63,15 @@ a
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` timestamp(4) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
`a` timestamp(4) NOT NULL DEFAULT CURRENT_TIMESTAMP(4) ON UPDATE CURRENT_TIMESTAMP(4)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
show columns from t1;
Field Type Null Key Default Extra
a timestamp(4) NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
a timestamp(4) NO CURRENT_TIMESTAMP(4) on update CURRENT_TIMESTAMP
select table_name, column_name, column_default, is_nullable, data_type, character_maximum_length, character_octet_length, numeric_precision, numeric_scale, datetime_precision, character_set_name, collation_name, column_type, column_key, extra from information_schema.columns where table_name='t1';
table_name t1
column_name a
column_default CURRENT_TIMESTAMP
column_default CURRENT_TIMESTAMP(4)
is_nullable NO
data_type timestamp
character_maximum_length NULL
@ -113,7 +113,7 @@ t2 CREATE TABLE `t2` (
show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`a` timestamp(4) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
`a` timestamp(4) NOT NULL DEFAULT CURRENT_TIMESTAMP(4) ON UPDATE CURRENT_TIMESTAMP(4)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
drop table t2, t3;
insert t1 values ('2010-12-13 14:15:16.222222');

View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<database name="test">
<table_structure name="onerow">
<field Field="a" Type="int(11)" Null="YES" Key="" Extra="" />
</table_structure>
<table_data name="onerow">
<row>
<field name="a">1</field>
</row>
</table_data>
</database>
</mysqldump>

View File

@ -59,7 +59,7 @@ def mysql func ret 2 0 NO tinyint NULL NULL 3 0 NULL NULL NULL tinyint(1) sele
def mysql func type 4 NULL NO enum 9 27 NULL NULL NULL utf8 utf8_general_ci enum('function','aggregate') select,insert,update,references
def mysql general_log argument 6 NULL NO mediumtext 16777215 16777215 NULL NULL NULL utf8 utf8_general_ci mediumtext select,insert,update,references
def mysql general_log command_type 5 NULL NO varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) select,insert,update,references
def mysql general_log event_time 1 CURRENT_TIMESTAMP NO timestamp NULL NULL NULL NULL 6 NULL NULL timestamp(6) on update CURRENT_TIMESTAMP select,insert,update,references
def mysql general_log event_time 1 CURRENT_TIMESTAMP(6) NO timestamp NULL NULL NULL NULL 6 NULL NULL timestamp(6) on update CURRENT_TIMESTAMP select,insert,update,references
def mysql general_log server_id 4 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select,insert,update,references
def mysql general_log thread_id 3 NULL NO int NULL NULL 10 0 NULL NULL NULL int(11) select,insert,update,references
def mysql general_log user_host 2 NULL NO mediumtext 16777215 16777215 NULL NULL NULL utf8 utf8_general_ci mediumtext select,insert,update,references
@ -159,7 +159,7 @@ def mysql slow_log rows_examined 6 NULL NO int NULL NULL 10 0 NULL NULL NULL int
def mysql slow_log rows_sent 5 NULL NO int NULL NULL 10 0 NULL NULL NULL int(11) select,insert,update,references
def mysql slow_log server_id 10 NULL NO int NULL NULL 10 0 NULL NULL NULL int(10) unsigned select,insert,update,references
def mysql slow_log sql_text 11 NULL NO mediumtext 16777215 16777215 NULL NULL NULL utf8 utf8_general_ci mediumtext select,insert,update,references
def mysql slow_log start_time 1 CURRENT_TIMESTAMP NO timestamp NULL NULL NULL NULL 6 NULL NULL timestamp(6) on update CURRENT_TIMESTAMP select,insert,update,references
def mysql slow_log start_time 1 CURRENT_TIMESTAMP(6) NO timestamp NULL NULL NULL NULL 6 NULL NULL timestamp(6) on update CURRENT_TIMESTAMP select,insert,update,references
def mysql slow_log user_host 2 NULL NO mediumtext 16777215 16777215 NULL NULL NULL utf8 utf8_general_ci mediumtext select,insert,update,references
def mysql tables_priv Column_priv 8 NO set 31 93 NULL NULL NULL utf8 utf8_general_ci set('Select','Insert','Update','References') select,insert,update,references
def mysql tables_priv Db 2 NO char 64 192 NULL NULL NULL utf8 utf8_bin char(64) PRI select,insert,update,references

View File

@ -0,0 +1,132 @@
#
# Test of function defaults on replicated tables.
#
include/master-slave.inc
[connection master]
connection master
SET TIME_ZONE="+10:30";
SET TIMESTAMP=123456.789123;
SELECT CURRENT_TIMESTAMP;
CURRENT_TIMESTAMP
1970-01-02 20:47:36
connection slave
SET TIME_ZONE="+00:00";
SET TIMESTAMP=987654321.123456;
SELECT CURRENT_TIMESTAMP;
CURRENT_TIMESTAMP
2001-04-19 04:25:21
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 );
sync_slave_with_master
connection slave
SELECT * FROM t1;
a 1970-01-02 10:17:36
b 1970-01-02 10:17:36.7
c 1970-01-02 10:17:36.78
d 1970-01-02 10:17:36.789
e 1970-01-02 10:17:36.7891
f 1970-01-02 10:17:36.78912
g 1970-01-02 10:17:36.789123
h 1970-01-02 20:47:36
i 1970-01-02 20:47:36.7
j 1970-01-02 20:47:36.78
k 1970-01-02 20:47:36.789
l 1970-01-02 20:47:36.7891
m 1970-01-02 20:47:36.78912
n 1970-01-02 20:47:36.789123
o 1
SELECT * FROM t2;
a 0000-00-00 00:00:00
b 0000-00-00 00:00:00.0
c 0000-00-00 00:00:00.00
d 0000-00-00 00:00:00.000
e 0000-00-00 00:00:00.0000
f 0000-00-00 00:00:00.00000
g 0000-00-00 00:00:00.000000
h NULL
i NULL
j NULL
k NULL
l NULL
m NULL
n NULL
o 1
connection master
SET TIMESTAMP=1234567890.123456;
SELECT CURRENT_TIMESTAMP;
CURRENT_TIMESTAMP
2009-02-14 10:01:30
UPDATE t1 SET o = 2;
UPDATE t2 SET o = 2;
sync_slave_with_master
connection slave
SELECT * FROM t1;
a 1970-01-02 10:17:36
b 1970-01-02 10:17:36.7
c 1970-01-02 10:17:36.78
d 1970-01-02 10:17:36.789
e 1970-01-02 10:17:36.7891
f 1970-01-02 10:17:36.78912
g 1970-01-02 10:17:36.789123
h 1970-01-02 20:47:36
i 1970-01-02 20:47:36.7
j 1970-01-02 20:47:36.78
k 1970-01-02 20:47:36.789
l 1970-01-02 20:47:36.7891
m 1970-01-02 20:47:36.78912
n 1970-01-02 20:47:36.789123
o 2
SELECT * FROM t2;
a 2009-02-13 23:31:30
b 2009-02-13 23:31:30.1
c 2009-02-13 23:31:30.12
d 2009-02-13 23:31:30.123
e 2009-02-13 23:31:30.1234
f 2009-02-13 23:31:30.12345
g 2009-02-13 23:31:30.123456
h 2009-02-14 10:01:30
i 2009-02-14 10:01:30.1
j 2009-02-14 10:01:30.12
k 2009-02-14 10:01:30.123
l 2009-02-14 10:01:30.1234
m 2009-02-14 10:01:30.12345
n 2009-02-14 10:01:30.123456
o 2
connection master
DROP TABLE t1, t2;
include/rpl_end.inc

View 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

View File

@ -55,10 +55,10 @@ create table a (`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#
# Some wrong defaults, so these creates should fail too (Bug #5902)
#
--error 1067
create table t1 (a datetime default now());
--error 1294
drop table t1;
create table t1 (a datetime on update now());
drop table t1;
--error 1067
create table t1 (a int default 100 auto_increment);
--error 1067

View File

@ -0,0 +1,23 @@
--echo #
--echo # Test of function defaults for any server, including embedded.
--echo #
--source include/have_innodb.inc
--echo #
--echo # Function defaults run 1. No microsecond precision.
--echo #
let $current_timestamp=CURRENT_TIMESTAMP;
let $now=NOW();
let $timestamp=TIMESTAMP;
let $datetime=DATETIME;
source 'include/function_defaults.inc';
--echo #
--echo # Function defaults run 2. Six digits scale on seconds precision.
--echo #
let $current_timestamp=CURRENT_TIMESTAMP(6);
let $now=NOW(6);
let $timestamp=TIMESTAMP(6);
let $datetime=DATETIME(6);
source 'include/function_defaults.inc';

View File

@ -0,0 +1,18 @@
--echo #
--echo # Test of function defaults for non-embedded server.
--echo #
--source include/not_embedded.inc
--source include/have_debug_sync.inc
--echo #
--echo # Function defaults run 1. No microsecond precision.
--echo #
let $timestamp=TIMESTAMP;
--source include/function_defaults_notembedded.inc
--echo #
--echo # Function defaults run 2. Six digits scale on seconds precision.
--echo #
let $timestamp=TIMESTAMP(6);
--source include/function_defaults_notembedded.inc

View File

@ -86,17 +86,16 @@ drop table t1;
# Test for TIMESTAMP column with default now() and on update now() clauses
#
# These statements should fail.
--error 1293
create table t1 (t1 timestamp, t2 timestamp default now());
--error 1293
drop table t1;
create table t1 (t1 timestamp, t2 timestamp on update now());
--error 1293
drop table t1;
create table t1 (t1 timestamp, t2 timestamp default now() on update now());
--error 1293
drop table t1;
create table t1 (t1 timestamp default now(), t2 timestamp on update now());
--error 1293
drop table t1;
create table t1 (t1 timestamp on update now(), t2 timestamp default now() on update now());
drop table t1;
# Let us test TIMESTAMP auto-update behaviour
# Also we will test behaviour of TIMESTAMP field in SHOW CREATE TABLE and