Skip to content

Commit

Permalink
SQL: hide archive tables [closes #193]
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgs authored and midenok committed Sep 27, 2017
1 parent e9e3cb0 commit c5801dd
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 65 deletions.
38 changes: 19 additions & 19 deletions mysql-test/suite/versioning/r/ddl.result
Expand Up @@ -72,15 +72,15 @@ prepare stmt from concat(a, b, c);
execute stmt;
deallocate prepare stmt;
end~~
create function get_historical_table_name(table_name_arg varchar(255))
create function get_archive_table_name()
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);
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_historical(table_name_arg varchar(255))
create procedure drop_last_archive()
begin
call concat_exec2('drop table ', get_historical_table_name(table_name_arg));
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;
Expand All @@ -91,21 +91,21 @@ 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');
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_historical_table_name('t'), ' for system_time all where a=2');
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_historical_table_name('t'), ' for system_time all where a=2');
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_historical('t');
call drop_last_archive();
set versioning_alter_history= keep;
drop table t_vtmd;
drop table t;
Expand All @@ -118,21 +118,21 @@ 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');
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_historical_table_name('t'), ' for system_time all where a=2');
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_historical_table_name('t'), ' for system_time all where a=2');
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_historical('t');
call drop_last_archive();
set versioning_alter_history= keep;
drop table t_vtmd;
drop table t;
Expand All @@ -145,21 +145,21 @@ 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');
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_historical_table_name('t'), ' for system_time all where a=2');
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_historical_table_name('t'), ' for system_time all where a=2');
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_historical('t');
call drop_last_archive();
set versioning_alter_history= keep;
drop table t_vtmd;
drop table t;
Expand All @@ -169,8 +169,8 @@ 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_historical_table_name;
drop procedure drop_last_historical;
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;
Expand Down
79 changes: 67 additions & 12 deletions mysql-test/suite/versioning/r/vtmd.result
Expand Up @@ -44,6 +44,12 @@ substr(archive_name, 1, instr(archive_name, '_')) as C_archive_name
from tmp_vtmd for system_time all;
drop table tmp_vtmd;
end~~
create or replace procedure show_tables()
begin
show tables;
select table_name, table_schema from information_schema.tables
where table_schema not in ('mysql', 'performance_schema', 'information_schema', 'mtr');
end~~
set versioning_alter_history= keep;
create table t0 (z int) with system versioning;
show tables;
Expand Down Expand Up @@ -178,10 +184,6 @@ use db0;
show tables;
Tables_in_db0
t0
t0_TIMESTAMP_SUFFIX
t0_TIMESTAMP_SUFFIX
t0_TIMESTAMP_SUFFIX
t0_TIMESTAMP_SUFFIX
t0_vtmd
call test.check_vtmd('db0.t0_vtmd');
@start > 0 and @start < @inf
Expand All @@ -206,10 +208,6 @@ show tables;
Tables_in_db1
other_name
other_name_vtmd
t0_TIMESTAMP_SUFFIX
t0_TIMESTAMP_SUFFIX
t0_TIMESTAMP_SUFFIX
t0_TIMESTAMP_SUFFIX
call test.check_vtmd('db1.other_name_vtmd');
@start > 0 and @start < @inf
1
Expand Down Expand Up @@ -246,10 +244,6 @@ alter table t1 rename to test.t2, add column (y int);
use test;
show tables;
Tables_in_test
t0_TIMESTAMP_SUFFIX
t0_TIMESTAMP_SUFFIX
t0_TIMESTAMP_SUFFIX
t0_TIMESTAMP_SUFFIX
t2
t2_vtmd
call check_vtmd('t2_vtmd');
Expand Down Expand Up @@ -279,6 +273,67 @@ A_start B_end name C_archive_name
1 0 t3 t3_
1 0 t3 t3_
1 1 t3 NULL
set versioning_hide = auto;
call show_tables();
Tables_in_test
t2
t2_vtmd
t3
t3_vtmd
table_name table_schema
t2 test
t2_vtmd test
t3 test
t3_vtmd test
set versioning_hide = implicit;
call show_tables();
Tables_in_test
t2
t2_vtmd
t3
t3_vtmd
table_name table_schema
t2 test
t2_vtmd test
t3 test
t3_vtmd test
set versioning_hide = full;
call show_tables();
Tables_in_test
t2
t2_vtmd
t3
t3_vtmd
table_name table_schema
t2 test
t2_vtmd test
t3 test
t3_vtmd test
set versioning_hide = never;
call show_tables();
Tables_in_test
t0_TIMESTAMP_SUFFIX
t0_TIMESTAMP_SUFFIX
t0_TIMESTAMP_SUFFIX
t0_TIMESTAMP_SUFFIX
t2
t2_vtmd
t3
t3_TIMESTAMP_SUFFIX
t3_TIMESTAMP_SUFFIX
t3_vtmd
table_name table_schema
t1_TIMESTAMP_SUFFIX db1
t0_TIMESTAMP_SUFFIX test
t0_TIMESTAMP_SUFFIX test
t0_TIMESTAMP_SUFFIX test
t0_TIMESTAMP_SUFFIX test
t2 test
t2_vtmd test
t3 test
t3_TIMESTAMP_SUFFIX test
t3_TIMESTAMP_SUFFIX test
t3_vtmd test
drop database db0;
drop database db1;
drop database test;
Expand Down
38 changes: 19 additions & 19 deletions mysql-test/suite/versioning/t/ddl.test
@@ -1,16 +1,16 @@
-- source suite/versioning/common.inc

