1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

SQL: versioning DDL part I [closes #172]

This commit is contained in:
kevg
2017-04-24 14:47:44 +03:00
committed by Aleksey Midenkov
parent f94fd4b730
commit 0185872449
8 changed files with 457 additions and 17 deletions

View File

@@ -0,0 +1,104 @@
-- source suite/versioning/common.inc
delimiter ~~;
create procedure concat_exec2(a varchar(255), b varchar(255))
begin
prepare stmt from concat(a, b);
execute stmt;
deallocate prepare stmt;
end~~
create procedure concat_exec3(a varchar(255), b varchar(255), c varchar(255))
begin
prepare stmt from concat(a, b, c);
execute stmt;
deallocate prepare stmt;
end~~
create function get_historical_table_name(table_name_arg varchar(255))
returns varchar(255)
begin
return (select table_name from information_schema.tables
where table_schema='test' and table_name like concat(table_name_arg, '_%') limit 1);
end~~
create procedure drop_last_historical(table_name_arg varchar(255))
begin
call concat_exec2('drop table ', get_historical_table_name(table_name_arg));
end~~
delimiter ;~~
set versioning_ddl_survival = 1;
create or replace table t (a int) with system versioning;
insert into t values (1);
update t set a=2 where a=1;
select sys_trx_start from t where a=2 into @tm;
alter table t add column b int;
select * from t;
call concat_exec3('select * from ', get_historical_table_name('t'), ' for system_time all');
call concat_exec3('select @tm=sys_trx_start from ', get_historical_table_name('t'), ' for system_time all where a=2');
select @tm<sys_trx_start from t where a=2;
select sys_trx_start from t where a=2 into @tm;
call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t'), ' for system_time all where a=2');
call drop_last_historical('t');
# same for INNODB ALGORITHM=COPY
create or replace table t (a int) with system versioning;
insert into t values (1);
update t set a=2 where a=1;
select sys_trx_start from t where a=2 into @tm;
alter table t add column b int;
select * from t;
call concat_exec3('select * from ', get_historical_table_name('t'), ' for system_time all');
call concat_exec3('select @tm=sys_trx_start from ', get_historical_table_name('t'), ' for system_time all where a=2');
select @tm<sys_trx_start from t where a=2;
select sys_trx_start from t where a=2 into @tm;
call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t'), ' for system_time all where a=2');
call drop_last_historical('t');
# same for INNODB default ALGORITHM
create or replace table t (a int) with system versioning engine innodb;
insert into t values (1);
update t set a=2 where a=1;
select sys_trx_start from t where a=2 into @tm;
alter table t add column b int;
select * from t;
call concat_exec3('select * from ', get_historical_table_name('t'), ' for system_time all');
call concat_exec3('select @tm=sys_trx_start from ', get_historical_table_name('t'), ' for system_time all where a=2');
select @tm<sys_trx_start from t where a=2;
select sys_trx_start from t where a=2 into @tm;
call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t'), ' for system_time all where a=2');
call drop_last_historical('t');
# no DDL for INNODB explicit ALGORITHM=INPLACE
create or replace table t (a int) with system versioning engine innodb;
insert into t values (1);
update t set a=2 where a=1;
alter table t add column b int, algorithm=inplace;
set versioning_ddl_survival = 0;
drop procedure concat_exec2;
drop procedure concat_exec3;
drop function get_historical_table_name;
drop procedure drop_last_historical;
call verify_vtq;
drop table t;
-- source suite/versioning/common_finish.inc