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; 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"; 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 ) select * from ancestors"; 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 = 'bill' for system_time as of timestamp @ts union select ee.emp_id, ee.name, ee.mgr from emp as ee, ancestors as a where ee.mgr = a.emp_id for system_time as of timestamp @ts ) select * from ancestors; set @tmp= " with recursive ancestors as ( select e.emp_id, e.name, e.mgr from emp as e where name = 'bill' for system_time as of timestamp @ts union select ee.emp_id, ee.name, ee.mgr from emp as ee, ancestors as a where ee.mgr = a.emp_id for system_time as of timestamp @ts ) select * from ancestors"; prepare stmt from @tmp; execute stmt; 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); --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; --echo # SYSTEM_TIME propagation from inner to outer select * from (select * from t1 for system_time as of timestamp @t0, t2) as s0; with s1 as (select * from t1 for system_time as of timestamp @t0, t2) select * from s1; --echo # leading table selection 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; --echo # 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; 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; 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; --echo ### 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; --echo # SYSTEM_TIME propagation from view select * from vt1; --echo # SYSTEM_TIME propagation from inner to outer select * from (select * from vt1, t2) as s0; --echo # leading table selection select * from (select *, vt1.sys_trx_end from t2, vt1) as s0; --echo ### SYSTEM_TIME clash --error ER_VERS_SYSTEM_TIME_CLASH select * from (select * from t1 for system_time all) dt0 for system_time all; --error ER_VERS_SYSTEM_TIME_CLASH select * from vt1 for system_time all; --error ER_VERS_SYSTEM_TIME_CLASH with dt1 as (select * from t1 for system_time all) select * from dt1 for system_time all; --echo ### UNION set @t1= now(6); delete from t2; insert into t2 values (3); --echo # SYSTEM_TIME is not propagated select x from t1 union select y from t2; select x from t1 for system_time as of @t0 union select y from t2; select x from t1 union select y from t2 for system_time as of @t1; select x from t1 for system_time as of @t0 union select y from t2 for system_time as of @t1; drop database test; create database test;