mirror of
https://github.com/MariaDB/server.git
synced 2025-08-21 16:03:24 +03:00
212 lines
6.2 KiB
Plaintext
212 lines
6.2 KiB
Plaintext
set @@session.time_zone='+00:00';
|
|
select ifnull(max(transaction_id), 0) into @start_trx_id from mysql.transaction_registry;
|
|
set @test_start=now(6);
|
|
create procedure if not exists verify_vtq()
|
|
begin
|
|
set @i= 0;
|
|
select
|
|
@i:= @i + 1 as No,
|
|
transaction_id > 0 as A,
|
|
commit_id > transaction_id as B,
|
|
begin_timestamp > @test_start as C,
|
|
commit_timestamp >= begin_timestamp as D
|
|
from mysql.transaction_registry
|
|
where transaction_id > @start_trx_id;
|
|
select ifnull(max(transaction_id), 0)
|
|
into @start_trx_id
|
|
from mysql.transaction_registry;
|
|
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_archive_table_name()
|
|
returns varchar(255)
|
|
begin
|
|
return (select archive_name from t_vtmd for system_time all where archive_name is not NULL
|
|
order by start desc limit 1);
|
|
end~~
|
|
create procedure drop_last_archive()
|
|
begin
|
|
call concat_exec2('drop table ', get_archive_table_name());
|
|
end~~
|
|
set versioning_alter_history= survive;
|
|
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_archive_table_name(), ' for system_time all');
|
|
a
|
|
2
|
|
1
|
|
call concat_exec3('select @tm=sys_trx_start from ', get_archive_table_name(), ' 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_archive_table_name(), ' for system_time all where a=2');
|
|
@tm=sys_trx_end
|
|
1
|
|
call drop_last_archive();
|
|
set versioning_alter_history= keep;
|
|
drop table t_vtmd;
|
|
drop table t;
|
|
set versioning_alter_history= survive;
|
|
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_archive_table_name(), ' for system_time all');
|
|
a
|
|
2
|
|
1
|
|
call concat_exec3('select @tm=sys_trx_start from ', get_archive_table_name(), ' 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_archive_table_name(), ' for system_time all where a=2');
|
|
@tm=sys_trx_end
|
|
1
|
|
call drop_last_archive();
|
|
set versioning_alter_history= keep;
|
|
drop table t_vtmd;
|
|
drop table t;
|
|
set versioning_alter_history= survive;
|
|
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_archive_table_name(), ' for system_time all');
|
|
a
|
|
2
|
|
1
|
|
call concat_exec3('select @tm=sys_trx_start from ', get_archive_table_name(), ' 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_archive_table_name(), ' for system_time all where a=2');
|
|
@tm=sys_trx_end
|
|
1
|
|
call drop_last_archive();
|
|
set versioning_alter_history= keep;
|
|
drop table t_vtmd;
|
|
drop table t;
|
|
set versioning_alter_history= survive;
|
|
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_alter_history = keep;
|
|
drop function get_archive_table_name;
|
|
drop procedure drop_last_archive;
|
|
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 current lifetime period',
|
|
`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`),
|
|
KEY `archive_name` (`archive_name`),
|
|
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
|
|
6 1 1 1 1
|
|
7 1 1 1 1
|
|
8 1 1 1 1
|
|
9 1 1 1 1
|
|
10 1 1 1 1
|
|
11 1 1 1 1
|
|
12 1 1 1 1
|
|
drop table t;
|
|
drop table t_vtmd;
|
|
drop procedure verify_vtq;
|
|
drop procedure innodb_verify_vtq;
|
|
drop function default_engine;
|
|
drop function sys_commit_ts;
|
|
drop function sys_datatype;
|
|
drop procedure concat_exec2;
|
|
drop procedure concat_exec3;
|