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'
DROP VIEW v2, v1;
DROP TABLE t1, t2;
#
# Test for SYSTEM VERSIONING
# System Versioning Support
#
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';
XNo Sys_end < '2038-01-19 03:14:07'
#
set @@session.time_zone='+00:00';
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(
XNo 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(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);
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
1 0
2 0
......@@ -557,9 +586,7 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 0
8 0
9 0
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';
XNo Sys_end < '2038-01-19 03:14:07'
XNo sys_end < '2038-01-19 03:14:07'
0 1
1 0
2 0
......@@ -570,9 +597,7 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 0
8 0
9 0
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';
XNo Sys_end < '2038-01-19 03:14:07'
XNo sys_end < '2038-01-19 03:14:07'
0 1
1 1
2 0
......@@ -583,22 +608,16 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 0
8 0
9 0
DELETE FROM t1 WHERE XNo > 5;
CREATE VIEW vt1 AS SELECT XNo FROM t1;
SELECT XNo FROM vt1;
XNo
2
3
4
5
DELETE FROM vt1 WHERE XNo = 3;
SELECT XNo FROM vt1;
XNo
2
4
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
1 1
2 0
......@@ -609,27 +628,8 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 1
8 1
9 1
DROP VIEW vt1;
DROP TABLE t1;
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'
call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
XNo commit_ts(sys_end) < '2038-01-19 03:14:07'
0 0
1 0
2 0
......@@ -640,9 +640,7 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 0
8 0
9 0
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';
XNo Sys_end < '2038-01-19 03:14:07'
XNo commit_ts(sys_end) < '2038-01-19 03:14:07'
0 1
1 0
2 0
......@@ -653,9 +651,7 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 0
8 0
9 0
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';
XNo Sys_end < '2038-01-19 03:14:07'
XNo commit_ts(sys_end) < '2038-01-19 03:14:07'
0 1
1 1
2 0
......@@ -666,22 +662,16 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 0
8 0
9 0
DELETE FROM t1 WHERE XNo > 5;
CREATE VIEW vt1 AS SELECT XNo FROM t1;
SELECT XNo FROM vt1;
XNo
2
3
4
5
DELETE FROM vt1 WHERE XNo = 3;
SELECT XNo FROM vt1;
XNo
2
4
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 commit_ts(sys_end) < '2038-01-19 03:14:07'
0 1
1 1
2 0
......@@ -692,10 +682,23 @@ XNo Sys_end < '2038-01-19 03:14:07'
7 1
8 1
9 1
DROP VIEW vt1;
DROP TABLE t1;
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_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
......@@ -711,3 +714,4 @@ No A B C D
12 1 1 1 1
13 1 1 1 1
14 1 1 1 1
drop procedure verify_vtq;
This diff is collapsed.
......@@ -860,9 +860,26 @@ End of 5.1 tests
# 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;
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
set @@session.time_zone='+00:00';
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('(
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),
(2, 2000),
(3, 3000),
......@@ -872,8 +889,8 @@ INSERT INTO t1(x, y) VALUES
(7, 7000),
(8, 8000),
(9, 9000);
DELETE FROM t1 WHERE x >= 1;
INSERT INTO t1(x, y) VALUES
delete from t1 where x >= 1;
insert into t1(x, y) values
(1, 1001),
(2, 2001),
(3, 3001),
......@@ -883,8 +900,13 @@ INSERT INTO t1(x, y) VALUES
(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;
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;
end~~
call test_01('timestamp(6)', 'myisam', 'sys_end');
x y
1 1001
2 2001
......@@ -895,7 +917,6 @@ x y
7 7001
8 8001
9 9001
SELECT x, y FROM t2;
x y
1 1000
2 2000
......@@ -915,33 +936,7 @@ x y
7 7001
8 8001
9 9001
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),
(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;
call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
x y
1 1001
2 2001
......@@ -952,7 +947,6 @@ x y
7 7001
8 8001
9 9001
SELECT x, y FROM t2;
x y
1 1000
2 2000
......@@ -972,5 +966,26 @@ x y
7 7001
8 8001
9 9001
DROP TABLE t1;
DROP TABLE t2;
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
drop procedure verify_vtq;
......@@ -416,8 +416,25 @@ drop table t1;
# 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;
INSERT INTO t1(x, y) VALUES
set @@session.time_zone='+00:00';
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),
(2, 2000),
(3, 3000),
......@@ -427,11 +444,15 @@ INSERT INTO t1(x, y) VALUES
(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';
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';
select x, y from t1;
drop table t1;
end~~
call test_01('timestamp(6)', 'myisam', 'sys_end');
x y
1 1000
2 2000
......@@ -446,35 +467,18 @@ x y
4 4000
4 4001
4 4444
SELECT x, y FROM t1;
x y
1 1000
2 2000
3 3001
4 4002
4 4444
5 5000
6 6000
7 7000
8 8000
9 9000
4 4444
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';
call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
x y
1 1000
2 2000
......@@ -489,7 +493,6 @@ x y
7 7000
8 8000
9 9000
SELECT x, y FROM t1;
x y
1 1000
2 2000
......@@ -501,4 +504,27 @@ x y
7 7000
8 8000
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
# 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;
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;
INSERT INTO t1(x, y) VALUES
set @@session.time_zone='+00:00';
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('(
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),
(2, 2000),
(3, 3000),
......@@ -1072,7 +1089,7 @@ INSERT INTO t1(x, y) VALUES
(7, 7000),
(8, 8000),
(9, 9000);
INSERT INTO t2(x, y) VALUES
insert into t2(x, y) values
(1, 1010),
(2, 2010),
(3, 3010),
......@@ -1082,8 +1099,15 @@ INSERT INTO t2(x, y) VALUES
(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';
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;
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
1 1000
2 2000
......@@ -1096,7 +1120,6 @@ x y
9 9009
8 8000
9 9000
SELECT x, y FROM t1;
x y
1 1000
2 2000
......@@ -1107,7 +1130,6 @@ x y
7 7000
8 8008
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
1 1011
2 2012
......@@ -1124,7 +1146,6 @@ x y
4 4010
5 5010
6 6010
SELECT x, y FROM t2;
x y
1 1011
2 2012
......@@ -1135,32 +1156,7 @@ x y
7 7010
8 8010
9 9010
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),
(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';
call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
x y
1 1000
2 2000
......@@ -1173,7 +1169,6 @@ x y
9 9009
8 8000
9 9000
SELECT x, y FROM t1;
x y
1 1000
2 2000
......@@ -1184,7 +1179,6 @@ x y
7 7000
8 8008
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
1 1011
2 2012
......@@ -1201,7 +1195,6 @@ x y
4 4010
5 5010
6 6010
SELECT x, y FROM t2;
x y
1 1011
2 2012
......@@ -1212,5 +1205,25 @@ x y
7 7010
8 8010
9 9010
DROP TABLE t1;
DROP TABLE t2;
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
drop procedure verify_vtq;
......@@ -723,8 +723,24 @@ drop table t1, t2;
# 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;
INSERT INTO t1(x, y) VALUES
set @@session.time_zone='+00:00';
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),
(2, 2000),
(3, 3000),
......@@ -734,7 +750,15 @@ INSERT INTO t1(x, y) VALUES
(7, 7000),
(8, 8000),
(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
1 1000
2 2000
......@@ -745,8 +769,6 @@ x y
7 7000
8 8000
9 9000
UPDATE t1 SET y = y + 1 WHERE x > 7;
SELECT x, y FROM t1;
x y
1 1000
2 2000
......@@ -757,7 +779,6 @@ x y
7 7000
8 8001
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
1 1000
2 2000
......@@ -770,20 +791,7 @@ x y
9 9001
8 8000
9 9000
DROP TABLE t1;
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;
call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
x y
1 1000
2 2000
......@@ -794,8 +802,6 @@ x y
7 7000
8 8000
9 9000
UPDATE t1 SET y = y + 1 WHERE x > 7;
SELECT x, y FROM t1;
x y
1 1000
2 2000
......@@ -806,7 +812,6 @@ x y
7 7000
8 8001
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
1 1000
2 2000
......@@ -819,9 +824,24 @@ x y
9 9001
8 8000
9 9000
DROP TABLE t1;
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_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
drop procedure verify_vtq;
......@@ -587,83 +587,83 @@ DROP TABLE t1, t2;
# SQL DELETE for SYSTEM VERSIONING
#
--echo #
--echo # Test for SYSTEM VERSIONING
--echo # System Versioning Support
--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
set @@session.time_zone='+00:00';
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';
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;
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;
delimiter ~~;
create procedure test_01(
sys_type varchar(255),
engine varchar(255),
fields varchar(255))
begin
set @str= concat('
create table t1(
XNo 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(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);
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~~
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;
--echo #
-- 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;
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;
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(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;
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;
DROP TABLE t1;
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;
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;
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;
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);
--error ER_GENERATED_FIELD_CANNOT_BE_SET_BY_USER
INSERT INTO t1(x, y, Sys_end) VALUES(8001, 9001, '2015-1-1 0:0:0');
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);
--error ER_GENERATED_FIELD_CANNOT_BE_SET_BY_USER
INSERT INTO vt1_2 VALUES(3002, 4002, '2015-1-1 0:0:0');
SELECT x, y, Sys_end FROM t1;
SELECT x, y FROM vt1_1;
SELECT x, y, Sys_end FROM vt1_2;
DROP TABLE t1;
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);
--error ER_GENERATED_FIELD_CANNOT_BE_SET_BY_USER
INSERT INTO t1(x, y, Sys_end) VALUES(8001, 9001, '2015-1-1 0:0:0');
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);
--error ER_GENERATED_FIELD_CANNOT_BE_SET_BY_USER
INSERT INTO vt1_2 VALUES(3002, 4002, '2015-1-1 0:0:0');
SELECT x, y, Sys_end FROM t1;
SELECT x, y FROM vt1_1;
SELECT x, y, Sys_end FROM vt1_2;
DROP TABLE t1;
DROP VIEW vt1_1;
DROP VIEW vt1_2;
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;
select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
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 TABLE t2(x INT UNSIGNED) ENGINE=InnoDB;
START TRANSACTION;
INSERT INTO t1(x) VALUES(1);
COMMIT;
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(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~~
delimiter ;~~
call test_01('timestamp(6)', 'myisam', 'sys_end');
call test_01('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
drop procedure test_01;
delimiter ~~;
create procedure test_02(
sys_type varchar(255),
engine varchar(255),
fields varchar(255))
begin
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~~
delimiter ;~~
call test_02('timestamp(6)', 'myisam', 'sys_end');
call test_02('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
drop procedure test_02;
delimiter ~~;
create procedure test_03(
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;
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;
START TRANSACTION;
INSERT INTO t2(x) VALUES(1);
SAVEPOINT a;
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;
drop table t1;
drop table t2;
drop procedure verify_vtq;
\ No newline at end of file
......@@ -432,61 +432,79 @@ DROP TABLE t1;
--echo #
-- source include/have_innodb.inc
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;
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
(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;
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),
(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;
SELECT x, y FROM t2;
DROP TABLE t1;
DROP TABLE t2;
set @@session.time_zone='+00:00';
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),
(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;
select x, y from t2;
drop table t1;
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,41 +318,69 @@ drop table t1;
--echo #
-- source include/have_innodb.inc
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;
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';
SELECT x, y 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), 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';
SELECT x, y FROM t1;
DROP TABLE t1;
set @@session.time_zone='+00:00';
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('
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),
(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';
select x, y from t1;
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;
......@@ -1041,62 +1041,81 @@ SET SESSION SQL_MODE=default;
--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;
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;
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';
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;
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';
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;
-- 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;
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),
(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';
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~~
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;
......@@ -660,41 +660,69 @@ drop table t1, t2;
--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
set @@session.time_zone='+00:00';
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;
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;
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;
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),
(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;
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