mariadb/mysql-test/suite/versioning/r/derived_tables.result

129 lines
2.8 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 for system_time all;
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 for system_time all";
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 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
)
select * from ancestors for system_time as of timestamp @ts;
emp_id name mgr
1 bill 0
2 bill 1
3 kate 1
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
)
select * from ancestors for system_time as of timestamp @ts;
";
prepare stmt from @tmp;
execute stmt;
emp_id name mgr
1 bill 0
2 bill 1
3 kate 1
drop prepare stmt;
drop table emp;