1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

SQL: inner/outer system_time consistency [fixes #384]

This commit is contained in:
Aleksey Midenkov
2017-12-14 13:43:37 +03:00
parent eab471260b
commit 2e3b580ba4
6 changed files with 77 additions and 45 deletions

View File

@ -96,9 +96,10 @@ 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
from emp
for system_time as of timestamp @ts as ee,
ancestors as a
where ee.mgr = a.emp_id
for system_time as of timestamp @ts
)
select * from ancestors;
emp_id name mgr
@ -116,9 +117,9 @@ as
for system_time as of timestamp @ts
union
select ee.emp_id, ee.name, ee.mgr
from emp as ee, ancestors as a
from emp for system_time as of timestamp @ts 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;
@ -154,16 +155,6 @@ y x
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
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;
@ -216,6 +207,18 @@ create or replace table t1 (x int, y int) with system versioning;
create or replace table t2 (x int, y int) with system versioning;
insert into t1 values (1, 1), (1, 2), (1, 3), (4, 4), (5, 5);
insert into t2 values (1, 2), (2, 1), (3, 1);
## Outer or inner SYSTEM_TIME produces same expression
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join)
Query A:
Note 1003 select `test`.`t1`.`x` AS `x`,`test`.`t1`.`y` AS `y1`,`test`.`t2`.`x` AS `x2`,`test`.`t2`.`y` AS `y2` from `test`.`t1` FOR SYSTEM_TIME ALL join `test`.`t2` FOR SYSTEM_TIME ALL where `test`.`t1`.`x` = `test`.`t2`.`x` and `test`.`t1`.`sys_trx_end` > <cache>(current_timestamp(6)) and `test`.`t1`.`sys_trx_start` <= <cache>(current_timestamp(6)) and `test`.`t2`.`sys_trx_end` > <cache>(current_timestamp(6)) and `test`.`t2`.`sys_trx_start` <= <cache>(current_timestamp(6))
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join)
Query B:
Note 1003 select `test`.`t1`.`x` AS `x`,`test`.`t1`.`y` AS `y1`,`test`.`t2`.`x` AS `x2`,`test`.`t2`.`y` AS `y2` from `test`.`t1` FOR SYSTEM_TIME ALL join `test`.`t2` FOR SYSTEM_TIME ALL where `test`.`t1`.`x` = `test`.`t2`.`x` and `test`.`t1`.`sys_trx_end` > <cache>(current_timestamp(6)) and `test`.`t1`.`sys_trx_start` <= <cache>(current_timestamp(6)) and `test`.`t2`.`sys_trx_end` > <cache>(current_timestamp(6)) and `test`.`t2`.`sys_trx_start` <= <cache>(current_timestamp(6))
Fine result: queries A and B are equal.
## LEFT JOIN: t1, t2 versioned
select * from (
select t1.x as LJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2