mirror of
https://github.com/MariaDB/server.git
synced 2025-01-31 02:51:44 +01:00
189 lines
5.8 KiB
Text
189 lines
5.8 KiB
Text
set @@session.time_zone='+00:00';
|
|
select ifnull(max(trx_id), 0) into @start_trx_id from information_schema.innodb_vtq;
|
|
create procedure if not exists verify_vtq()
|
|
begin
|
|
set @i= 0;
|
|
select
|
|
@i:= @i + 1 as No,
|
|
trx_id > 0 as A,
|
|
commit_id > trx_id as B,
|
|
begin_ts > '1-1-1 0:0:0' as C,
|
|
commit_ts >= begin_ts 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~~
|
|
create function if not exists default_engine()
|
|
returns varchar(255)
|
|
deterministic
|
|
begin
|
|
declare e varchar(255);
|
|
select lower(engine) from information_schema.engines where support='DEFAULT' into e;
|
|
return e;
|
|
end~~
|
|
create function if not exists sys_datatype()
|
|
returns varchar(255)
|
|
deterministic
|
|
begin
|
|
if default_engine() = 'innodb' then
|
|
return 'bigint unsigned';
|
|
elseif default_engine() = 'myisam' then
|
|
return 'timestamp(6)';
|
|
end if;
|
|
return NULL;
|
|
end~~
|
|
create function if not exists sys_commit_ts(sys_field varchar(255))
|
|
returns varchar(255)
|
|
deterministic
|
|
begin
|
|
if default_engine() = 'innodb' then
|
|
return concat('vtq_commit_ts(', sys_field, ')');
|
|
elseif default_engine() = 'myisam' then
|
|
return sys_field;
|
|
end if;
|
|
return NULL;
|
|
end~~
|
|
create procedure if not exists innodb_verify_vtq(recs int)
|
|
begin
|
|
declare i int default 1;
|
|
if default_engine() = 'innodb' then
|
|
call verify_vtq;
|
|
elseif default_engine() = 'myisam' then
|
|
create temporary table tmp (No int, A bool, B bool, C bool, D bool);
|
|
while i <= recs do
|
|
insert into tmp values (i, 1, 1, 1, 1);
|
|
set i= i + 1;
|
|
end while;
|
|
select * from tmp;
|
|
drop table tmp;
|
|
end if;
|
|
end~~
|
|
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~~
|
|
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;
|
|
a b
|
|
2 NULL
|
|
call concat_exec3('select * from ', get_historical_table_name('t'), ' for system_time all');
|
|
a
|
|
2
|
|
1
|
|
call concat_exec3('select @tm=sys_trx_start from ', get_historical_table_name('t'), ' for system_time all where a=2');
|
|
@tm=sys_trx_start
|
|
1
|
|
select @tm<sys_trx_start from t where a=2;
|
|
@tm<sys_trx_start
|
|
1
|
|
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');
|
|
@tm=sys_trx_end
|
|
1
|
|
call drop_last_historical('t');
|
|
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;
|
|
a b
|
|
2 NULL
|
|
call concat_exec3('select * from ', get_historical_table_name('t'), ' for system_time all');
|
|
a
|
|
2
|
|
1
|
|
call concat_exec3('select @tm=sys_trx_start from ', get_historical_table_name('t'), ' for system_time all where a=2');
|
|
@tm=sys_trx_start
|
|
1
|
|
select @tm<sys_trx_start from t where a=2;
|
|
@tm<sys_trx_start
|
|
1
|
|
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');
|
|
@tm=sys_trx_end
|
|
1
|
|
call drop_last_historical('t');
|
|
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;
|
|
a b
|
|
2 NULL
|
|
call concat_exec3('select * from ', get_historical_table_name('t'), ' for system_time all');
|
|
a
|
|
2
|
|
1
|
|
call concat_exec3('select @tm=sys_trx_start from ', get_historical_table_name('t'), ' for system_time all where a=2');
|
|
@tm=sys_trx_start
|
|
1
|
|
select @tm<sys_trx_start from t where a=2;
|
|
@tm<sys_trx_start
|
|
1
|
|
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');
|
|
@tm=sys_trx_end
|
|
1
|
|
call drop_last_historical('t');
|
|
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;
|
|
select * from mysql.vtmd_template;
|
|
start end name archive_name col_renames
|
|
show create table mysql.vtmd_template;
|
|
Table Create Table
|
|
vtmd_template CREATE TABLE `vtmd_template` (
|
|
`start` bigint(20) unsigned GENERATED ALWAYS AS ROW START COMMENT 'TRX_ID of table lifetime start',
|
|
`end` bigint(20) unsigned GENERATED ALWAYS AS ROW END NOT NULL COMMENT 'TRX_ID of table lifetime end',
|
|
`name` varchar(64) COLLATE utf8_bin NOT NULL COMMENT 'Table name during period [start, end)',
|
|
`archive_name` varchar(64) COLLATE utf8_bin DEFAULT NULL COMMENT 'Name of archive table',
|
|
`col_renames` blob DEFAULT NULL COMMENT 'Column name mappings from previous lifetime',
|
|
PRIMARY KEY (`end`),
|
|
PERIOD FOR SYSTEM_TIME (`start`, `end`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin STATS_PERSISTENT=0 WITH SYSTEM VERSIONING
|
|
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 table t;
|
|
drop procedure verify_vtq;
|
|
drop procedure innodb_verify_vtq;
|
|
drop function default_engine;
|
|
drop function sys_commit_ts;
|
|
drop function sys_datatype;
|