mirror of
https://github.com/MariaDB/server.git
synced 2025-11-30 05:23:50 +03:00
SQL: derived SYSTEM_TIME clash detection [closes #371]
This commit is contained in:
@@ -42,7 +42,26 @@ from emp for system_time as of timestamp @ts_1 as e,
|
||||
ancestors as a
|
||||
where e.mgr = a.emp_id
|
||||
)
|
||||
select * from ancestors for system_time as of current_timestamp;
|
||||
select * from ancestors;
|
||||
emp_id name mgr salary
|
||||
1 bill NULL 1000
|
||||
20 john 1 500
|
||||
30 jane 1 750
|
||||
with recursive
|
||||
ancestors
|
||||
as
|
||||
(
|
||||
select e.emp_id, e.name, e.mgr, e.salary
|
||||
from emp as e
|
||||
where name = 'bill'
|
||||
union
|
||||
select e.emp_id, e.name, e.mgr, e.salary
|
||||
from emp as e,
|
||||
ancestors as a
|
||||
where e.mgr = a.emp_id
|
||||
)
|
||||
select * from ancestors
|
||||
for system_time as of timestamp @ts_1;
|
||||
emp_id name mgr salary
|
||||
1 bill NULL 1000
|
||||
30 jane 1 750
|
||||
|
||||
@@ -133,25 +133,28 @@ create or replace table t1 (x int) with system versioning;
|
||||
create or replace table t2 (y int) with system versioning;
|
||||
insert into t1 values (1);
|
||||
set @t0= now(6);
|
||||
delete from t1;
|
||||
insert into t1 values (2);
|
||||
delete from t1 where x = 1;
|
||||
insert into t2 values (10);
|
||||
select * from (select *, t1.sys_trx_end, t1.sys_trx_end as endo from t1) as s0;
|
||||
ERROR HY000: Derived table is prohibited: multiple end system fields `t1.sys_trx_end`, `t1.sys_trx_end` in query!
|
||||
select * from (select *, t1.sys_trx_end, t2.sys_trx_start from t1, t2) as s0;
|
||||
ERROR HY000: Derived table is prohibited: system fields from multiple tables `t1`, `t2` in query!
|
||||
# SYSTEM_TIME propagation from inner to outer
|
||||
select * from (select * from t1 for system_time as of timestamp @t0, t2) as s0;
|
||||
x y
|
||||
1 10
|
||||
with s1 as (select * from t1 for system_time as of timestamp @t0, t2) select * from s1;
|
||||
x y
|
||||
1 10
|
||||
# leading table selection
|
||||
select * from (select *, t1.sys_trx_end from t2, t1 for system_time as of timestamp @t0) as s2;
|
||||
y x
|
||||
10 1
|
||||
with s3 as (select *, t1.sys_trx_end from t2, t1 for system_time as of timestamp @t0) select * from s3;
|
||||
y x
|
||||
10 1
|
||||
# SYSTEM_TIME propagation from outer to inner
|
||||
select * from (select *, t1.sys_trx_start from t2 for system_time as of current_timestamp, t1) as s4 for system_time as of timestamp @t0;
|
||||
y x
|
||||
10 1
|
||||
@@ -161,21 +164,56 @@ y x
|
||||
with s6 as (select *, t1.sys_trx_start from t2 for system_time as of current_timestamp, t1) select * from s6 for system_time as of timestamp @t0;
|
||||
y x
|
||||
10 1
|
||||
### VIEW instead of t1
|
||||
set @q= concat("create view vt1 as select * from t1 for system_time as of timestamp '", @t0, "'");
|
||||
prepare q from @q;
|
||||
execute q;
|
||||
drop prepare q;
|
||||
create view vt2 as select * from t1;
|
||||
# SYSTEM_TIME propagation from view
|
||||
select * from vt1;
|
||||
x
|
||||
1
|
||||
# SYSTEM_TIME propagation from inner to outer
|
||||
select * from (select * from vt1, t2) as s0;
|
||||
x y
|
||||
1 10
|
||||
# leading table selection
|
||||
select * from (select *, vt1.sys_trx_end from t2, vt1) as s0;
|
||||
y x
|
||||
10 1
|
||||
select * from (select *, vt1.sys_trx_start from t2 for system_time as of current_timestamp, vt1) as s0 for system_time as of timestamp @t0;
|
||||
y x
|
||||
10 1
|
||||
drop table t1, t2;
|
||||
drop view vt1;
|
||||
### SYSTEM_TIME clash
|
||||
select * from (select * from t1 for system_time all) dt0 for system_time all;
|
||||
ERROR HY000: SYSTEM_TIME is not allowed outside historical `dt0`
|
||||
select * from vt1 for system_time all;
|
||||
ERROR HY000: SYSTEM_TIME is not allowed outside historical `vt1`
|
||||
with dt1 as (select * from t1 for system_time all)
|
||||
select * from dt1 for system_time all;
|
||||
ERROR HY000: SYSTEM_TIME is not allowed outside historical `dt1`
|
||||
### UNION
|
||||
set @t1= now(6);
|
||||
delete from t2;
|
||||
insert into t2 values (3);
|
||||
# SYSTEM_TIME is not propagated
|
||||
select x from t1 union
|
||||
select y from t2;
|
||||
x
|
||||
2
|
||||
3
|
||||
select x from t1 for system_time as of @t0 union
|
||||
select y from t2;
|
||||
x
|
||||
1
|
||||
3
|
||||
select x from t1 union
|
||||
select y from t2 for system_time as of @t1;
|
||||
x
|
||||
2
|
||||
10
|
||||
select x from t1 for system_time as of @t0 union
|
||||
select y from t2 for system_time as of @t1;
|
||||
x
|
||||
1
|
||||
10
|
||||
drop database test;
|
||||
create database test;
|
||||
|
||||
@@ -12,12 +12,6 @@ set @vt2= concat("create or replace view vt2 as select *, sys_trx_end from t1 fo
|
||||
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;
|
||||
@@ -26,17 +20,7 @@ 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;
|
||||
create or replace view vt1 as select * from t1 for system_time all;
|
||||
select * from vt1;
|
||||
x
|
||||
2
|
||||
@@ -47,39 +31,24 @@ x
|
||||
2
|
||||
1
|
||||
drop prepare stmt;
|
||||
set @str= concat('create or replace view vt1 as
|
||||
select * from t1 for system_time as of timestamp "', @t1, '"');
|
||||
prepare stmt from @str;
|
||||
execute stmt;
|
||||
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;
|
||||
select * from vt1;
|
||||
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);
|
||||
@@ -91,7 +60,7 @@ set @tmp= concat("create or replace view vt1 as select * from t1 for system_time
|
||||
prepare stmt from @tmp;
|
||||
execute stmt;
|
||||
drop prepare stmt;
|
||||
select * from vt1 for system_time all;
|
||||
select * from vt1;
|
||||
x
|
||||
1
|
||||
2
|
||||
|
||||
Reference in New Issue
Block a user