delimiter ~~;
create function get_historical_table_name(table_name_arg varchar(255))
create function get_archive_table_name()
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);
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_historical(table_name_arg varchar(255))
create procedure drop_last_archive()
begin
call concat_exec2('drop table ', get_historical_table_name(table_name_arg));
call concat_exec2('drop table ', get_archive_table_name());
end~~
delimiter ;~~

Expand All @@ -23,14 +23,14 @@ 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 * from ', get_archive_table_name(), ' 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');
call concat_exec3('select @tm=sys_trx_start from ', get_archive_table_name(), ' 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 concat_exec3('select @tm=sys_trx_end from ', get_archive_table_name(), ' for system_time all where a=2');

call drop_last_historical('t');
call drop_last_archive();


set versioning_alter_history= keep;
Expand All @@ -46,14 +46,14 @@ 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 * from ', get_archive_table_name(), ' 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');
call concat_exec3('select @tm=sys_trx_start from ', get_archive_table_name(), ' 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 concat_exec3('select @tm=sys_trx_end from ', get_archive_table_name(), ' for system_time all where a=2');

call drop_last_historical('t');
call drop_last_archive();


set versioning_alter_history= keep;
Expand All @@ -69,14 +69,14 @@ 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 * from ', get_archive_table_name(), ' 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');
call concat_exec3('select @tm=sys_trx_start from ', get_archive_table_name(), ' 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 concat_exec3('select @tm=sys_trx_end from ', get_archive_table_name(), ' for system_time all where a=2');

call drop_last_historical('t');
call drop_last_archive();


set versioning_alter_history= keep;
Expand All @@ -92,8 +92,8 @@ alter table t add column b int, algorithm=inplace;

set versioning_alter_history = keep;

drop function get_historical_table_name;
drop procedure drop_last_historical;
drop function get_archive_table_name;
drop procedure drop_last_archive;

select * from mysql.vtmd_template;
show create table mysql.vtmd_template;
Expand Down
25 changes: 22 additions & 3 deletions mysql-test/suite/versioning/t/vtmd.test
Expand Up @@ -56,6 +56,15 @@ begin
end~~
delimiter ;~~

delimiter ~~;
create or replace procedure show_tables()
begin
show tables;
select table_name, table_schema from information_schema.tables
where table_schema not in ('mysql', 'performance_schema', 'information_schema', 'mtr');
end~~
delimiter ;~~

# create
set versioning_alter_history= keep;
create table t0 (z int) with system versioning;
Expand Down Expand Up @@ -136,15 +145,13 @@ create database db0;
rename table t0 to db0.t0;
show tables;
use db0;
--replace_regex /\d{8}_\d{6}_\d{6}/TIMESTAMP_SUFFIX/
show tables;
call test.check_vtmd('db0.t0_vtmd');

create database db1;
rename table t0 to db1.other_name;
show tables;
use db1;
--replace_regex /\d{8}_\d{6}_\d{6}/TIMESTAMP_SUFFIX/
show tables;
call test.check_vtmd('db1.other_name_vtmd');

Expand All @@ -155,7 +162,6 @@ call test.check_vtmd('db1.t1_vtmd');
# alter rename and modify to different schema
alter table t1 rename to test.t2, add column (y int);
use test;
--replace_regex /\d{8}_\d{6}_\d{6}/TIMESTAMP_SUFFIX/
show tables;
call check_vtmd('t2_vtmd');

Expand All @@ -164,6 +170,19 @@ alter table t3 change x x bigint;
alter table t3 change x x bigint after sys_trx_start;
call check_vtmd('t3_vtmd');

set versioning_hide = auto;
call show_tables();

set versioning_hide = implicit;
call show_tables();

set versioning_hide = full;
call show_tables();

set versioning_hide = never;
--replace_regex /\d{8}_\d{6}_\d{6}/TIMESTAMP_SUFFIX/
call show_tables();

drop database db0;
drop database db1;
drop database test;
Expand Down

0 comments on commit c5801dd

Please sign in to comment.