2016-10-18 09:05:49 +00:00
|
|
|
-- source suite/versioning/common.inc
|
|
|
|
|
|
|
|
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,
|
2017-12-19 16:12:56 +03:00
|
|
|
sys_start ', sys_type, ' as row start invisible,
|
|
|
|
sys_end ', sys_type, ' as row end invisible,
|
2016-10-18 09:05:49 +00:00
|
|
|
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);
|
2017-11-29 11:57:52 +03:00
|
|
|
insert delayed into t1(x, y) values(2, 3);
|
2016-10-18 09:05:49 +00:00
|
|
|
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~~
|
|
|
|
|
|
|
|
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,
|
2017-12-19 16:12:56 +03:00
|
|
|
sys_start ', sys_type, ' as row start invisible,
|
|
|
|
sys_end ', sys_type, ' as row end invisible,
|
2016-10-18 09:05:49 +00:00
|
|
|
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~~
|
|
|
|
|
|
|
|
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,
|
2017-12-19 16:12:56 +03:00
|
|
|
sys_start ', sys_type, ' as row start invisible,
|
|
|
|
sys_end ', sys_type, ' as row end invisible,
|
2016-10-18 09:05:49 +00:00
|
|
|
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;
|
|
|
|
insert into t1(x, y) values(8001, 9001);
|
|
|
|
insert into vt1_1(x, y) values(1001, 2001);
|
|
|
|
insert into vt1_1 values(1002, 2002);
|
|
|
|
set @str= concat('select x, y, ', fields, ' from t1');
|
|
|
|
prepare stmt from @str; execute stmt; drop prepare stmt;
|
|
|
|
select x, y from vt1_1;
|
|
|
|
end~~
|
|
|
|
|
|
|
|
create procedure test_04(
|
|
|
|
sys_type varchar(255),
|
|
|
|
engine varchar(255),
|
|
|
|
fields varchar(255))
|
|
|
|
begin
|
|
|
|
set @str= concat('
|
|
|
|
create table t1(
|
|
|
|
id bigint primary key,
|
|
|
|
a int,
|
|
|
|
b int)
|
|
|
|
with system versioning
|
|
|
|
engine ', engine);
|
|
|
|
prepare stmt from @str; execute stmt; drop prepare stmt;
|
|
|
|
insert into t1 values(1, 1, 1);
|
2018-01-08 18:03:55 +01:00
|
|
|
select row_start, row_end from t1 into @sys_start, @sys_end;
|
2016-10-18 09:05:49 +00:00
|
|
|
select id, a, b from t1;
|
|
|
|
insert into t1 values(2, 2, 2);
|
2018-01-08 18:03:55 +01:00
|
|
|
select id, a, b, row_start > @sys_start as C, row_end = @sys_end as D from t1 where id = 2;
|
2016-10-18 09:05:49 +00:00
|
|
|
drop table t1;
|
|
|
|
end~~
|
|
|
|
|
|
|
|
create procedure test_05(
|
|
|
|
sys_type varchar(255),
|
|
|
|
engine varchar(255),
|
|
|
|
fields varchar(255))
|
|
|
|
begin
|
|
|
|
set @str= concat('(
|
|
|
|
x int unsigned,
|
|
|
|
y int unsigned,
|
2017-12-19 16:12:56 +03:00
|
|
|
sys_start ', sys_type, ' as row start invisible,
|
|
|
|
sys_end ', sys_type, ' as row end invisible,
|
2016-10-18 09:05:49 +00:00
|
|
|
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),
|
2017-12-10 23:52:51 +03:00
|
|
|
(6, 6001);
|
|
|
|
insert into t1(x, y, sys_start) values
|
|
|
|
(7, 7001, DEFAULT);
|
|
|
|
insert into t1(x, y, sys_end) values
|
|
|
|
(8, 8001, DEFAULT);
|
|
|
|
insert into t1(x, y, sys_start, sys_end) values
|
|
|
|
(9, 9001, DEFAULT, DEFAULT);
|
2016-10-18 09:05:49 +00:00
|
|
|
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');
|
2016-11-14 06:14:28 +00:00
|
|
|
call test_01('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
|
2016-10-18 09:05:49 +00:00
|
|
|
|
|
|
|
call test_02('timestamp(6)', 'myisam', 'sys_end');
|
2016-11-14 06:14:28 +00:00
|
|
|
call test_02('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
|
2016-10-18 09:05:49 +00:00
|
|
|
|
|
|
|
call test_03('timestamp(6)', 'myisam', 'sys_end');
|
|
|
|
drop table t1;
|
|
|
|
drop view vt1_1;
|
|
|
|
|
2016-11-14 06:14:28 +00:00
|
|
|
call test_03('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
|
2016-10-18 09:05:49 +00:00
|
|
|
drop table t1;
|
|
|
|
drop view vt1_1;
|
|
|
|
|
|
|
|
call test_04('timestamp(6)', 'myisam', 'sys_end');
|
2016-11-14 06:14:28 +00:00
|
|
|
call test_04('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
|
2016-10-18 09:05:49 +00:00
|
|
|
|
|
|
|
call test_05('timestamp(6)', 'myisam', 'sys_end');
|
2016-11-14 06:14:28 +00:00
|
|
|
call test_05('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
|
2016-10-18 09:05:49 +00:00
|
|
|
|
|
|
|
# VTQ test
|
|
|
|
|
|
|
|
call verify_vtq;
|
|
|
|
|
|
|
|
create table t1(
|
|
|
|
x int unsigned,
|
2017-12-19 16:12:56 +03:00
|
|
|
sys_start bigint unsigned as row start invisible,
|
|
|
|
sys_end bigint unsigned as row end invisible,
|
2016-10-18 09:05:49 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
start transaction;
|
|
|
|
insert into t2(x) values(1);
|
|
|
|
savepoint a;
|
|
|
|
insert into t1(x) values(1);
|
|
|
|
rollback to a;
|
|
|
|
commit;
|
|
|
|
call verify_vtq;
|
|
|
|
|
2017-11-28 18:12:18 +03:00
|
|
|
insert into t2(x) values (1);
|
|
|
|
|
2017-11-28 21:40:27 +03:00
|
|
|
# virtual columns
|
|
|
|
create or replace table t1 (
|
|
|
|
x int,
|
2017-12-18 19:03:51 +03:00
|
|
|
y int as (x) virtual,
|
2017-12-19 16:12:56 +03:00
|
|
|
sys_trx_start bigint unsigned as row start invisible,
|
|
|
|
sys_trx_end bigint unsigned as row end invisible,
|
2017-12-18 19:03:51 +03:00
|
|
|
period for system_time (sys_trx_start, sys_trx_end)
|
2017-11-28 21:40:27 +03:00
|
|
|
) engine=innodb with system versioning;
|
|
|
|
insert into t1 values (1, null);
|
|
|
|
update t1 set x= x + 1;
|
2017-12-18 19:03:51 +03:00
|
|
|
select x, y, sys_trx_end = 18446744073709551615 as current from t1 for system_time all;
|
2017-11-28 21:40:27 +03:00
|
|
|
|
2018-02-10 20:34:18 +01:00
|
|
|
create or replace table t1 (
|
|
|
|
x int,
|
|
|
|
row_start timestamp(6) as row start invisible,
|
|
|
|
row_end timestamp(6) as row end invisible,
|
|
|
|
period for system_time (row_start, row_end)
|
|
|
|
) with system versioning;
|
2018-01-01 13:41:50 +03:00
|
|
|
insert into t1 values (1), (2);
|
|
|
|
--error ER_WARNING_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN
|
2018-01-08 18:03:55 +01:00
|
|
|
insert into t1 (row_start) select row_end from t1;
|
2018-01-08 20:15:42 +01:00
|
|
|
set sql_mode='';
|
2018-01-08 18:03:55 +01:00
|
|
|
insert into t1 (row_start, row_end) values (DEFAULT, 1);
|
2018-01-08 20:15:42 +01:00
|
|
|
set sql_mode=default;
|
2018-01-01 13:41:50 +03:00
|
|
|
select @@sql_mode into @saved_mode;
|
|
|
|
set sql_mode= '';
|
2018-01-08 18:03:55 +01:00
|
|
|
insert into t1 (x, row_start, row_end) values (3, 4, 5);
|
2018-01-01 13:41:50 +03:00
|
|
|
set sql_mode= @saved_mode;
|
2018-01-08 18:03:55 +01:00
|
|
|
insert into t1 (row_start, row_end) values (DEFAULT, DEFAULT);
|
2018-01-01 13:41:50 +03:00
|
|
|
select * from t1;
|
|
|
|
|
|
|
|
--echo # MDEV-14792 INSERT without column list into table with explicit versioning columns produces bad data
|
|
|
|
create or replace table t1 (
|
|
|
|
i int,
|
|
|
|
s timestamp(6) as row start,
|
|
|
|
e timestamp(6) as row end,
|
|
|
|
c varchar(8),
|
|
|
|
period for system_time(s, e))
|
|
|
|
with system versioning;
|
|
|
|
insert into t1 values (1, null, null, 'foo');
|
2018-01-29 19:52:34 +04:00
|
|
|
select i, c, e>TIMESTAMP'2038-01-01 00:00:00' AS current_row from t1;
|
2017-12-12 22:33:49 +03:00
|
|
|
|
2016-10-18 09:05:49 +00:00
|
|
|
drop table t1;
|
|
|
|
drop table t2;
|
|
|
|
|
|
|
|
drop procedure test_01;
|
|
|
|
drop procedure test_02;
|
|
|
|
drop procedure test_03;
|
|
|
|
drop procedure test_04;
|
|
|
|
drop procedure test_05;
|
2017-03-15 18:36:54 +03:00
|
|
|
|
|
|
|
-- source suite/versioning/common_finish.inc
|
2018-01-04 22:15:05 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# MDEV-14788 System versioning cannot be based on local timestamps, as it is now
|
|
|
|
#
|
|
|
|
set timestamp=1000000019;
|
|
|
|
select now() < sysdate();
|
|
|
|
create table t1 (a int) with system versioning;
|
|
|
|
insert t1 values (1);
|
2018-01-11 16:34:32 +01:00
|
|
|
|
|
|
|
--source suite/versioning/wait_system_clock.inc
|
|
|
|
set @a=sysdate(6);
|
|
|
|
|
2018-01-04 22:15:05 +01:00
|
|
|
select * from t1 for system_time as of now(6);
|
|
|
|
select * from t1 for system_time as of sysdate(6);
|
2018-01-11 19:41:32 +01:00
|
|
|
update t1 set a=2;
|
|
|
|
delete from t1;
|
|
|
|
--sorted_result
|
|
|
|
select *, row_start > @a, row_end > @a from t1 for system_time all;
|
2018-01-10 12:30:27 +03:00
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # MDEV-14871 Server crashes in fill_record / fill_record_n_invoke_before_triggers upon inserting into versioned table with trigger
|
|
|
|
--echo #
|
|
|
|
create or replace table t1 (pk int primary key) with system versioning;
|
|
|
|
create trigger tr before insert on t1 for each row select 1 into @a;
|
|
|
|
insert into t1 values (1),(2);
|
2018-02-02 15:01:53 +03:00
|
|
|
drop table t1;
|
2018-01-10 12:30:27 +03:00
|
|
|
|
2018-02-02 15:01:53 +03:00
|
|
|
#
|
|
|
|
# MDEV-14794 Limitations which the row end as a part of PK imposes due to CURRENT_TIMESTAMP behavior and otherwise
|
|
|
|
#
|
|
|
|
create table t1 (pk int primary key, i int) with system versioning;
|
|
|
|
replace into t1 values (1,10),(1,100),(1,1000);
|
|
|
|
select pk,i,row_end > '2038-01-01' from t1 for system_time all;
|
2018-01-04 22:15:05 +01:00
|
|
|
drop table t1;
|