mirror of
https://github.com/MariaDB/server.git
synced 2025-01-31 11:01:52 +01:00
ca6454bcfe
non-standard, redundant, potentially risky in the future, hides bugs. See #383, #384, #385 Fixed a parser bug where SELECT * FROM (t1 join t2) FOR SYSTEM_TIME ... was not an error.
213 lines
5.4 KiB
Text
213 lines
5.4 KiB
Text
create table emp
|
|
(
|
|
emp_id int,
|
|
name varchar(127),
|
|
mgr int
|
|
) with system versioning;
|
|
insert into emp values (1, 'bill', 0),
|
|
(2, 'bill', 1),
|
|
(3, 'kate', 1);
|
|
set @ts=now(6);
|
|
delete from emp;
|
|
insert into emp values (4, 'john', 1);
|
|
with ancestors as (select * from emp) select * from ancestors;
|
|
emp_id name mgr
|
|
4 john 1
|
|
set @tmp= "with ancestors as (select * from emp) select * from ancestors";
|
|
prepare stmt from @tmp;
|
|
execute stmt;
|
|
emp_id name mgr
|
|
4 john 1
|
|
drop prepare stmt;
|
|
with ancestors as (select * from emp for system_time all) select * from ancestors;
|
|
emp_id name mgr
|
|
1 bill 0
|
|
2 bill 1
|
|
3 kate 1
|
|
4 john 1
|
|
set @tmp= "with ancestors as (select * from emp for system_time all) select * from ancestors";
|
|
prepare stmt from @tmp;
|
|
execute stmt;
|
|
emp_id name mgr
|
|
1 bill 0
|
|
2 bill 1
|
|
3 kate 1
|
|
4 john 1
|
|
drop prepare stmt;
|
|
with recursive ancestors as (select * from emp) select * from ancestors;
|
|
emp_id name mgr
|
|
4 john 1
|
|
set @tmp= "with recursive ancestors as (select * from emp) select * from ancestors";
|
|
prepare stmt from @tmp;
|
|
execute stmt;
|
|
emp_id name mgr
|
|
4 john 1
|
|
drop prepare stmt;
|
|
select emp_id from (select emp_id from emp where sys_trx_end>'2031-1-1') as tmp;
|
|
emp_id
|
|
4
|
|
set @tmp= "select emp_id from (select emp_id from emp where sys_trx_end>'2031-1-1') as tmp";
|
|
prepare stmt from @tmp;
|
|
execute stmt;
|
|
emp_id
|
|
4
|
|
drop prepare stmt;
|
|
with recursive
|
|
ancestors
|
|
as
|
|
(
|
|
select e.emp_id, e.name, e.mgr
|
|
from emp as e
|
|
where name = 'john'
|
|
union
|
|
select ee.emp_id, ee.name, ee.mgr
|
|
from emp as ee, ancestors as a
|
|
where ee.mgr = a.emp_id
|
|
)
|
|
select * from ancestors;
|
|
emp_id name mgr
|
|
4 john 1
|
|
set @tmp= "
|
|
with recursive
|
|
ancestors
|
|
as
|
|
(
|
|
select e.emp_id, e.name, e.mgr
|
|
from emp as e
|
|
where name = 'john'
|
|
union
|
|
select ee.emp_id, ee.name, ee.mgr
|
|
from emp as ee, ancestors as a
|
|
where ee.mgr = a.emp_id
|
|
)
|
|
select * from ancestors";
|
|
prepare stmt from @tmp;
|
|
execute stmt;
|
|
emp_id name mgr
|
|
4 john 1
|
|
drop prepare stmt;
|
|
with recursive
|
|
ancestors
|
|
as
|
|
(
|
|
select e.emp_id, e.name, e.mgr
|
|
from emp for system_time as of timestamp @ts as e
|
|
where name = 'bill'
|
|
union
|
|
select ee.emp_id, ee.name, ee.mgr
|
|
from emp for system_time as of timestamp @ts as ee, ancestors as a
|
|
where ee.mgr = a.emp_id
|
|
)
|
|
select * from ancestors;
|
|
emp_id name mgr
|
|
1 bill 0
|
|
2 bill 1
|
|
set @tmp= "
|
|
with recursive
|
|
ancestors
|
|
as
|
|
(
|
|
select e.emp_id, e.name, e.mgr
|
|
from emp for system_time as of timestamp @ts as e
|
|
where name = 'bill'
|
|
union
|
|
select ee.emp_id, ee.name, ee.mgr
|
|
from emp for system_time as of timestamp @ts as ee, ancestors as a
|
|
where ee.mgr = a.emp_id
|
|
)
|
|
select * from ancestors";
|
|
prepare stmt from @tmp;
|
|
execute stmt;
|
|
emp_id name mgr
|
|
1 bill 0
|
|
2 bill 1
|
|
drop prepare stmt;
|
|
drop table emp;
|
|
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);
|
|
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) for system_time as of timestamp @t0 as s4;
|
|
y x
|
|
10 1
|
|
with s5 as (select *, t1.sys_trx_start from t2 for system_time as of current_timestamp, t1) select * from s5 for system_time as of timestamp @t0;
|
|
y x
|
|
10 1
|
|
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
|
|
### SYSTEM_TIME clash
|
|
select * from (select * from t1 for system_time all) for system_time all as dt0;
|
|
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;
|