mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
SQL: hide archive tables [closes #193]
This commit is contained in:
committed by
Aleksey Midenkov
parent
e9e3cb0f6e
commit
c5801dd67b
@ -72,15 +72,15 @@ prepare stmt from concat(a, b, c);
|
|||||||
execute stmt;
|
execute stmt;
|
||||||
deallocate prepare stmt;
|
deallocate prepare stmt;
|
||||||
end~~
|
end~~
|
||||||
create function get_historical_table_name(table_name_arg varchar(255))
|
create function get_archive_table_name()
|
||||||
returns varchar(255)
|
returns varchar(255)
|
||||||
begin
|
begin
|
||||||
return (select table_name from information_schema.tables
|
return (select archive_name from t_vtmd for system_time all where archive_name is not NULL
|
||||||
where table_schema='test' and table_name like concat(table_name_arg, '_%') limit 1);
|
order by start desc limit 1);
|
||||||
end~~
|
end~~
|
||||||
create procedure drop_last_historical(table_name_arg varchar(255))
|
create procedure drop_last_archive()
|
||||||
begin
|
begin
|
||||||
call concat_exec2('drop table ', get_historical_table_name(table_name_arg));
|
call concat_exec2('drop table ', get_archive_table_name());
|
||||||
end~~
|
end~~
|
||||||
set versioning_alter_history= survive;
|
set versioning_alter_history= survive;
|
||||||
create or replace table t (a int) with system versioning;
|
create or replace table t (a int) with system versioning;
|
||||||
@ -91,21 +91,21 @@ alter table t add column b int;
|
|||||||
select * from t;
|
select * from t;
|
||||||
a b
|
a b
|
||||||
2 NULL
|
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
|
a
|
||||||
2
|
2
|
||||||
1
|
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
|
@tm=sys_trx_start
|
||||||
1
|
1
|
||||||
select @tm<sys_trx_start from t where a=2;
|
select @tm<sys_trx_start from t where a=2;
|
||||||
@tm<sys_trx_start
|
@tm<sys_trx_start
|
||||||
1
|
1
|
||||||
select sys_trx_start from t where a=2 into @tm;
|
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
|
@tm=sys_trx_end
|
||||||
1
|
1
|
||||||
call drop_last_historical('t');
|
call drop_last_archive();
|
||||||
set versioning_alter_history= keep;
|
set versioning_alter_history= keep;
|
||||||
drop table t_vtmd;
|
drop table t_vtmd;
|
||||||
drop table t;
|
drop table t;
|
||||||
@ -118,21 +118,21 @@ alter table t add column b int;
|
|||||||
select * from t;
|
select * from t;
|
||||||
a b
|
a b
|
||||||
2 NULL
|
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
|
a
|
||||||
2
|
2
|
||||||
1
|
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
|
@tm=sys_trx_start
|
||||||
1
|
1
|
||||||
select @tm<sys_trx_start from t where a=2;
|
select @tm<sys_trx_start from t where a=2;
|
||||||
@tm<sys_trx_start
|
@tm<sys_trx_start
|
||||||
1
|
1
|
||||||
select sys_trx_start from t where a=2 into @tm;
|
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
|
@tm=sys_trx_end
|
||||||
1
|
1
|
||||||
call drop_last_historical('t');
|
call drop_last_archive();
|
||||||
set versioning_alter_history= keep;
|
set versioning_alter_history= keep;
|
||||||
drop table t_vtmd;
|
drop table t_vtmd;
|
||||||
drop table t;
|
drop table t;
|
||||||
@ -145,21 +145,21 @@ alter table t add column b int;
|
|||||||
select * from t;
|
select * from t;
|
||||||
a b
|
a b
|
||||||
2 NULL
|
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
|
a
|
||||||
2
|
2
|
||||||
1
|
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
|
@tm=sys_trx_start
|
||||||
1
|
1
|
||||||
select @tm<sys_trx_start from t where a=2;
|
select @tm<sys_trx_start from t where a=2;
|
||||||
@tm<sys_trx_start
|
@tm<sys_trx_start
|
||||||
1
|
1
|
||||||
select sys_trx_start from t where a=2 into @tm;
|
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
|
@tm=sys_trx_end
|
||||||
1
|
1
|
||||||
call drop_last_historical('t');
|
call drop_last_archive();
|
||||||
set versioning_alter_history= keep;
|
set versioning_alter_history= keep;
|
||||||
drop table t_vtmd;
|
drop table t_vtmd;
|
||||||
drop table t;
|
drop table t;
|
||||||
@ -169,8 +169,8 @@ insert into t values (1);
|
|||||||
update t set a=2 where a=1;
|
update t set a=2 where a=1;
|
||||||
alter table t add column b int, algorithm=inplace;
|
alter table t add column b int, algorithm=inplace;
|
||||||
set versioning_alter_history = keep;
|
set versioning_alter_history = keep;
|
||||||
drop function get_historical_table_name;
|
drop function get_archive_table_name;
|
||||||
drop procedure drop_last_historical;
|
drop procedure drop_last_archive;
|
||||||
select * from mysql.vtmd_template;
|
select * from mysql.vtmd_template;
|
||||||
start end name archive_name col_renames
|
start end name archive_name col_renames
|
||||||
show create table mysql.vtmd_template;
|
show create table mysql.vtmd_template;
|
||||||
|
@ -44,6 +44,12 @@ substr(archive_name, 1, instr(archive_name, '_')) as C_archive_name
|
|||||||
from tmp_vtmd for system_time all;
|
from tmp_vtmd for system_time all;
|
||||||
drop table tmp_vtmd;
|
drop table tmp_vtmd;
|
||||||
end~~
|
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;
|
set versioning_alter_history= keep;
|
||||||
create table t0 (z int) with system versioning;
|
create table t0 (z int) with system versioning;
|
||||||
show tables;
|
show tables;
|
||||||
@ -178,10 +184,6 @@ use db0;
|
|||||||
show tables;
|
show tables;
|
||||||
Tables_in_db0
|
Tables_in_db0
|
||||||
t0
|
t0
|
||||||
t0_TIMESTAMP_SUFFIX
|
|
||||||
t0_TIMESTAMP_SUFFIX
|
|
||||||
t0_TIMESTAMP_SUFFIX
|
|
||||||
t0_TIMESTAMP_SUFFIX
|
|
||||||
t0_vtmd
|
t0_vtmd
|
||||||
call test.check_vtmd('db0.t0_vtmd');
|
call test.check_vtmd('db0.t0_vtmd');
|
||||||
@start > 0 and @start < @inf
|
@start > 0 and @start < @inf
|
||||||
@ -206,10 +208,6 @@ show tables;
|
|||||||
Tables_in_db1
|
Tables_in_db1
|
||||||
other_name
|
other_name
|
||||||
other_name_vtmd
|
other_name_vtmd
|
||||||
t0_TIMESTAMP_SUFFIX
|
|
||||||
t0_TIMESTAMP_SUFFIX
|
|
||||||
t0_TIMESTAMP_SUFFIX
|
|
||||||
t0_TIMESTAMP_SUFFIX
|
|
||||||
call test.check_vtmd('db1.other_name_vtmd');
|
call test.check_vtmd('db1.other_name_vtmd');
|
||||||
@start > 0 and @start < @inf
|
@start > 0 and @start < @inf
|
||||||
1
|
1
|
||||||
@ -246,10 +244,6 @@ alter table t1 rename to test.t2, add column (y int);
|
|||||||
use test;
|
use test;
|
||||||
show tables;
|
show tables;
|
||||||
Tables_in_test
|
Tables_in_test
|
||||||
t0_TIMESTAMP_SUFFIX
|
|
||||||
t0_TIMESTAMP_SUFFIX
|
|
||||||
t0_TIMESTAMP_SUFFIX
|
|
||||||
t0_TIMESTAMP_SUFFIX
|
|
||||||
t2
|
t2
|
||||||
t2_vtmd
|
t2_vtmd
|
||||||
call check_vtmd('t2_vtmd');
|
call check_vtmd('t2_vtmd');
|
||||||
@ -279,6 +273,67 @@ A_start B_end name C_archive_name
|
|||||||
1 0 t3 t3_
|
1 0 t3 t3_
|
||||||
1 0 t3 t3_
|
1 0 t3 t3_
|
||||||
1 1 t3 NULL
|
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 db0;
|
||||||
drop database db1;
|
drop database db1;
|
||||||
drop database test;
|
drop database test;
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
-- source suite/versioning/common.inc
|
-- source suite/versioning/common.inc
|
||||||
|
|
||||||
delimiter ~~;
|
delimiter ~~;
|
||||||
create function get_historical_table_name(table_name_arg varchar(255))
|
create function get_archive_table_name()
|
||||||
returns varchar(255)
|
returns varchar(255)
|
||||||
begin
|
begin
|
||||||
return (select table_name from information_schema.tables
|
return (select archive_name from t_vtmd for system_time all where archive_name is not NULL
|
||||||
where table_schema='test' and table_name like concat(table_name_arg, '_%') limit 1);
|
order by start desc limit 1);
|
||||||
end~~
|
end~~
|
||||||
|
|
||||||
create procedure drop_last_historical(table_name_arg varchar(255))
|
create procedure drop_last_archive()
|
||||||
begin
|
begin
|
||||||
call concat_exec2('drop table ', get_historical_table_name(table_name_arg));
|
call concat_exec2('drop table ', get_archive_table_name());
|
||||||
end~~
|
end~~
|
||||||
delimiter ;~~
|
delimiter ;~~
|
||||||
|
|
||||||
@ -23,14 +23,14 @@ select sys_trx_start from t where a=2 into @tm;
|
|||||||
alter table t add column b int;
|
alter table t add column b int;
|
||||||
|
|
||||||
select * from t;
|
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 @tm<sys_trx_start from t where a=2;
|
||||||
select sys_trx_start from t where a=2 into @tm;
|
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;
|
set versioning_alter_history= keep;
|
||||||
@ -46,14 +46,14 @@ select sys_trx_start from t where a=2 into @tm;
|
|||||||
alter table t add column b int;
|
alter table t add column b int;
|
||||||
|
|
||||||
select * from t;
|
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 @tm<sys_trx_start from t where a=2;
|
||||||
select sys_trx_start from t where a=2 into @tm;
|
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;
|
set versioning_alter_history= keep;
|
||||||
@ -69,14 +69,14 @@ select sys_trx_start from t where a=2 into @tm;
|
|||||||
alter table t add column b int;
|
alter table t add column b int;
|
||||||
|
|
||||||
select * from t;
|
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 @tm<sys_trx_start from t where a=2;
|
||||||
select sys_trx_start from t where a=2 into @tm;
|
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;
|
set versioning_alter_history= keep;
|
||||||
@ -92,8 +92,8 @@ alter table t add column b int, algorithm=inplace;
|
|||||||
|
|
||||||
set versioning_alter_history = keep;
|
set versioning_alter_history = keep;
|
||||||
|
|
||||||
drop function get_historical_table_name;
|
drop function get_archive_table_name;
|
||||||
drop procedure drop_last_historical;
|
drop procedure drop_last_archive;
|
||||||
|
|
||||||
select * from mysql.vtmd_template;
|
select * from mysql.vtmd_template;
|
||||||
show create table mysql.vtmd_template;
|
show create table mysql.vtmd_template;
|
||||||
|
@ -56,6 +56,15 @@ begin
|
|||||||
end~~
|
end~~
|
||||||
delimiter ;~~
|
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
|
# create
|
||||||
set versioning_alter_history= keep;
|
set versioning_alter_history= keep;
|
||||||
create table t0 (z int) with system versioning;
|
create table t0 (z int) with system versioning;
|
||||||
@ -136,7 +145,6 @@ create database db0;
|
|||||||
rename table t0 to db0.t0;
|
rename table t0 to db0.t0;
|
||||||
show tables;
|
show tables;
|
||||||
use db0;
|
use db0;
|
||||||
--replace_regex /\d{8}_\d{6}_\d{6}/TIMESTAMP_SUFFIX/
|
|
||||||
show tables;
|
show tables;
|
||||||
call test.check_vtmd('db0.t0_vtmd');
|
call test.check_vtmd('db0.t0_vtmd');
|
||||||
|
|
||||||
@ -144,7 +152,6 @@ create database db1;
|
|||||||
rename table t0 to db1.other_name;
|
rename table t0 to db1.other_name;
|
||||||
show tables;
|
show tables;
|
||||||
use db1;
|
use db1;
|
||||||
--replace_regex /\d{8}_\d{6}_\d{6}/TIMESTAMP_SUFFIX/
|
|
||||||
show tables;
|
show tables;
|
||||||
call test.check_vtmd('db1.other_name_vtmd');
|
call test.check_vtmd('db1.other_name_vtmd');
|
||||||
|
|
||||||
@ -155,7 +162,6 @@ call test.check_vtmd('db1.t1_vtmd');
|
|||||||
# alter rename and modify to different schema
|
# alter rename and modify to different schema
|
||||||
alter table t1 rename to test.t2, add column (y int);
|
alter table t1 rename to test.t2, add column (y int);
|
||||||
use test;
|
use test;
|
||||||
--replace_regex /\d{8}_\d{6}_\d{6}/TIMESTAMP_SUFFIX/
|
|
||||||
show tables;
|
show tables;
|
||||||
call check_vtmd('t2_vtmd');
|
call check_vtmd('t2_vtmd');
|
||||||
|
|
||||||
@ -164,6 +170,19 @@ alter table t3 change x x bigint;
|
|||||||
alter table t3 change x x bigint after sys_trx_start;
|
alter table t3 change x x bigint after sys_trx_start;
|
||||||
call check_vtmd('t3_vtmd');
|
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 db0;
|
||||||
drop database db1;
|
drop database db1;
|
||||||
drop database test;
|
drop database test;
|
||||||
|
@ -4863,6 +4863,59 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static bool get_all_archive_tables(THD *thd,
|
||||||
|
Dynamic_array<String> &all_archive_tables)
|
||||||
|
{
|
||||||
|
if (thd->variables.vers_hide == VERS_HIDE_NEVER)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Dynamic_array<LEX_STRING *> all_db;
|
||||||
|
LOOKUP_FIELD_VALUES lookup_field_values= {
|
||||||
|
*thd->make_lex_string(C_STRING_WITH_LEN("%")), {NULL, 0}, true, false};
|
||||||
|
if (make_db_list(thd, &all_db, &lookup_field_values))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
LEX_STRING information_schema= {C_STRING_WITH_LEN("information_schema")};
|
||||||
|
for (size_t i= 0; i < all_db.elements(); i++)
|
||||||
|
{
|
||||||
|
LEX_STRING db= *all_db.at(i);
|
||||||
|
if (db.length == information_schema.length &&
|
||||||
|
!memcmp(db.str, information_schema.str, db.length))
|
||||||
|
{
|
||||||
|
all_db.del(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i= 0; i < all_db.elements(); i++)
|
||||||
|
{
|
||||||
|
LEX_STRING db_name= *all_db.at(i);
|
||||||
|
Dynamic_array<String> archive_tables;
|
||||||
|
if (VTMD_table::get_archive_tables(thd, db_name.str, db_name.length,
|
||||||
|
archive_tables))
|
||||||
|
return true;
|
||||||
|
for (size_t i= 0; i < archive_tables.elements(); i++)
|
||||||
|
if (all_archive_tables.push(archive_tables.at(i)))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_archive_table(const Dynamic_array<String> &all_archive_tables,
|
||||||
|
LEX_STRING candidate)
|
||||||
|
{
|
||||||
|
for (size_t i= 0; i < all_archive_tables.elements(); i++)
|
||||||
|
{
|
||||||
|
const String &archive_table= all_archive_tables.at(i);
|
||||||
|
if (candidate.length == archive_table.length() &&
|
||||||
|
!memcmp(candidate.str, archive_table.ptr(), candidate.length))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Fill I_S tables whose data are retrieved
|
@brief Fill I_S tables whose data are retrieved
|
||||||
@ -4905,6 +4958,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
|
|||||||
#endif
|
#endif
|
||||||
uint table_open_method= tables->table_open_method;
|
uint table_open_method= tables->table_open_method;
|
||||||
bool can_deadlock;
|
bool can_deadlock;
|
||||||
|
Dynamic_array<String> all_archive_tables;
|
||||||
DBUG_ENTER("get_all_tables");
|
DBUG_ENTER("get_all_tables");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -4967,6 +5021,10 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
|
|||||||
|
|
||||||
if (make_db_list(thd, &db_names, &plan->lookup_field_vals))
|
if (make_db_list(thd, &db_names, &plan->lookup_field_vals))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
if (get_all_archive_tables(thd, all_archive_tables))
|
||||||
|
goto err;
|
||||||
|
|
||||||
for (size_t i=0; i < db_names.elements(); i++)
|
for (size_t i=0; i < db_names.elements(); i++)
|
||||||
{
|
{
|
||||||
LEX_STRING *db_name= db_names.at(i);
|
LEX_STRING *db_name= db_names.at(i);
|
||||||
@ -4992,6 +5050,9 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
|
|||||||
LEX_STRING *table_name= table_names.at(i);
|
LEX_STRING *table_name= table_names.at(i);
|
||||||
DBUG_ASSERT(table_name->length <= NAME_LEN);
|
DBUG_ASSERT(table_name->length <= NAME_LEN);
|
||||||
|
|
||||||
|
if (is_archive_table(all_archive_tables, *table_name))
|
||||||
|
continue;
|
||||||
|
|
||||||
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
||||||
if (!(thd->col_access & TABLE_ACLS))
|
if (!(thd->col_access & TABLE_ACLS))
|
||||||
{
|
{
|
||||||
|
25
sql/vtmd.cc
25
sql/vtmd.cc
@ -569,24 +569,26 @@ err:
|
|||||||
|
|
||||||
static
|
static
|
||||||
bool
|
bool
|
||||||
get_vtmd_tables(THD *thd, Dynamic_array<LEX_STRING *> &table_names)
|
get_vtmd_tables(THD *thd, const char *db,
|
||||||
|
size_t db_length, Dynamic_array<LEX_STRING *> &table_names)
|
||||||
{
|
{
|
||||||
// Note function retrieves table names from current db only.
|
|
||||||
LOOKUP_FIELD_VALUES lookup_field_values= {
|
LOOKUP_FIELD_VALUES lookup_field_values= {
|
||||||
*thd->make_lex_string(thd->db, strlen(thd->db)),
|
*thd->make_lex_string(db, db_length),
|
||||||
*thd->make_lex_string(C_STRING_WITH_LEN("%_vtmd")), false, true};
|
*thd->make_lex_string(C_STRING_WITH_LEN("%_vtmd")), false, true};
|
||||||
|
|
||||||
int res= make_table_name_list(thd, &table_names, thd->lex, &lookup_field_values,
|
int res=
|
||||||
&lookup_field_values.db_value);
|
make_table_name_list(thd, &table_names, thd->lex, &lookup_field_values,
|
||||||
|
&lookup_field_values.db_value);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
VTMD_table::get_archive_tables(THD *thd, Dynamic_array<String> &result)
|
VTMD_table::get_archive_tables(THD *thd, const char *db, size_t db_length,
|
||||||
|
Dynamic_array<String> &result)
|
||||||
{
|
{
|
||||||
Dynamic_array<LEX_STRING *> vtmd_tables;
|
Dynamic_array<LEX_STRING *> vtmd_tables;
|
||||||
if (get_vtmd_tables(thd, vtmd_tables))
|
if (get_vtmd_tables(thd, db, db_length, vtmd_tables))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
for (uint i= 0; i < vtmd_tables.elements(); i++)
|
for (uint i= 0; i < vtmd_tables.elements(); i++)
|
||||||
@ -595,10 +597,8 @@ VTMD_table::get_archive_tables(THD *thd, Dynamic_array<String> &result)
|
|||||||
|
|
||||||
Open_tables_backup open_tables_backup;
|
Open_tables_backup open_tables_backup;
|
||||||
TABLE_LIST table_list;
|
TABLE_LIST table_list;
|
||||||
// Assume VTMD tables belongs to current db.
|
table_list.init_one_table(db, db_length, LEX_STRING_WITH_LEN(table_name),
|
||||||
table_list.init_one_table(thd->db, strlen(thd->db),
|
table_name.str, TL_READ);
|
||||||
LEX_STRING_WITH_LEN(table_name), table_name.str,
|
|
||||||
TL_READ);
|
|
||||||
|
|
||||||
TABLE *table= open_log_table(thd, &table_list, &open_tables_backup);
|
TABLE *table= open_log_table(thd, &table_list, &open_tables_backup);
|
||||||
if (!table)
|
if (!table)
|
||||||
@ -633,6 +633,9 @@ VTMD_table::get_archive_tables(THD *thd, Dynamic_array<String> &result)
|
|||||||
archive_name.length());
|
archive_name.length());
|
||||||
result.push(archive_name);
|
result.push(archive_name);
|
||||||
}
|
}
|
||||||
|
// check for EOF
|
||||||
|
if (!thd->is_error())
|
||||||
|
error= 0;
|
||||||
|
|
||||||
end_read_record(&read_record);
|
end_read_record(&read_record);
|
||||||
delete sql_select;
|
delete sql_select;
|
||||||
|
@ -92,7 +92,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool find_archive_name(THD *thd, String &out);
|
bool find_archive_name(THD *thd, String &out);
|
||||||
bool get_archive_tables(THD *thd, Dynamic_array<String> &result);
|
static bool get_archive_tables(THD *thd, const char *db, size_t db_length,
|
||||||
|
Dynamic_array<String> &result);
|
||||||
};
|
};
|
||||||
|
|
||||||
class VTMD_exists : public VTMD_table
|
class VTMD_exists : public VTMD_table
|
||||||
|
Reference in New Issue
Block a user