2017-02-09 12:01:05 +03:00
|
|
|
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;
|
|
|
|
set @tmp= "with ancestors as (select * from emp) select * from ancestors";
|
|
|
|
prepare stmt from @tmp; execute stmt; drop prepare stmt;
|
|
|
|
|
2017-04-28 12:07:04 +03:00
|
|
|
with ancestors as (select * from emp for system_time all) select * from ancestors;
|
|
|
|
set @tmp= "with ancestors as (select * from emp for system_time all) select * from ancestors";
|
2017-02-09 12:01:05 +03:00
|
|
|
prepare stmt from @tmp; execute stmt; drop prepare stmt;
|
|
|
|
|
|
|
|
with recursive ancestors as (select * from emp) select * from ancestors;
|
|
|
|
set @tmp= "with recursive ancestors as (select * from emp) select * from ancestors";
|
|
|
|
prepare stmt from @tmp; execute stmt; drop prepare stmt;
|
|
|
|
|
|
|
|
select emp_id from (select emp_id from emp where sys_trx_end>'2031-1-1') as tmp;
|
|
|
|
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; 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;
|
|
|
|
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
|
|
|
|
)
|
2017-04-28 12:07:04 +03:00
|
|
|
select * from ancestors";
|
2017-02-09 12:01:05 +03:00
|
|
|
prepare stmt from @tmp; execute stmt; drop prepare stmt;
|
|
|
|
|
|
|
|
with recursive
|
|
|
|
ancestors
|
|
|
|
as
|
|
|
|
(
|
|
|
|
select e.emp_id, e.name, e.mgr
|
|
|
|
from emp as e for system_time as of timestamp @ts
|
|
|
|
where name = 'bill'
|
|
|
|
union
|
|
|
|
select ee.emp_id, ee.name, ee.mgr
|
|
|
|
from emp as ee for system_time as of timestamp @ts, ancestors as a for system_time as of timestamp @ts
|
|
|
|
where ee.mgr = a.emp_id
|
|
|
|
)
|
2017-04-28 12:07:04 +03:00
|
|
|
select * from ancestors;
|
2017-02-09 12:01:05 +03:00
|
|
|
set @tmp= "
|
|
|
|
with recursive
|
|
|
|
ancestors
|
|
|
|
as
|
|
|
|
(
|
|
|
|
select e.emp_id, e.name, e.mgr
|
|
|
|
from emp as e for system_time as of timestamp @ts
|
|
|
|
where name = 'bill'
|
|
|
|
union
|
|
|
|
select ee.emp_id, ee.name, ee.mgr
|
|
|
|
from emp as ee for system_time as of timestamp @ts, ancestors as a for system_time as of timestamp @ts
|
|
|
|
where ee.mgr = a.emp_id
|
|
|
|
)
|
2017-04-28 12:07:04 +03:00
|
|
|
select * from ancestors";
|
2017-02-09 12:01:05 +03:00
|
|
|
prepare stmt from @tmp; execute stmt; drop prepare stmt;
|
|
|
|
|
|
|
|
drop table emp;
|
2017-04-28 12:07:04 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
insert into t1 values (2);
|
|
|
|
delete from t1 where x = 1;
|
|
|
|
insert into t2 values (10);
|
|
|
|
|
|
|
|
--error ER_VERS_DERIVED_PROHIBITED
|
|
|
|
select * from (select *, t1.sys_trx_end, t1.sys_trx_end as endo from t1) as s0;
|
|
|
|
--error ER_VERS_DERIVED_PROHIBITED
|
|
|
|
select * from (select *, t1.sys_trx_end, t2.sys_trx_start from t1, t2) as s0;
|
|
|
|
|
|
|
|
# system_time propagation from inner to outer
|
|
|
|
select * from (select * from t1 for system_time as of timestamp @t0, t2) as s0;
|
2017-07-12 10:36:02 +03:00
|
|
|
with s1 as (select * from t1 for system_time as of timestamp @t0, t2) select * from s1;
|
2017-04-28 12:07:04 +03:00
|
|
|
# leading table selection
|
2017-07-12 10:36:02 +03:00
|
|
|
select * from (select *, t1.sys_trx_end from t2, t1 for system_time as of timestamp @t0) as s2;
|
|
|
|
with s3 as (select *, t1.sys_trx_end from t2, t1 for system_time as of timestamp @t0) select * from s3;
|
2017-04-28 12:07:04 +03:00
|
|
|
# system_time propagation from outer to inner
|
2017-07-12 11:24:03 +03:00
|
|
|
select * from (select *, t1.sys_trx_start from t2 for system_time as of now, t1) as s4 system_time as of timestamp @t0;
|
2017-07-12 10:36:02 +03:00
|
|
|
with s5 as (select *, t1.sys_trx_start from t2 for system_time as of now, t1) select * from s5 for system_time as of timestamp @t0;
|
2017-07-12 11:24:03 +03:00
|
|
|
with s6 as (select *, t1.sys_trx_start from t2 for system_time as of now, t1) select * from s6 system_time as of timestamp @t0;
|
2017-04-28 12:07:04 +03:00
|
|
|
|
|
|
|
# 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;
|
|
|
|
|
|
|
|
# system_time propagation from view
|
|
|
|
select * from vt1;
|
|
|
|
# system_time propagation from inner to outer
|
|
|
|
select * from (select * from vt1, t2) as s0;
|
|
|
|
# leading table selection
|
|
|
|
select * from (select *, vt1.sys_trx_end from t2, vt1) as s0;
|
|
|
|
# system_time propagation from outer to inner
|
2017-07-12 11:24:03 +03:00
|
|
|
select * from (select *, vt1.sys_trx_start from t2 for system_time as of now, vt1) as s0 system_time as of timestamp @t0;
|
2017-04-28 12:07:04 +03:00
|
|
|
|
|
|
|
drop table t1, t2;
|
|
|
|
drop view vt1;
|