Commit 3579f5f9 authored by Aleksey Midenkov's avatar Aleksey Midenkov

Tests: insert, update, delete, insert_select, insert_update, multi_update

parent 53a892fc
...@@ -526,27 +526,56 @@ ERROR HY000: Can not delete from join view 'test.v2' ...@@ -526,27 +526,56 @@ ERROR HY000: Can not delete from join view 'test.v2'
DROP VIEW v2, v1; DROP VIEW v2, v1;
DROP TABLE t1, t2; DROP TABLE t1, t2;
# #
# Test for SYSTEM VERSIONING # System Versioning Support
# #
SET @@session.time_zone='+00:00'; #
create table t1 ( set @@session.time_zone='+00:00';
XNo INT UNSIGNED, select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, create procedure test_01(
Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, sys_type varchar(255),
PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end) engine varchar(255),
) WITH SYSTEM VERSIONING; fields varchar(255))
INSERT INTO t1(XNo) VALUES(0); begin
INSERT INTO t1(XNo) VALUES(1); set @str= concat('
INSERT INTO t1(XNo) VALUES(2); create table t1(
INSERT INTO t1(XNo) VALUES(3); XNo int unsigned,
INSERT INTO t1(XNo) VALUES(4); sys_start ', sys_type, ' generated always as row start,
INSERT INTO t1(XNo) VALUES(5); sys_end ', sys_type, ' generated always as row end,
INSERT INTO t1(XNo) VALUES(6); period for system_time (sys_start, sys_end))
INSERT INTO t1(XNo) VALUES(7); with system versioning
INSERT INTO t1(XNo) VALUES(8); engine ', engine);
INSERT INTO t1(XNo) VALUES(9); prepare stmt from @str; execute stmt; drop prepare stmt;
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07'; insert into t1(XNo) values(0);
XNo Sys_end < '2038-01-19 03:14:07' insert into t1(XNo) values(1);
insert into t1(XNo) values(2);
insert into t1(XNo) values(3);
insert into t1(XNo) values(4);
insert into t1(XNo) values(5);
insert into t1(XNo) values(6);
insert into t1(XNo) values(7);
insert into t1(XNo) values(8);
insert into t1(XNo) values(9);
set @str= concat('select XNo, ',
fields, " < '2038-01-19 03:14:07'
from t1 for system_time
between timestamp '0000-0-0 0:0:0'
and timestamp '2038-01-19 04:14:07'");
prepare stmt from @str; execute stmt;
delete from t1 where XNo = 0;
execute stmt;
delete from t1 where XNo = 1;
execute stmt;
delete from t1 where XNo > 5;
create view vt1 as select XNo from t1;
select XNo from vt1;
delete from vt1 where XNo = 3;
select XNo from vt1;
execute stmt; drop prepare stmt;
drop view vt1;
drop table t1;
end~~
call test_01('timestamp(6)', 'myisam', 'sys_end');
XNo sys_end < '2038-01-19 03:14:07'
0 0 0 0
1 0 1 0
2 0 2 0
...@@ -557,9 +586,7 @@ XNo Sys_end < '2038-01-19 03:14:07' ...@@ -557,9 +586,7 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 0 7 0
8 0 8 0
9 0 9 0
DELETE FROM t1 WHERE XNo = 0; XNo sys_end < '2038-01-19 03:14:07'
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07';
XNo Sys_end < '2038-01-19 03:14:07'
0 1 0 1
1 0 1 0
2 0 2 0
...@@ -570,9 +597,7 @@ XNo Sys_end < '2038-01-19 03:14:07' ...@@ -570,9 +597,7 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 0 7 0
8 0 8 0
9 0 9 0
DELETE FROM t1 WHERE XNo = 1; XNo sys_end < '2038-01-19 03:14:07'
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07';
XNo Sys_end < '2038-01-19 03:14:07'
0 1 0 1
1 1 1 1
2 0 2 0
...@@ -583,22 +608,16 @@ XNo Sys_end < '2038-01-19 03:14:07' ...@@ -583,22 +608,16 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 0 7 0
8 0 8 0
9 0 9 0
DELETE FROM t1 WHERE XNo > 5;
CREATE VIEW vt1 AS SELECT XNo FROM t1;
SELECT XNo FROM vt1;
XNo XNo
2 2
3 3
4 4
5 5
DELETE FROM vt1 WHERE XNo = 3;
SELECT XNo FROM vt1;
XNo XNo
2 2
4 4
5 5
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07'; XNo sys_end < '2038-01-19 03:14:07'
XNo Sys_end < '2038-01-19 03:14:07'
0 1 0 1
1 1 1 1
2 0 2 0
...@@ -609,27 +628,8 @@ XNo Sys_end < '2038-01-19 03:14:07' ...@@ -609,27 +628,8 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 1 7 1
8 1 8 1
9 1 9 1
DROP VIEW vt1; call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
DROP TABLE t1; XNo commit_ts(sys_end) < '2038-01-19 03:14:07'
select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
create table t1 (
XNo INT UNSIGNED,
Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START,
Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)
) WITH SYSTEM VERSIONING ENGINE InnoDB;
INSERT INTO t1(XNo) VALUES(0);
INSERT INTO t1(XNo) VALUES(1);
INSERT INTO t1(XNo) VALUES(2);
INSERT INTO t1(XNo) VALUES(3);
INSERT INTO t1(XNo) VALUES(4);
INSERT INTO t1(XNo) VALUES(5);
INSERT INTO t1(XNo) VALUES(6);
INSERT INTO t1(XNo) VALUES(7);
INSERT INTO t1(XNo) VALUES(8);
INSERT INTO t1(XNo) VALUES(9);
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07';
XNo Sys_end < '2038-01-19 03:14:07'
0 0 0 0
1 0 1 0
2 0 2 0
...@@ -640,9 +640,7 @@ XNo Sys_end < '2038-01-19 03:14:07' ...@@ -640,9 +640,7 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 0 7 0
8 0 8 0
9 0 9 0
DELETE FROM t1 WHERE XNo = 0; XNo commit_ts(sys_end) < '2038-01-19 03:14:07'
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07';
XNo Sys_end < '2038-01-19 03:14:07'
0 1 0 1
1 0 1 0
2 0 2 0
...@@ -653,9 +651,7 @@ XNo Sys_end < '2038-01-19 03:14:07' ...@@ -653,9 +651,7 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 0 7 0
8 0 8 0
9 0 9 0
DELETE FROM t1 WHERE XNo = 1; XNo commit_ts(sys_end) < '2038-01-19 03:14:07'
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07';
XNo Sys_end < '2038-01-19 03:14:07'
0 1 0 1
1 1 1 1
2 0 2 0
...@@ -666,22 +662,16 @@ XNo Sys_end < '2038-01-19 03:14:07' ...@@ -666,22 +662,16 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 0 7 0
8 0 8 0
9 0 9 0
DELETE FROM t1 WHERE XNo > 5;
CREATE VIEW vt1 AS SELECT XNo FROM t1;
SELECT XNo FROM vt1;
XNo XNo
2 2
3 3
4 4
5 5
DELETE FROM vt1 WHERE XNo = 3;
SELECT XNo FROM vt1;
XNo XNo
2 2
4 4
5 5
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07'; XNo commit_ts(sys_end) < '2038-01-19 03:14:07'
XNo Sys_end < '2038-01-19 03:14:07'
0 1 0 1
1 1 1 1
2 0 2 0
...@@ -692,10 +682,23 @@ XNo Sys_end < '2038-01-19 03:14:07' ...@@ -692,10 +682,23 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 1 7 1
8 1 8 1
9 1 9 1
DROP VIEW vt1; drop procedure test_01;
DROP TABLE t1; create procedure verify_vtq()
SET @i = 0; begin
SELECT @i:=@i+1 AS No, trx_id > 0 AS A, begin_ts > '2015-1-1 0:0:0' AS B, commit_ts > begin_ts AS C, concurr_trx IS NULL AS D FROM INFORMATION_SCHEMA.INNODB_VTQ WHERE trx_id > @start_trx_id; set @i= 0;
select
@i:= @i + 1 as No,
trx_id > 0 as A,
begin_ts > '1-1-1 0:0:0' as B,
commit_ts > begin_ts as C,
concurr_trx is null as D
from information_schema.innodb_vtq
where trx_id > @start_trx_id;
select ifnull(max(trx_id), 0)
into @start_trx_id
from information_schema.innodb_vtq;
end~~
call verify_vtq;
No A B C D No A B C D
1 1 1 1 1 1 1 1 1 1
2 1 1 1 1 2 1 1 1 1
...@@ -711,3 +714,4 @@ No A B C D ...@@ -711,3 +714,4 @@ No A B C D
12 1 1 1 1 12 1 1 1 1
13 1 1 1 1 13 1 1 1 1
14 1 1 1 1 14 1 1 1 1
drop procedure verify_vtq;
...@@ -721,114 +721,165 @@ DROP TABLE t1; ...@@ -721,114 +721,165 @@ DROP TABLE t1;
# System Versioning Support # System Versioning Support
# #
# #
SET @@session.time_zone='+00:00'; set @@session.time_zone='+00:00';
select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq; select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING; create procedure test_01(
INSERT INTO t1(x, y) VALUES(3, 4); sys_type varchar(255),
INSERT INTO t1(x, y) VALUES(2, 3); engine varchar(255),
INSERT INTO t1 VALUES(40, 33); fields varchar(255))
SELECT x, y, Sys_end FROM t1; begin
x y Sys_end set @str= concat('
create table t1(
x int unsigned,
y int unsigned,
sys_start ', sys_type, ' generated always as row start,
sys_end ', sys_type, ' generated always as row end,
period for system_time (sys_start, sys_end))
with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
insert into t1(x, y) values(3, 4);
insert into t1(x, y) values(2, 3);
insert into t1 values(40, 33);
set @str= concat('select x, y, ', fields, ' from t1');
prepare stmt from @str; execute stmt; drop prepare stmt;
drop table t1;
end~~
call test_01('timestamp(6)', 'myisam', 'sys_end');
x y sys_end
3 4 2038-01-19 03:14:07.000000 3 4 2038-01-19 03:14:07.000000
2 3 2038-01-19 03:14:07.000000 2 3 2038-01-19 03:14:07.000000
40 33 2038-01-19 03:14:07.000000 40 33 2038-01-19 03:14:07.000000
DROP TABLE t1; call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB; x y commit_ts(sys_end)
INSERT INTO t1(x, y) VALUES(3, 4);
INSERT INTO t1(x, y) VALUES(2, 3);
INSERT INTO t1 VALUES(40, 33);
SELECT x, y, Sys_end FROM t1;
x y Sys_end
3 4 2038-01-19 03:14:07.000000 3 4 2038-01-19 03:14:07.000000
2 3 2038-01-19 03:14:07.000000 2 3 2038-01-19 03:14:07.000000
40 33 2038-01-19 03:14:07.000000 40 33 2038-01-19 03:14:07.000000
DROP TABLE t1; drop procedure test_01;
CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT, x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end), PRIMARY KEY(id)) WITH SYSTEM VERSIONING; create procedure test_02(
INSERT INTO t1(x, y) VALUES(33, 44); sys_type varchar(255),
INSERT INTO t1(id, x, y) VALUES(20, 33, 44); engine varchar(255),
INSERT INTO t1 VALUES(40, 33, 44); fields varchar(255))
SELECT id, x, y, Sys_end FROM t1; begin
id x y Sys_end set @str= concat('
create table t1(
id int unsigned auto_increment primary key,
x int unsigned,
y int unsigned,
sys_start ', sys_type, ' generated always as row start,
sys_end ', sys_type, ' generated always as row end,
period for system_time (sys_start, sys_end))
with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
insert into t1(x, y) values(33, 44);
insert into t1(id, x, y) values(20, 33, 44);
insert into t1 values(40, 33, 44);
set @str= concat('select id, x, y, ', fields, ' from t1');
prepare stmt from @str; execute stmt; drop prepare stmt;
drop table t1;
end~~
call test_02('timestamp(6)', 'myisam', 'sys_end');
id x y sys_end
1 33 44 2038-01-19 03:14:07.000000 1 33 44 2038-01-19 03:14:07.000000
20 33 44 2038-01-19 03:14:07.000000 20 33 44 2038-01-19 03:14:07.000000
40 33 44 2038-01-19 03:14:07.000000 40 33 44 2038-01-19 03:14:07.000000
DROP TABLE t1; call test_02('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT, x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end), PRIMARY KEY(id)) WITH SYSTEM VERSIONING ENGINE=InnoDB; id x y commit_ts(sys_end)
INSERT INTO t1(x, y) VALUES(33, 44);
INSERT INTO t1(id, x, y) VALUES(20, 33, 44);
INSERT INTO t1 VALUES(40, 33, 44);
SELECT id, x, y, Sys_end FROM t1;
id x y Sys_end
1 33 44 2038-01-19 03:14:07.000000 1 33 44 2038-01-19 03:14:07.000000
20 33 44 2038-01-19 03:14:07.000000 20 33 44 2038-01-19 03:14:07.000000
40 33 44 2038-01-19 03:14:07.000000 40 33 44 2038-01-19 03:14:07.000000
DROP TABLE t1; drop procedure test_02;
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING; create procedure test_03(
CREATE VIEW vt1_1 AS SELECT x, y FROM t1; sys_type varchar(255),
CREATE VIEW vt1_2 AS SELECT x, y, Sys_end FROM t1; engine varchar(255),
INSERT INTO t1(x, y) VALUES(8001, 9001); fields varchar(255))
INSERT INTO t1(x, y, Sys_end) VALUES(8001, 9001, '2015-1-1 0:0:0'); begin
ERROR HY000: Generated field for System Versioning cannot be set by user set @str= concat('
INSERT INTO vt1_1(x, y) VALUES(1001, 2001); create table t1(
INSERT INTO vt1_1 VALUES(1002, 2002); x int unsigned,
INSERT INTO vt1_2(x, y) VALUES(3001, 4001); y int unsigned,
INSERT INTO vt1_2 VALUES(3002, 4002, '2015-1-1 0:0:0'); sys_start ', sys_type, ' generated always as row start,
ERROR HY000: Generated field for System Versioning cannot be set by user sys_end ', sys_type, ' generated always as row end,
SELECT x, y, Sys_end FROM t1; period for system_time (sys_start, sys_end))
x y Sys_end with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
create view vt1_1 as select x, y from t1;
create view vt1_2 as select x, y, sys_end from t1;
insert into t1(x, y) values(8001, 9001);
insert into vt1_1(x, y) values(1001, 2001);
insert into vt1_1 values(1002, 2002);
insert into vt1_2(x, y) values(3001, 4001);
set @str= concat('select x, y, ', fields, ' from t1');
prepare stmt from @str; execute stmt; drop prepare stmt;
select x, y from vt1_1;
set @str= concat('select x, y, ', fields, ' from vt1_2');
prepare stmt from @str; execute stmt; drop prepare stmt;
end~~
call test_03('timestamp(6)', 'myisam', 'sys_end');
x y sys_end
8001 9001 2038-01-19 03:14:07.000000 8001 9001 2038-01-19 03:14:07.000000
1001 2001 2038-01-19 03:14:07.000000 1001 2001 2038-01-19 03:14:07.000000
1002 2002 2038-01-19 03:14:07.000000 1002 2002 2038-01-19 03:14:07.000000
3001 4001 2038-01-19 03:14:07.000000 3001 4001 2038-01-19 03:14:07.000000
SELECT x, y FROM vt1_1;
x y x y
8001 9001 8001 9001
1001 2001 1001 2001
1002 2002 1002 2002
3001 4001 3001 4001
SELECT x, y, Sys_end FROM vt1_2; x y sys_end
x y Sys_end
8001 9001 2038-01-19 03:14:07.000000 8001 9001 2038-01-19 03:14:07.000000
1001 2001 2038-01-19 03:14:07.000000 1001 2001 2038-01-19 03:14:07.000000
1002 2002 2038-01-19 03:14:07.000000 1002 2002 2038-01-19 03:14:07.000000
3001 4001 2038-01-19 03:14:07.000000 3001 4001 2038-01-19 03:14:07.000000
DROP TABLE t1; insert into t1(x, y, sys_end) values(8001, 9001, '2015-1-1 1:1:1');
DROP VIEW vt1_1;
DROP VIEW vt1_2;
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB;
CREATE VIEW vt1_1 AS SELECT x, y FROM t1;
CREATE VIEW vt1_2 AS SELECT x, y, Sys_end FROM t1;
INSERT INTO t1(x, y) VALUES(8001, 9001);
INSERT INTO t1(x, y, Sys_end) VALUES(8001, 9001, '2015-1-1 0:0:0');
ERROR HY000: Generated field for System Versioning cannot be set by user ERROR HY000: Generated field for System Versioning cannot be set by user
INSERT INTO vt1_1(x, y) VALUES(1001, 2001); insert into vt1_2 values(3002, 4002, '2015-2-2 2:2:2');
INSERT INTO vt1_1 VALUES(1002, 2002);
INSERT INTO vt1_2(x, y) VALUES(3001, 4001);
INSERT INTO vt1_2 VALUES(3002, 4002, '2015-1-1 0:0:0');
ERROR HY000: Generated field for System Versioning cannot be set by user ERROR HY000: Generated field for System Versioning cannot be set by user
SELECT x, y, Sys_end FROM t1; drop table t1;
x y Sys_end drop view vt1_1;
drop view vt1_2;
call test_03('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
x y commit_ts(sys_end)
8001 9001 2038-01-19 03:14:07.000000 8001 9001 2038-01-19 03:14:07.000000
1001 2001 2038-01-19 03:14:07.000000 1001 2001 2038-01-19 03:14:07.000000
1002 2002 2038-01-19 03:14:07.000000 1002 2002 2038-01-19 03:14:07.000000
3001 4001 2038-01-19 03:14:07.000000 3001 4001 2038-01-19 03:14:07.000000
SELECT x, y FROM vt1_1;
x y x y
8001 9001 8001 9001
1001 2001 1001 2001
1002 2002 1002 2002
3001 4001 3001 4001
SELECT x, y, Sys_end FROM vt1_2; x y commit_ts(sys_end)
x y Sys_end
8001 9001 2038-01-19 03:14:07.000000 8001 9001 2038-01-19 03:14:07.000000
1001 2001 2038-01-19 03:14:07.000000 1001 2001 2038-01-19 03:14:07.000000
1002 2002 2038-01-19 03:14:07.000000 1002 2002 2038-01-19 03:14:07.000000
3001 4001 2038-01-19 03:14:07.000000 3001 4001 2038-01-19 03:14:07.000000
DROP TABLE t1; insert into t1(x, y, sys_end) values(8001, 9001, 1111111);
DROP VIEW vt1_1; ERROR HY000: Generated field for System Versioning cannot be set by user
DROP VIEW vt1_2; insert into vt1_2 values(3002, 4002, 2222222);
SET @i = 0; ERROR HY000: Generated field for System Versioning cannot be set by user
SELECT @i:=@i+1 AS No, trx_id > 0 AS A, begin_ts > '2015-1-1 0:0:0' AS B, commit_ts > begin_ts AS C, concurr_trx IS NULL AS D FROM INFORMATION_SCHEMA.INNODB_VTQ WHERE trx_id > @start_trx_id; drop table t1;
drop view vt1_1;
drop view vt1_2;
drop procedure test_03;
create procedure verify_vtq()
begin
set @i= 0;
select
@i:= @i + 1 as No,
trx_id > 0 as A,
begin_ts > '1-1-1 0:0:0' as B,
commit_ts > begin_ts as C,
concurr_trx is null as D
from information_schema.innodb_vtq
where trx_id > @start_trx_id;
select ifnull(max(trx_id), 0)
into @start_trx_id
from information_schema.innodb_vtq;
end~~
call verify_vtq;
No A B C D No A B C D
1 1 1 1 1 1 1 1 1 1
2 1 1 1 1 2 1 1 1 1
...@@ -840,25 +891,27 @@ No A B C D ...@@ -840,25 +891,27 @@ No A B C D
8 1 1 1 1 8 1 1 1 1
9 1 1 1 1 9 1 1 1 1
10 1 1 1 1 10 1 1 1 1
select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq; create table t1(
CREATE TABLE t1(x INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB; x int unsigned,
CREATE TABLE t2(x INT UNSIGNED) ENGINE=InnoDB; sys_start bigint unsigned generated always as row start,
START TRANSACTION; sys_end bigint unsigned generated always as row end,
INSERT INTO t1(x) VALUES(1); period for system_time (sys_start, sys_end))
COMMIT; with system versioning engine=innodb;
SET @i = 0; create table t2(x int unsigned) engine=innodb;
SELECT @i:=@i+1 AS No, trx_id > 0 AS A, begin_ts > '2015-1-1 0:0:0' AS B, commit_ts > begin_ts AS C, concurr_trx IS NULL AS D FROM INFORMATION_SCHEMA.INNODB_VTQ WHERE trx_id > @start_trx_id; start transaction;
insert into t1(x) values(1);
commit;
call verify_vtq;
No A B C D No A B C D
1 1 1 1 1 1 1 1 1 1
select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq; start transaction;
START TRANSACTION; insert into t2(x) values(1);
INSERT INTO t2(x) VALUES(1); savepoint a;
SAVEPOINT a; insert into t1(x) values(1);
INSERT INTO t1(x) VALUES(1); rollback to a;
ROLLBACK TO a; commit;
COMMIT; call verify_vtq;
SET @i = 0;
SELECT @i:=@i+1 AS No, trx_id > 0 AS A, begin_ts > '2015-1-1 0:0:0' AS B, commit_ts > begin_ts AS C, concurr_trx IS NULL AS D FROM INFORMATION_SCHEMA.INNODB_VTQ WHERE trx_id > @start_trx_id;
No A B C D No A B C D
DROP TABLE t1; drop table t1;
DROP TABLE t2; drop table t2;
drop procedure verify_vtq;
...@@ -860,9 +860,26 @@ End of 5.1 tests ...@@ -860,9 +860,26 @@ End of 5.1 tests
# System Versioning Support # System Versioning Support
# #
# #
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=MyISAM; set @@session.time_zone='+00:00';
CREATE TABLE t2(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=MyISAM; select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
INSERT INTO t1(x, y) VALUES create procedure test_01(
sys_type varchar(255),
engine varchar(255),
fields varchar(255))
begin
set @str= concat('(
x int unsigned,
y int unsigned,
sys_start ', sys_type, ' generated always as row start,
sys_end ', sys_type, ' generated always as row end,
period for system_time (sys_start, sys_end))
with system versioning
engine ', engine);
set @str2= concat('create table t1', @str);
prepare stmt from @str2; execute stmt; drop prepare stmt;
set @str2= concat('create table t2', @str);
prepare stmt from @str2; execute stmt; drop prepare stmt;
insert into t1(x, y) values
(1, 1000), (1, 1000),
(2, 2000), (2, 2000),
(3, 3000), (3, 3000),
...@@ -872,8 +889,8 @@ INSERT INTO t1(x, y) VALUES ...@@ -872,8 +889,8 @@ INSERT INTO t1(x, y) VALUES
(7, 7000), (7, 7000),
(8, 8000), (8, 8000),
(9, 9000); (9, 9000);
DELETE FROM t1 WHERE x >= 1; delete from t1 where x >= 1;
INSERT INTO t1(x, y) VALUES insert into t1(x, y) values
(1, 1001), (1, 1001),
(2, 2001), (2, 2001),
(3, 3001), (3, 3001),
...@@ -883,8 +900,13 @@ INSERT INTO t1(x, y) VALUES ...@@ -883,8 +900,13 @@ INSERT INTO t1(x, y) VALUES
(7, 7001), (7, 7001),
(8, 8001), (8, 8001),
(9, 9001); (9, 9001);
INSERT INTO t2 SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0'; insert into t2 select x, y from t1 for system_time between timestamp '0000-0-0 0:0:0' and timestamp '9999-1-1 0:0:0';
SELECT x, y FROM t1; select x, y from t1;
select x, y from t2;
drop table t1;
drop table t2;
end~~
call test_01('timestamp(6)', 'myisam', 'sys_end');
x y x y
1 1001 1 1001
2 2001 2 2001
...@@ -895,7 +917,6 @@ x y ...@@ -895,7 +917,6 @@ x y
7 7001 7 7001
8 8001 8 8001
9 9001 9 9001
SELECT x, y FROM t2;
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -915,33 +936,7 @@ x y ...@@ -915,33 +936,7 @@ x y
7 7001 7 7001
8 8001 8 8001
9 9001 9 9001
DROP TABLE t1; call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
DROP TABLE t2;
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB;
CREATE TABLE t2(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB;
INSERT INTO t1(x, y) VALUES
(1, 1000),
(2, 2000),
(3, 3000),
(4, 4000),
(5, 5000),
(6, 6000),
(7, 7000),
(8, 8000),
(9, 9000);
DELETE FROM t1 WHERE x >= 1;
INSERT INTO t1(x, y) VALUES
(1, 1001),
(2, 2001),
(3, 3001),
(4, 4001),
(5, 5001),
(6, 6001),
(7, 7001),
(8, 8001),
(9, 9001);
INSERT INTO t2 SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0';
SELECT x, y FROM t1;
x y x y
1 1001 1 1001
2 2001 2 2001
...@@ -952,7 +947,6 @@ x y ...@@ -952,7 +947,6 @@ x y
7 7001 7 7001
8 8001 8 8001
9 9001 9 9001
SELECT x, y FROM t2;
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -972,5 +966,26 @@ x y ...@@ -972,5 +966,26 @@ x y
7 7001 7 7001
8 8001 8 8001
9 9001 9 9001
DROP TABLE t1; drop procedure test_01;
DROP TABLE t2; create procedure verify_vtq()
begin
set @i= 0;
select
@i:= @i + 1 as No,
trx_id > 0 as A,
begin_ts > '1-1-1 0:0:0' as B,
commit_ts > begin_ts as C,
concurr_trx is null as D
from information_schema.innodb_vtq
where trx_id > @start_trx_id;
select ifnull(max(trx_id), 0)
into @start_trx_id
from information_schema.innodb_vtq;
end~~
call verify_vtq;
No A B C D
1 1 1 1 1
2 1 1 1 1
3 1 1 1 1
4 1 1 1 1
drop procedure verify_vtq;
...@@ -416,8 +416,25 @@ drop table t1; ...@@ -416,8 +416,25 @@ drop table t1;
# System Versioning Support # System Versioning Support
# #
# #
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end), PRIMARY KEY(x, y)) WITH SYSTEM VERSIONING; set @@session.time_zone='+00:00';
INSERT INTO t1(x, y) VALUES select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
create procedure test_01(
sys_type varchar(255),
engine varchar(255),
fields varchar(255))
begin
set @str= concat('
create table t1(
x int unsigned,
y int unsigned,
sys_start ', sys_type, ' generated always as row start,
sys_end ', sys_type, ' generated always as row end,
period for system_time (sys_start, sys_end),
primary key(x, y))
with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
insert into t1(x, y) values
(1, 1000), (1, 1000),
(2, 2000), (2, 2000),
(3, 3000), (3, 3000),
...@@ -427,11 +444,15 @@ INSERT INTO t1(x, y) VALUES ...@@ -427,11 +444,15 @@ INSERT INTO t1(x, y) VALUES
(7, 7000), (7, 7000),
(8, 8000), (8, 8000),
(9, 9000); (9, 9000);
INSERT INTO t1(x, y) VALUES(3, 3000) ON DUPLICATE KEY UPDATE y = y+1; insert into t1(x, y) values(3, 3000) on duplicate key update y = y+1;
INSERT INTO t1(x, y) VALUES(4, 4000) ON DUPLICATE KEY UPDATE y = y+1; insert into t1(x, y) values(4, 4000) on duplicate key update y = y+1;
INSERT INTO t1(x, y) VALUES(4, 4001) ON DUPLICATE KEY UPDATE y = y+1; insert into t1(x, y) values(4, 4001) on duplicate key update y = y+1;
INSERT INTO t1(x, y) VALUES(4, 4444) ON DUPLICATE KEY UPDATE y = y+1; insert into t1(x, y) values(4, 4444) on duplicate key update y = y+1;
SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0'; select x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp '9999-1-1 0:0:0';
select x, y from t1;
drop table t1;
end~~
call test_01('timestamp(6)', 'myisam', 'sys_end');
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -446,35 +467,18 @@ x y ...@@ -446,35 +467,18 @@ x y
4 4000 4 4000
4 4001 4 4001
4 4444 4 4444
SELECT x, y FROM t1;
x y x y
1 1000 1 1000
2 2000 2 2000
3 3001 3 3001
4 4002 4 4002
4 4444
5 5000 5 5000
6 6000 6 6000
7 7000 7 7000
8 8000 8 8000
9 9000 9 9000
4 4444 call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
DROP TABLE t1;
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end), PRIMARY KEY(x, y)) WITH SYSTEM VERSIONING ENGINE=InnoDB;
INSERT INTO t1(x, y) VALUES
(1, 1000),
(2, 2000),
(3, 3000),
(4, 4000),
(5, 5000),
(6, 6000),
(7, 7000),
(8, 8000),
(9, 9000);
INSERT INTO t1(x, y) VALUES(3, 3000) ON DUPLICATE KEY UPDATE y = y+1;
INSERT INTO t1(x, y) VALUES(4, 4000) ON DUPLICATE KEY UPDATE y = y+1;
INSERT INTO t1(x, y) VALUES(4, 4001) ON DUPLICATE KEY UPDATE y = y+1;
INSERT INTO t1(x, y) VALUES(4, 4444) ON DUPLICATE KEY UPDATE y = y+1;
SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0';
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -489,7 +493,6 @@ x y ...@@ -489,7 +493,6 @@ x y
7 7000 7 7000
8 8000 8 8000
9 9000 9 9000
SELECT x, y FROM t1;
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -501,4 +504,27 @@ x y ...@@ -501,4 +504,27 @@ x y
7 7000 7 7000
8 8000 8 8000
9 9000 9 9000
DROP TABLE t1; drop procedure test_01;
create procedure verify_vtq()
begin
set @i= 0;
select
@i:= @i + 1 as No,
trx_id > 0 as A,
begin_ts > '1-1-1 0:0:0' as B,
commit_ts > begin_ts as C,
concurr_trx is null as D
from information_schema.innodb_vtq
where trx_id > @start_trx_id;
select ifnull(max(trx_id), 0)
into @start_trx_id
from information_schema.innodb_vtq;
end~~
call verify_vtq;
No A B C D
1 1 1 1 1
2 1 1 1 1
3 1 1 1 1
4 1 1 1 1
5 1 1 1 1
drop procedure verify_vtq;
...@@ -1060,9 +1060,26 @@ end of 10.0 tests ...@@ -1060,9 +1060,26 @@ end of 10.0 tests
# System Versioning Support # System Versioning Support
# #
# #
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING; set @@session.time_zone='+00:00';
CREATE TABLE t2(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING; select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
INSERT INTO t1(x, y) VALUES create procedure test_01(
sys_type varchar(255),
engine varchar(255),
fields varchar(255))
begin
set @str= concat('(
x int unsigned,
y int unsigned,
sys_start ', sys_type, ' generated always as row start,
sys_end ', sys_type, ' generated always as row end,
period for system_time (sys_start, sys_end))
with system versioning
engine ', engine);
set @str2= concat('create table t1', @str);
prepare stmt from @str2; execute stmt; drop prepare stmt;
set @str2= concat('create table t2', @str);
prepare stmt from @str2; execute stmt; drop prepare stmt;
insert into t1(x, y) values
(1, 1000), (1, 1000),
(2, 2000), (2, 2000),
(3, 3000), (3, 3000),
...@@ -1072,7 +1089,7 @@ INSERT INTO t1(x, y) VALUES ...@@ -1072,7 +1089,7 @@ INSERT INTO t1(x, y) VALUES
(7, 7000), (7, 7000),
(8, 8000), (8, 8000),
(9, 9000); (9, 9000);
INSERT INTO t2(x, y) VALUES insert into t2(x, y) values
(1, 1010), (1, 1010),
(2, 2010), (2, 2010),
(3, 3010), (3, 3010),
...@@ -1082,8 +1099,15 @@ INSERT INTO t2(x, y) VALUES ...@@ -1082,8 +1099,15 @@ INSERT INTO t2(x, y) VALUES
(7, 7010), (7, 7010),
(8, 8010), (8, 8010),
(9, 9010); (9, 9010);
UPDATE t1, t2 SET t1.y = t1.x + t1.y, t2.y = t2.x + t2.y WHERE t1.x > 7 AND t2.x < 7; update t1, t2 set t1.y = t1.x + t1.y, t2.y = t2.x + t2.y where t1.x > 7 and t2.x < 7;
SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0'; select x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp '9999-1-1 0:0:0';
select x, y from t1;
select x, y from t2 for system_time between timestamp '0-0-0 0:0:0' and timestamp '9999-1-1 0:0:0';
select x, y from t2;
drop table t1;
drop table t2;
end~~
call test_01('timestamp(6)', 'myisam', 'sys_end');
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -1096,7 +1120,6 @@ x y ...@@ -1096,7 +1120,6 @@ x y
9 9009 9 9009
8 8000 8 8000
9 9000 9 9000
SELECT x, y FROM t1;
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -1107,7 +1130,6 @@ x y ...@@ -1107,7 +1130,6 @@ x y
7 7000 7 7000
8 8008 8 8008
9 9009 9 9009
SELECT x, y FROM t2 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0';
x y x y
1 1011 1 1011
2 2012 2 2012
...@@ -1124,7 +1146,6 @@ x y ...@@ -1124,7 +1146,6 @@ x y
4 4010 4 4010
5 5010 5 5010
6 6010 6 6010
SELECT x, y FROM t2;
x y x y
1 1011 1 1011
2 2012 2 2012
...@@ -1135,32 +1156,7 @@ x y ...@@ -1135,32 +1156,7 @@ x y
7 7010 7 7010
8 8010 8 8010
9 9010 9 9010
DROP TABLE t1; call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
DROP TABLE t2;
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB;
CREATE TABLE t2(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB;
INSERT INTO t1(x, y) VALUES
(1, 1000),
(2, 2000),
(3, 3000),
(4, 4000),
(5, 5000),
(6, 6000),
(7, 7000),
(8, 8000),
(9, 9000);
INSERT INTO t2(x, y) VALUES
(1, 1010),
(2, 2010),
(3, 3010),
(4, 4010),
(5, 5010),
(6, 6010),
(7, 7010),
(8, 8010),
(9, 9010);
UPDATE t1, t2 SET t1.y = t1.x + t1.y, t2.y = t2.x + t2.y WHERE t1.x > 7 AND t2.x < 7;
SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0';
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -1173,7 +1169,6 @@ x y ...@@ -1173,7 +1169,6 @@ x y
9 9009 9 9009
8 8000 8 8000
9 9000 9 9000
SELECT x, y FROM t1;
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -1184,7 +1179,6 @@ x y ...@@ -1184,7 +1179,6 @@ x y
7 7000 7 7000
8 8008 8 8008
9 9009 9 9009
SELECT x, y FROM t2 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0';
x y x y
1 1011 1 1011
2 2012 2 2012
...@@ -1201,7 +1195,6 @@ x y ...@@ -1201,7 +1195,6 @@ x y
4 4010 4 4010
5 5010 5 5010
6 6010 6 6010
SELECT x, y FROM t2;
x y x y
1 1011 1 1011
2 2012 2 2012
...@@ -1212,5 +1205,25 @@ x y ...@@ -1212,5 +1205,25 @@ x y
7 7010 7 7010
8 8010 8 8010
9 9010 9 9010
DROP TABLE t1; drop procedure test_01;
DROP TABLE t2; create procedure verify_vtq()
begin
set @i= 0;
select
@i:= @i + 1 as No,
trx_id > 0 as A,
begin_ts > '1-1-1 0:0:0' as B,
commit_ts > begin_ts as C,
concurr_trx is null as D
from information_schema.innodb_vtq
where trx_id > @start_trx_id;
select ifnull(max(trx_id), 0)
into @start_trx_id
from information_schema.innodb_vtq;
end~~
call verify_vtq;
No A B C D
1 1 1 1 1
2 1 1 1 1
3 1 1 1 1
drop procedure verify_vtq;
...@@ -723,8 +723,24 @@ drop table t1, t2; ...@@ -723,8 +723,24 @@ drop table t1, t2;
# System Versioning Support # System Versioning Support
# #
# #
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING; set @@session.time_zone='+00:00';
INSERT INTO t1(x, y) VALUES select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
create procedure test_01(
sys_type varchar(255),
engine varchar(255),
fields varchar(255))
begin
set @str= concat('
create table t1(
x int unsigned,
y int unsigned,
sys_start ', sys_type, ' generated always as row start,
sys_end ', sys_type, ' generated always as row end,
period for system_time (sys_start, sys_end))
with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
insert into t1(x, y) values
(1, 1000), (1, 1000),
(2, 2000), (2, 2000),
(3, 3000), (3, 3000),
...@@ -734,7 +750,15 @@ INSERT INTO t1(x, y) VALUES ...@@ -734,7 +750,15 @@ INSERT INTO t1(x, y) VALUES
(7, 7000), (7, 7000),
(8, 8000), (8, 8000),
(9, 9000); (9, 9000);
SELECT x, y FROM t1; select x, y from t1;
update t1 set y = y + 1 where x > 7;
select x, y from t1;
select x, y from t1 for system_time
between timestamp '0000-0-0 0:0:0'
and timestamp '2038-01-19 04:14:07';
drop table t1;
end~~
call test_01('timestamp(6)', 'myisam', 'sys_end');
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -745,8 +769,6 @@ x y ...@@ -745,8 +769,6 @@ x y
7 7000 7 7000
8 8000 8 8000
9 9000 9 9000
UPDATE t1 SET y = y + 1 WHERE x > 7;
SELECT x, y FROM t1;
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -757,7 +779,6 @@ x y ...@@ -757,7 +779,6 @@ x y
7 7000 7 7000
8 8001 8 8001
9 9001 9 9001
SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07';
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -770,20 +791,7 @@ x y ...@@ -770,20 +791,7 @@ x y
9 9001 9 9001
8 8000 8 8000
9 9000 9 9000
DROP TABLE t1; call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB;
INSERT INTO t1(x, y) VALUES
(1, 1000),
(2, 2000),
(3, 3000),
(4, 4000),
(5, 5000),
(6, 6000),
(7, 7000),
(8, 8000),
(9, 9000);
SELECT x, y FROM t1;
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -794,8 +802,6 @@ x y ...@@ -794,8 +802,6 @@ x y
7 7000 7 7000
8 8000 8 8000
9 9000 9 9000
UPDATE t1 SET y = y + 1 WHERE x > 7;
SELECT x, y FROM t1;
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -806,7 +812,6 @@ x y ...@@ -806,7 +812,6 @@ x y
7 7000 7 7000
8 8001 8 8001
9 9001 9 9001
SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07';
x y x y
1 1000 1 1000
2 2000 2 2000
...@@ -819,9 +824,24 @@ x y ...@@ -819,9 +824,24 @@ x y
9 9001 9 9001
8 8000 8 8000
9 9000 9 9000
DROP TABLE t1; drop procedure test_01;
SET @i = 0; create procedure verify_vtq()
SELECT @i:=@i+1 AS No, trx_id > 0 AS A, begin_ts > '2015-1-1 0:0:0' AS B, commit_ts > begin_ts AS C, concurr_trx IS NULL AS D FROM INFORMATION_SCHEMA.INNODB_VTQ WHERE trx_id > @start_trx_id; begin
set @i= 0;
select
@i:= @i + 1 as No,
trx_id > 0 as A,
begin_ts > '1-1-1 0:0:0' as B,
commit_ts > begin_ts as C,
concurr_trx is null as D
from information_schema.innodb_vtq
where trx_id > @start_trx_id;
select ifnull(max(trx_id), 0)
into @start_trx_id
from information_schema.innodb_vtq;
end~~
call verify_vtq;
No A B C D No A B C D
1 1 1 1 1 1 1 1 1 1
2 1 1 1 1 2 1 1 1 1
drop procedure verify_vtq;
...@@ -587,83 +587,83 @@ DROP TABLE t1, t2; ...@@ -587,83 +587,83 @@ DROP TABLE t1, t2;
# SQL DELETE for SYSTEM VERSIONING # SQL DELETE for SYSTEM VERSIONING
# #
--echo # --echo #
--echo # Test for SYSTEM VERSIONING --echo # System Versioning Support
--echo #
--echo # --echo #
SET @@session.time_zone='+00:00';
create table t1 (
XNo INT UNSIGNED,
Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START,
Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)
) WITH SYSTEM VERSIONING;
INSERT INTO t1(XNo) VALUES(0);
INSERT INTO t1(XNo) VALUES(1);
INSERT INTO t1(XNo) VALUES(2);
INSERT INTO t1(XNo) VALUES(3);
INSERT INTO t1(XNo) VALUES(4);
INSERT INTO t1(XNo) VALUES(5);
INSERT INTO t1(XNo) VALUES(6);
INSERT INTO t1(XNo) VALUES(7);
INSERT INTO t1(XNo) VALUES(8);
INSERT INTO t1(XNo) VALUES(9);
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07';
DELETE FROM t1 WHERE XNo = 0;
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07';
DELETE FROM t1 WHERE XNo = 1;
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07';
DELETE FROM t1 WHERE XNo > 5;
CREATE VIEW vt1 AS SELECT XNo FROM t1;
SELECT XNo FROM vt1;
DELETE FROM vt1 WHERE XNo = 3;
SELECT XNo FROM vt1;
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07';
DROP VIEW vt1;
DROP TABLE t1;
-- source include/have_innodb.inc -- source include/have_innodb.inc
set @@session.time_zone='+00:00';
select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq; select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
create table t1 ( delimiter ~~;
XNo INT UNSIGNED, create procedure test_01(
Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, sys_type varchar(255),
Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, engine varchar(255),
PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end) fields varchar(255))
) WITH SYSTEM VERSIONING ENGINE InnoDB; begin
set @str= concat('
INSERT INTO t1(XNo) VALUES(0); create table t1(
INSERT INTO t1(XNo) VALUES(1); XNo int unsigned,
INSERT INTO t1(XNo) VALUES(2); sys_start ', sys_type, ' generated always as row start,
INSERT INTO t1(XNo) VALUES(3); sys_end ', sys_type, ' generated always as row end,
INSERT INTO t1(XNo) VALUES(4); period for system_time (sys_start, sys_end))
INSERT INTO t1(XNo) VALUES(5); with system versioning
INSERT INTO t1(XNo) VALUES(6); engine ', engine);
INSERT INTO t1(XNo) VALUES(7); prepare stmt from @str; execute stmt; drop prepare stmt;
INSERT INTO t1(XNo) VALUES(8); insert into t1(XNo) values(0);
INSERT INTO t1(XNo) VALUES(9); insert into t1(XNo) values(1);
insert into t1(XNo) values(2);
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07'; insert into t1(XNo) values(3);
DELETE FROM t1 WHERE XNo = 0; insert into t1(XNo) values(4);
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07'; insert into t1(XNo) values(5);
DELETE FROM t1 WHERE XNo = 1; insert into t1(XNo) values(6);
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07'; insert into t1(XNo) values(7);
DELETE FROM t1 WHERE XNo > 5; insert into t1(XNo) values(8);
insert into t1(XNo) values(9);
CREATE VIEW vt1 AS SELECT XNo FROM t1; set @str= concat('select XNo, ',
fields, " < '2038-01-19 03:14:07'
SELECT XNo FROM vt1; from t1 for system_time
DELETE FROM vt1 WHERE XNo = 3; between timestamp '0000-0-0 0:0:0'
SELECT XNo FROM vt1; and timestamp '2038-01-19 04:14:07'");
SELECT XNo, Sys_end < '2038-01-19 03:14:07' FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07'; prepare stmt from @str; execute stmt;
delete from t1 where XNo = 0;
DROP VIEW vt1; execute stmt;
DROP TABLE t1; delete from t1 where XNo = 1;
execute stmt;
SET @i = 0; SELECT @i:=@i+1 AS No, trx_id > 0 AS A, begin_ts > '2015-1-1 0:0:0' AS B, commit_ts > begin_ts AS C, concurr_trx IS NULL AS D FROM INFORMATION_SCHEMA.INNODB_VTQ WHERE trx_id > @start_trx_id; delete from t1 where XNo > 5;
create view vt1 as select XNo from t1;
select XNo from vt1;
delete from vt1 where XNo = 3;
select XNo from vt1;
execute stmt; drop prepare stmt;
drop view vt1;
drop table t1;
end~~
delimiter ;~~
call test_01('timestamp(6)', 'myisam', 'sys_end');
call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
drop procedure test_01;
# VTQ test
delimiter ~~;
create procedure verify_vtq()
begin
set @i= 0;
select
@i:= @i + 1 as No,
trx_id > 0 as A,
begin_ts > '1-1-1 0:0:0' as B,
commit_ts > begin_ts as C,
concurr_trx is null as D
from information_schema.innodb_vtq
where trx_id > @start_trx_id;
select ifnull(max(trx_id), 0)
into @start_trx_id
from information_schema.innodb_vtq;
end~~
delimiter ;~~
call verify_vtq;
drop procedure verify_vtq;
...@@ -580,92 +580,161 @@ DROP TABLE t1; ...@@ -580,92 +580,161 @@ DROP TABLE t1;
--echo # --echo #
-- source include/have_innodb.inc -- source include/have_innodb.inc
set @@session.time_zone='+00:00';
SET @@session.time_zone='+00:00';
select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq; select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING;
INSERT INTO t1(x, y) VALUES(3, 4);
INSERT INTO t1(x, y) VALUES(2, 3);
INSERT INTO t1 VALUES(40, 33);
SELECT x, y, Sys_end FROM t1;
DROP TABLE t1;
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB; delimiter ~~;
INSERT INTO t1(x, y) VALUES(3, 4); create procedure test_01(
INSERT INTO t1(x, y) VALUES(2, 3); sys_type varchar(255),
INSERT INTO t1 VALUES(40, 33); engine varchar(255),
SELECT x, y, Sys_end FROM t1; fields varchar(255))
DROP TABLE t1; begin
set @str= concat('
CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT, x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end), PRIMARY KEY(id)) WITH SYSTEM VERSIONING; create table t1(
INSERT INTO t1(x, y) VALUES(33, 44); x int unsigned,
INSERT INTO t1(id, x, y) VALUES(20, 33, 44); y int unsigned,
INSERT INTO t1 VALUES(40, 33, 44); sys_start ', sys_type, ' generated always as row start,
SELECT id, x, y, Sys_end FROM t1; sys_end ', sys_type, ' generated always as row end,
DROP TABLE t1; period for system_time (sys_start, sys_end))
with system versioning
CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT, x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end), PRIMARY KEY(id)) WITH SYSTEM VERSIONING ENGINE=InnoDB; engine ', engine);
INSERT INTO t1(x, y) VALUES(33, 44); prepare stmt from @str; execute stmt; drop prepare stmt;
INSERT INTO t1(id, x, y) VALUES(20, 33, 44); insert into t1(x, y) values(3, 4);
INSERT INTO t1 VALUES(40, 33, 44); insert into t1(x, y) values(2, 3);
SELECT id, x, y, Sys_end FROM t1; insert into t1 values(40, 33);
DROP TABLE t1; set @str= concat('select x, y, ', fields, ' from t1');
prepare stmt from @str; execute stmt; drop prepare stmt;
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING; drop table t1;
CREATE VIEW vt1_1 AS SELECT x, y FROM t1; end~~
CREATE VIEW vt1_2 AS SELECT x, y, Sys_end FROM t1; delimiter ;~~
INSERT INTO t1(x, y) VALUES(8001, 9001);
--error ER_GENERATED_FIELD_CANNOT_BE_SET_BY_USER call test_01('timestamp(6)', 'myisam', 'sys_end');
INSERT INTO t1(x, y, Sys_end) VALUES(8001, 9001, '2015-1-1 0:0:0'); call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
INSERT INTO vt1_1(x, y) VALUES(1001, 2001); drop procedure test_01;
INSERT INTO vt1_1 VALUES(1002, 2002);
INSERT INTO vt1_2(x, y) VALUES(3001, 4001); delimiter ~~;
--error ER_GENERATED_FIELD_CANNOT_BE_SET_BY_USER create procedure test_02(
INSERT INTO vt1_2 VALUES(3002, 4002, '2015-1-1 0:0:0'); sys_type varchar(255),
SELECT x, y, Sys_end FROM t1; engine varchar(255),
SELECT x, y FROM vt1_1; fields varchar(255))
SELECT x, y, Sys_end FROM vt1_2; begin
DROP TABLE t1; set @str= concat('
DROP VIEW vt1_1; create table t1(
DROP VIEW vt1_2; id int unsigned auto_increment primary key,
x int unsigned,
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB; y int unsigned,
CREATE VIEW vt1_1 AS SELECT x, y FROM t1; sys_start ', sys_type, ' generated always as row start,
CREATE VIEW vt1_2 AS SELECT x, y, Sys_end FROM t1; sys_end ', sys_type, ' generated always as row end,
INSERT INTO t1(x, y) VALUES(8001, 9001); period for system_time (sys_start, sys_end))
--error ER_GENERATED_FIELD_CANNOT_BE_SET_BY_USER with system versioning
INSERT INTO t1(x, y, Sys_end) VALUES(8001, 9001, '2015-1-1 0:0:0'); engine ', engine);
INSERT INTO vt1_1(x, y) VALUES(1001, 2001); prepare stmt from @str; execute stmt; drop prepare stmt;
INSERT INTO vt1_1 VALUES(1002, 2002); insert into t1(x, y) values(33, 44);
INSERT INTO vt1_2(x, y) VALUES(3001, 4001); insert into t1(id, x, y) values(20, 33, 44);
--error ER_GENERATED_FIELD_CANNOT_BE_SET_BY_USER insert into t1 values(40, 33, 44);
INSERT INTO vt1_2 VALUES(3002, 4002, '2015-1-1 0:0:0'); set @str= concat('select id, x, y, ', fields, ' from t1');
SELECT x, y, Sys_end FROM t1; prepare stmt from @str; execute stmt; drop prepare stmt;
SELECT x, y FROM vt1_1; drop table t1;
SELECT x, y, Sys_end FROM vt1_2; end~~
DROP TABLE t1; delimiter ;~~
DROP VIEW vt1_1;
DROP VIEW vt1_2; call test_02('timestamp(6)', 'myisam', 'sys_end');
call test_02('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
SET @i = 0; SELECT @i:=@i+1 AS No, trx_id > 0 AS A, begin_ts > '2015-1-1 0:0:0' AS B, commit_ts > begin_ts AS C, concurr_trx IS NULL AS D FROM INFORMATION_SCHEMA.INNODB_VTQ WHERE trx_id > @start_trx_id; drop procedure test_02;
select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq; delimiter ~~;
CREATE TABLE t1(x INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB; create procedure test_03(
CREATE TABLE t2(x INT UNSIGNED) ENGINE=InnoDB; sys_type varchar(255),
START TRANSACTION; engine varchar(255),
INSERT INTO t1(x) VALUES(1); fields varchar(255))
COMMIT; begin
set @str= concat('
create table t1(
x int unsigned,
y int unsigned,
sys_start ', sys_type, ' generated always as row start,
sys_end ', sys_type, ' generated always as row end,
period for system_time (sys_start, sys_end))
with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
create view vt1_1 as select x, y from t1;
create view vt1_2 as select x, y, sys_end from t1;
insert into t1(x, y) values(8001, 9001);
insert into vt1_1(x, y) values(1001, 2001);
insert into vt1_1 values(1002, 2002);
insert into vt1_2(x, y) values(3001, 4001);
set @str= concat('select x, y, ', fields, ' from t1');
prepare stmt from @str; execute stmt; drop prepare stmt;
select x, y from vt1_1;
set @str= concat('select x, y, ', fields, ' from vt1_2');
prepare stmt from @str; execute stmt; drop prepare stmt;
end~~
delimiter ;~~
call test_03('timestamp(6)', 'myisam', 'sys_end');
--ERROR ER_GENERATED_FIELD_CANNOT_BE_SET_BY_USER
insert into t1(x, y, sys_end) values(8001, 9001, '2015-1-1 1:1:1');
--ERROR ER_GENERATED_FIELD_CANNOT_BE_SET_BY_USER
insert into vt1_2 values(3002, 4002, '2015-2-2 2:2:2');
drop table t1;
drop view vt1_1;
drop view vt1_2;
call test_03('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
--ERROR ER_GENERATED_FIELD_CANNOT_BE_SET_BY_USER
insert into t1(x, y, sys_end) values(8001, 9001, 1111111);
--ERROR ER_GENERATED_FIELD_CANNOT_BE_SET_BY_USER
insert into vt1_2 values(3002, 4002, 2222222);
drop table t1;
drop view vt1_1;
drop view vt1_2;
drop procedure test_03;
# VTQ test
delimiter ~~;
create procedure verify_vtq()
begin
set @i= 0;
select
@i:= @i + 1 as No,
trx_id > 0 as A,
begin_ts > '1-1-1 0:0:0' as B,
commit_ts > begin_ts as C,
concurr_trx is null as D
from information_schema.innodb_vtq
where trx_id > @start_trx_id;
select ifnull(max(trx_id), 0)
into @start_trx_id
from information_schema.innodb_vtq;
end~~
delimiter ;~~
call verify_vtq;
create table t1(
x int unsigned,
sys_start bigint unsigned generated always as row start,
sys_end bigint unsigned generated always as row end,
period for system_time (sys_start, sys_end))
with system versioning engine=innodb;
create table t2(x int unsigned) engine=innodb;
start transaction;
insert into t1(x) values(1);
commit;
call verify_vtq;
SET @i = 0; SELECT @i:=@i+1 AS No, trx_id > 0 AS A, begin_ts > '2015-1-1 0:0:0' AS B, commit_ts > begin_ts AS C, concurr_trx IS NULL AS D FROM INFORMATION_SCHEMA.INNODB_VTQ WHERE trx_id > @start_trx_id; start transaction;
insert into t2(x) values(1);
savepoint a;
insert into t1(x) values(1);
rollback to a;
commit;
call verify_vtq;
select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq; drop table t1;
START TRANSACTION; drop table t2;
INSERT INTO t2(x) VALUES(1); drop procedure verify_vtq;
SAVEPOINT a; \ No newline at end of file
INSERT INTO t1(x) VALUES(1);
ROLLBACK TO a;
COMMIT;
SET @i = 0; SELECT @i:=@i+1 AS No, trx_id > 0 AS A, begin_ts > '2015-1-1 0:0:0' AS B, commit_ts > begin_ts AS C, concurr_trx IS NULL AS D FROM INFORMATION_SCHEMA.INNODB_VTQ WHERE trx_id > @start_trx_id;
DROP TABLE t1;
DROP TABLE t2;
...@@ -432,39 +432,28 @@ DROP TABLE t1; ...@@ -432,39 +432,28 @@ DROP TABLE t1;
--echo # --echo #
-- source include/have_innodb.inc -- source include/have_innodb.inc
set @@session.time_zone='+00:00';
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=MyISAM; select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
CREATE TABLE t2(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=MyISAM;
INSERT INTO t1(x, y) VALUES delimiter ~~;
(1, 1000), create procedure test_01(
(2, 2000), sys_type varchar(255),
(3, 3000), engine varchar(255),
(4, 4000), fields varchar(255))
(5, 5000), begin
(6, 6000), set @str= concat('(
(7, 7000), x int unsigned,
(8, 8000), y int unsigned,
(9, 9000); sys_start ', sys_type, ' generated always as row start,
DELETE FROM t1 WHERE x >= 1; sys_end ', sys_type, ' generated always as row end,
INSERT INTO t1(x, y) VALUES period for system_time (sys_start, sys_end))
(1, 1001), with system versioning
(2, 2001), engine ', engine);
(3, 3001), set @str2= concat('create table t1', @str);
(4, 4001), prepare stmt from @str2; execute stmt; drop prepare stmt;
(5, 5001), set @str2= concat('create table t2', @str);
(6, 6001), prepare stmt from @str2; execute stmt; drop prepare stmt;
(7, 7001), insert into t1(x, y) values
(8, 8001),
(9, 9001);
INSERT INTO t2 SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0';
SELECT x, y FROM t1;
SELECT x, y FROM t2;
DROP TABLE t1;
DROP TABLE t2;
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB;
CREATE TABLE t2(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB;
INSERT INTO t1(x, y) VALUES
(1, 1000), (1, 1000),
(2, 2000), (2, 2000),
(3, 3000), (3, 3000),
...@@ -474,8 +463,8 @@ INSERT INTO t1(x, y) VALUES ...@@ -474,8 +463,8 @@ INSERT INTO t1(x, y) VALUES
(7, 7000), (7, 7000),
(8, 8000), (8, 8000),
(9, 9000); (9, 9000);
DELETE FROM t1 WHERE x >= 1; delete from t1 where x >= 1;
INSERT INTO t1(x, y) VALUES insert into t1(x, y) values
(1, 1001), (1, 1001),
(2, 2001), (2, 2001),
(3, 3001), (3, 3001),
...@@ -485,8 +474,37 @@ INSERT INTO t1(x, y) VALUES ...@@ -485,8 +474,37 @@ INSERT INTO t1(x, y) VALUES
(7, 7001), (7, 7001),
(8, 8001), (8, 8001),
(9, 9001); (9, 9001);
INSERT INTO t2 SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0'; insert into t2 select x, y from t1 for system_time between timestamp '0000-0-0 0:0:0' and timestamp '9999-1-1 0:0:0';
SELECT x, y FROM t1; select x, y from t1;
SELECT x, y FROM t2; select x, y from t2;
DROP TABLE t1; drop table t1;
DROP TABLE t2; drop table t2;
end~~
delimiter ;~~
call test_01('timestamp(6)', 'myisam', 'sys_end');
call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
drop procedure test_01;
# VTQ test
delimiter ~~;
create procedure verify_vtq()
begin
set @i= 0;
select
@i:= @i + 1 as No,
trx_id > 0 as A,
begin_ts > '1-1-1 0:0:0' as B,
commit_ts > begin_ts as C,
concurr_trx is null as D
from information_schema.innodb_vtq
where trx_id > @start_trx_id;
select ifnull(max(trx_id), 0)
into @start_trx_id
from information_schema.innodb_vtq;
end~~
delimiter ;~~
call verify_vtq;
drop procedure verify_vtq;
...@@ -318,9 +318,27 @@ drop table t1; ...@@ -318,9 +318,27 @@ drop table t1;
--echo # --echo #
-- source include/have_innodb.inc -- source include/have_innodb.inc
set @@session.time_zone='+00:00';
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end), PRIMARY KEY(x, y)) WITH SYSTEM VERSIONING; select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
INSERT INTO t1(x, y) VALUES
delimiter ~~;
create procedure test_01(
sys_type varchar(255),
engine varchar(255),
fields varchar(255))
begin
set @str= concat('
create table t1(
x int unsigned,
y int unsigned,
sys_start ', sys_type, ' generated always as row start,
sys_end ', sys_type, ' generated always as row end,
period for system_time (sys_start, sys_end),
primary key(x, y))
with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
insert into t1(x, y) values
(1, 1000), (1, 1000),
(2, 2000), (2, 2000),
(3, 3000), (3, 3000),
...@@ -330,29 +348,39 @@ INSERT INTO t1(x, y) VALUES ...@@ -330,29 +348,39 @@ INSERT INTO t1(x, y) VALUES
(7, 7000), (7, 7000),
(8, 8000), (8, 8000),
(9, 9000); (9, 9000);
INSERT INTO t1(x, y) VALUES(3, 3000) ON DUPLICATE KEY UPDATE y = y+1; insert into t1(x, y) values(3, 3000) on duplicate key update y = y+1;
INSERT INTO t1(x, y) VALUES(4, 4000) ON DUPLICATE KEY UPDATE y = y+1; insert into t1(x, y) values(4, 4000) on duplicate key update y = y+1;
INSERT INTO t1(x, y) VALUES(4, 4001) ON DUPLICATE KEY UPDATE y = y+1; insert into t1(x, y) values(4, 4001) on duplicate key update y = y+1;
INSERT INTO t1(x, y) VALUES(4, 4444) ON DUPLICATE KEY UPDATE y = y+1; insert into t1(x, y) values(4, 4444) on duplicate key update y = y+1;
SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0'; select x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp '9999-1-1 0:0:0';
SELECT x, y FROM t1; select x, y from t1;
DROP TABLE t1; drop table t1;
end~~
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end), PRIMARY KEY(x, y)) WITH SYSTEM VERSIONING ENGINE=InnoDB; delimiter ;~~
INSERT INTO t1(x, y) VALUES
(1, 1000), call test_01('timestamp(6)', 'myisam', 'sys_end');
(2, 2000), call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
(3, 3000), drop procedure test_01;
(4, 4000),
(5, 5000), # VTQ test
(6, 6000),
(7, 7000), delimiter ~~;
(8, 8000), create procedure verify_vtq()
(9, 9000); begin
INSERT INTO t1(x, y) VALUES(3, 3000) ON DUPLICATE KEY UPDATE y = y+1; set @i= 0;
INSERT INTO t1(x, y) VALUES(4, 4000) ON DUPLICATE KEY UPDATE y = y+1; select
INSERT INTO t1(x, y) VALUES(4, 4001) ON DUPLICATE KEY UPDATE y = y+1; @i:= @i + 1 as No,
INSERT INTO t1(x, y) VALUES(4, 4444) ON DUPLICATE KEY UPDATE y = y+1; trx_id > 0 as A,
SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0'; begin_ts > '1-1-1 0:0:0' as B,
SELECT x, y FROM t1; commit_ts > begin_ts as C,
DROP TABLE t1; concurr_trx is null as D
from information_schema.innodb_vtq
where trx_id > @start_trx_id;
select ifnull(max(trx_id), 0)
into @start_trx_id
from information_schema.innodb_vtq;
end~~
delimiter ;~~
call verify_vtq;
drop procedure verify_vtq;
...@@ -1041,9 +1041,29 @@ SET SESSION SQL_MODE=default; ...@@ -1041,9 +1041,29 @@ SET SESSION SQL_MODE=default;
--echo # --echo #
--echo # --echo #
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING; -- source include/have_innodb.inc
CREATE TABLE t2(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING; set @@session.time_zone='+00:00';
INSERT INTO t1(x, y) VALUES select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
delimiter ~~;
create procedure test_01(
sys_type varchar(255),
engine varchar(255),
fields varchar(255))
begin
set @str= concat('(
x int unsigned,
y int unsigned,
sys_start ', sys_type, ' generated always as row start,
sys_end ', sys_type, ' generated always as row end,
period for system_time (sys_start, sys_end))
with system versioning
engine ', engine);
set @str2= concat('create table t1', @str);
prepare stmt from @str2; execute stmt; drop prepare stmt;
set @str2= concat('create table t2', @str);
prepare stmt from @str2; execute stmt; drop prepare stmt;
insert into t1(x, y) values
(1, 1000), (1, 1000),
(2, 2000), (2, 2000),
(3, 3000), (3, 3000),
...@@ -1053,7 +1073,7 @@ INSERT INTO t1(x, y) VALUES ...@@ -1053,7 +1073,7 @@ INSERT INTO t1(x, y) VALUES
(7, 7000), (7, 7000),
(8, 8000), (8, 8000),
(9, 9000); (9, 9000);
INSERT INTO t2(x, y) VALUES insert into t2(x, y) values
(1, 1010), (1, 1010),
(2, 2010), (2, 2010),
(3, 3010), (3, 3010),
...@@ -1063,40 +1083,39 @@ INSERT INTO t2(x, y) VALUES ...@@ -1063,40 +1083,39 @@ INSERT INTO t2(x, y) VALUES
(7, 7010), (7, 7010),
(8, 8010), (8, 8010),
(9, 9010); (9, 9010);
UPDATE t1, t2 SET t1.y = t1.x + t1.y, t2.y = t2.x + t2.y WHERE t1.x > 7 AND t2.x < 7; update t1, t2 set t1.y = t1.x + t1.y, t2.y = t2.x + t2.y where t1.x > 7 and t2.x < 7;
SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0'; select x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp '9999-1-1 0:0:0';
SELECT x, y FROM t1; select x, y from t1;
SELECT x, y FROM t2 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0'; select x, y from t2 for system_time between timestamp '0-0-0 0:0:0' and timestamp '9999-1-1 0:0:0';
SELECT x, y FROM t2; select x, y from t2;
DROP TABLE t1; drop table t1;
DROP TABLE t2; drop table t2;
end~~
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB; delimiter ;~~
CREATE TABLE t2(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB;
INSERT INTO t1(x, y) VALUES call test_01('timestamp(6)', 'myisam', 'sys_end');
(1, 1000), call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
(2, 2000), drop procedure test_01;
(3, 3000),
(4, 4000), # VTQ test
(5, 5000),
(6, 6000), delimiter ~~;
(7, 7000), create procedure verify_vtq()
(8, 8000), begin
(9, 9000); set @i= 0;
INSERT INTO t2(x, y) VALUES select
(1, 1010), @i:= @i + 1 as No,
(2, 2010), trx_id > 0 as A,
(3, 3010), begin_ts > '1-1-1 0:0:0' as B,
(4, 4010), commit_ts > begin_ts as C,
(5, 5010), concurr_trx is null as D
(6, 6010), from information_schema.innodb_vtq
(7, 7010), where trx_id > @start_trx_id;
(8, 8010), select ifnull(max(trx_id), 0)
(9, 9010); into @start_trx_id
UPDATE t1, t2 SET t1.y = t1.x + t1.y, t2.y = t2.x + t2.y WHERE t1.x > 7 AND t2.x < 7; from information_schema.innodb_vtq;
SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0'; end~~
SELECT x, y FROM t1; delimiter ;~~
SELECT x, y FROM t2 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0-0-0 0:0:0' AND TIMESTAMP '9999-1-1 0:0:0';
SELECT x, y FROM t2; call verify_vtq;
DROP TABLE t1; drop procedure verify_vtq;
DROP TABLE t2;
...@@ -660,28 +660,27 @@ drop table t1, t2; ...@@ -660,28 +660,27 @@ drop table t1, t2;
--echo # --echo #
--echo # --echo #
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING;
INSERT INTO t1(x, y) VALUES
(1, 1000),
(2, 2000),
(3, 3000),
(4, 4000),
(5, 5000),
(6, 6000),
(7, 7000),
(8, 8000),
(9, 9000);
SELECT x, y FROM t1;
UPDATE t1 SET y = y + 1 WHERE x > 7;
SELECT x, y FROM t1;
SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07';
DROP TABLE t1;
-- source include/have_innodb.inc -- source include/have_innodb.inc
set @@session.time_zone='+00:00';
select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq; select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
CREATE TABLE t1(x INT UNSIGNED, y INT UNSIGNED, Sys_start TIMESTAMP(6) GENERATED ALWAYS AS ROW START, Sys_end TIMESTAMP(6) GENERATED ALWAYS AS ROW END, PERIOD FOR SYSTEM_TIME (Sys_start, Sys_end)) WITH SYSTEM VERSIONING ENGINE=InnoDB;
INSERT INTO t1(x, y) VALUES delimiter ~~;
create procedure test_01(
sys_type varchar(255),
engine varchar(255),
fields varchar(255))
begin
set @str= concat('
create table t1(
x int unsigned,
y int unsigned,
sys_start ', sys_type, ' generated always as row start,
sys_end ', sys_type, ' generated always as row end,
period for system_time (sys_start, sys_end))
with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
insert into t1(x, y) values
(1, 1000), (1, 1000),
(2, 2000), (2, 2000),
(3, 3000), (3, 3000),
...@@ -691,10 +690,39 @@ INSERT INTO t1(x, y) VALUES ...@@ -691,10 +690,39 @@ INSERT INTO t1(x, y) VALUES
(7, 7000), (7, 7000),
(8, 8000), (8, 8000),
(9, 9000); (9, 9000);
SELECT x, y FROM t1; select x, y from t1;
UPDATE t1 SET y = y + 1 WHERE x > 7; update t1 set y = y + 1 where x > 7;
SELECT x, y FROM t1; select x, y from t1;
SELECT x, y FROM t1 FOR SYSTEM_TIME BETWEEN TIMESTAMP '0000-0-0 0:0:0' AND TIMESTAMP '2038-01-19 04:14:07'; select x, y from t1 for system_time
DROP TABLE t1; between timestamp '0000-0-0 0:0:0'
and timestamp '2038-01-19 04:14:07';
SET @i = 0; SELECT @i:=@i+1 AS No, trx_id > 0 AS A, begin_ts > '2015-1-1 0:0:0' AS B, commit_ts > begin_ts AS C, concurr_trx IS NULL AS D FROM INFORMATION_SCHEMA.INNODB_VTQ WHERE trx_id > @start_trx_id; drop table t1;
end~~
delimiter ;~~
call test_01('timestamp(6)', 'myisam', 'sys_end');
call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
drop procedure test_01;
# VTQ test
delimiter ~~;
create procedure verify_vtq()
begin
set @i= 0;
select
@i:= @i + 1 as No,
trx_id > 0 as A,
begin_ts > '1-1-1 0:0:0' as B,
commit_ts > begin_ts as C,
concurr_trx is null as D
from information_schema.innodb_vtq
where trx_id > @start_trx_id;
select ifnull(max(trx_id), 0)
into @start_trx_id
from information_schema.innodb_vtq;
end~~
delimiter ;~~
call verify_vtq;
drop procedure verify_vtq;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment