mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 04:53:01 +01:00
217 lines
7.4 KiB
Text
217 lines
7.4 KiB
Text
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 or replace table t1 (x int) with system versioning;
|
|
insert into t1 values (1);
|
|
select now(6) into @t1;
|
|
update t1 set x= 2;
|
|
select now(6) into @t2;
|
|
delete from t1;
|
|
set @vt1= concat("create or replace view vt1 as select * from t1 for system_time as of timestamp '", @t1, "'");
|
|
prepare stmt from @vt1;
|
|
execute stmt;
|
|
drop prepare stmt;
|
|
set @vt2= concat("create or replace view vt2 as select *, sys_trx_end from t1 for system_time as of timestamp '", @t2, "'");
|
|
prepare stmt from @vt2;
|
|
execute stmt;
|
|
drop prepare stmt;
|
|
select * from vt1 for system_time all;
|
|
x
|
|
1
|
|
select * from vt2 for system_time all;
|
|
x
|
|
2
|
|
select * from t1;
|
|
x
|
|
create or replace view vt1 as select * from t1;
|
|
show create view vt1;
|
|
View Create View character_set_client collation_connection
|
|
vt1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vt1` AS select `t1`.`x` AS `x`,`t1`.`sys_trx_start` AS `sys_trx_start`,`t1`.`sys_trx_end` AS `sys_trx_end` from `t1` FOR SYSTEM_TIME ALL where `t1`.`sys_trx_end` = MAX_RESULT latin1 latin1_swedish_ci
|
|
drop view vt1;
|
|
drop view vt2;
|
|
create view vt1 as select * from t1 for system_time all;
|
|
select * from vt1 for system_time all;
|
|
x
|
|
2
|
|
1
|
|
prepare stmt from 'select * from vt1 for system_time all';
|
|
execute stmt;
|
|
x
|
|
2
|
|
1
|
|
drop prepare stmt;
|
|
select * from vt1;
|
|
x
|
|
2
|
|
1
|
|
prepare stmt from 'select * from vt1';
|
|
execute stmt;
|
|
x
|
|
2
|
|
1
|
|
drop prepare stmt;
|
|
select * from t1 for system_time as of timestamp @t1;
|
|
x
|
|
1
|
|
select * from vt1 for system_time as of timestamp @t1;
|
|
x
|
|
1
|
|
prepare stmt from 'select * from vt1 for system_time as of timestamp @t1';
|
|
execute stmt;
|
|
x
|
|
1
|
|
drop prepare stmt;
|
|
create or replace view vt1 as select * from t1;
|
|
select * from vt1 for system_time all;
|
|
x
|
|
prepare stmt from 'select * from vt1 for system_time all';
|
|
execute stmt;
|
|
x
|
|
drop prepare stmt;
|
|
insert into vt1 values (3);
|
|
select * from t1;
|
|
x
|
|
3
|
|
select * from vt1;
|
|
x
|
|
3
|
|
select * from t1 for system_time all;
|
|
x
|
|
2
|
|
1
|
|
3
|
|
select * from vt1 for system_time all;
|
|
x
|
|
3
|
|
create or replace table t1 (x int) with system versioning;
|
|
insert into t1 values (1), (2);
|
|
set @t1=now(6);
|
|
delete from t1 where x=2;
|
|
set @t2=now(6);
|
|
delete from t1 where x=1;
|
|
set @t3=now(6);
|
|
set @tmp= concat("create or replace view vt1 as select * from t1 for system_time as of timestamp '", @t1, "'");
|
|
prepare stmt from @tmp;
|
|
execute stmt;
|
|
drop prepare stmt;
|
|
select * from vt1 for system_time all;
|
|
x
|
|
1
|
|
2
|
|
# VIEW with parameters [#151]
|
|
create or replace table t1 (x int) with system versioning;
|
|
create or replace view vt1(c) as select x from t1;
|
|
show create view vt1;
|
|
View Create View character_set_client collation_connection
|
|
vt1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vt1` AS select `t1`.`x` AS `c`,`t1`.`sys_trx_start` AS `sys_trx_start`,`t1`.`sys_trx_end` AS `sys_trx_end` from `t1` FOR SYSTEM_TIME ALL where `t1`.`sys_trx_end` = MAX_RESULT latin1 latin1_swedish_ci
|
|
# VIEW over JOIN of versioned tables [#153]
|
|
create or replace table t1 (a int) with system versioning;
|
|
create or replace table t2 (b int) with system versioning;
|
|
insert into t1 values (1);
|
|
insert into t2 values (2);
|
|
create or replace view vt12 as select * from t1 cross join t2;
|
|
select * from vt12;
|
|
a b
|
|
1 2
|
|
create or replace view vt12 as select * from t1 for system_time as of timestamp '0-0-0' cross join t2;
|
|
select * from vt12;
|
|
a b
|
|
# VIEW improvements [#183]
|
|
create or replace view vt1 as select a, t1.sys_trx_start, t2.sys_trx_end from t1, t2;
|
|
ERROR HY000: Creating VIEW `vt1` is prohibited: system fields from multiple tables `t1`, `t2` in query!
|
|
create or replace view vt1 as select a, t1.sys_trx_end, t2.sys_trx_end from t1, t2;
|
|
ERROR HY000: Creating VIEW `vt1` is prohibited: multiple end system fields `t1.sys_trx_end`, `t2.sys_trx_end` in query!
|
|
create or replace table t3 (x int);
|
|
create or replace view vt1 as select * from t1, t2, t3;
|
|
show create view vt1;
|
|
View Create View character_set_client collation_connection
|
|
vt1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vt1` AS select `t1`.`a` AS `a`,`t2`.`b` AS `b`,`t3`.`x` AS `x`,`t1`.`sys_trx_start` AS `sys_trx_start`,`t1`.`sys_trx_end` AS `sys_trx_end` from ((`t1` FOR SYSTEM_TIME ALL join `t2` FOR SYSTEM_TIME ALL) join `t3`) where `t1`.`sys_trx_end` = MAX_RESULT and `t2`.`sys_trx_end` = MAX_RESULT latin1 latin1_swedish_ci
|
|
create or replace view vt1 as select * from t3, t2, t1;
|
|
show create view vt1;
|
|
View Create View character_set_client collation_connection
|
|
vt1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vt1` AS select `t3`.`x` AS `x`,`t2`.`b` AS `b`,`t1`.`a` AS `a`,`t2`.`sys_trx_start` AS `sys_trx_start`,`t2`.`sys_trx_end` AS `sys_trx_end` from ((`t3` join `t2` FOR SYSTEM_TIME ALL) join `t1` FOR SYSTEM_TIME ALL) where `t2`.`sys_trx_end` = MAX_RESULT and `t1`.`sys_trx_end` = MAX_RESULT latin1 latin1_swedish_ci
|
|
create or replace view vt1 as select a, t2.sys_trx_end as endo from t3, t1, t2;
|
|
show create view vt1;
|
|
View Create View character_set_client collation_connection
|
|
vt1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vt1` AS select `t1`.`a` AS `a`,`t2`.`sys_trx_end` AS `endo`,`t2`.`sys_trx_start` AS `sys_trx_start` from ((`t3` join `t1` FOR SYSTEM_TIME ALL) join `t2` FOR SYSTEM_TIME ALL) where `t1`.`sys_trx_end` = MAX_RESULT and `t2`.`sys_trx_end` = MAX_RESULT latin1 latin1_swedish_ci
|
|
# VIEW over UNION [#269]
|
|
create or replace view vt1 as select * from t1 union select * from t1;
|
|
select * from vt1;
|
|
a
|
|
1
|
|
create or replace view vvt1 as select * from t1, t2, vt1;
|
|
ERROR HY000: Creating VIEW `vvt1` is prohibited: versioned VIEW `vt1` in query!
|
|
drop database test;
|
|
create database test;
|