Skip to content

Commit

Permalink
for now, remove FOR SYSTEM_TIME at the end of the query
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vuvova committed Dec 13, 2017
1 parent a1141e2 commit ca6454b
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 156 deletions.
4 changes: 2 additions & 2 deletions mysql-test/suite/versioning/r/cte.result
Expand Up @@ -102,13 +102,13 @@ emp_id name mgr address
2 bill 1 New York
3 kate 1 London
4 john 1 Paris
with ancestors as (select * from emp natural join addr where 1 for system_time all) select * from ancestors;
with ancestors as (select * from (select * from emp natural join addr) for system_time all as t) select * from ancestors;
emp_id name mgr address
1 bill 0 Moscow
2 bill 1 New York
3 kate 1 London
4 john 1 Paris
select * from emp natural join addr where 1 for system_time all;
select * from (select * from emp natural join addr) for system_time all as t;
emp_id name mgr address
1 bill 0 Moscow
2 bill 1 New York
Expand Down
20 changes: 7 additions & 13 deletions mysql-test/suite/versioning/r/derived.result
Expand Up @@ -91,42 +91,36 @@ ancestors
as
(
select e.emp_id, e.name, e.mgr
from emp as e
from emp for system_time as of timestamp @ts as e
where name = 'bill'
for system_time as of timestamp @ts
union
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
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
from emp for system_time as of timestamp @ts 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
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;
execute stmt;
emp_id name mgr
1 bill 0
2 bill 1
3 kate 1
drop prepare stmt;
drop table emp;
create or replace table t1 (x int) with system versioning;
Expand Down Expand Up @@ -155,7 +149,7 @@ with s3 as (select *, t1.sys_trx_end from t2, t1 for system_time as of timestamp
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;
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;
Expand Down Expand Up @@ -183,7 +177,7 @@ 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) dt0 for system_time all;
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`
Expand Down
39 changes: 6 additions & 33 deletions mysql-test/suite/versioning/r/optimized.result
Expand Up @@ -25,7 +25,7 @@ a b
3 NULL
Warnings:
Warning 4112 Attempt to read unversioned field `b` in historical query
select count(*) from t group by b for system_time as of timestamp now(6);
select count(*) from t for system_time as of timestamp now(6) group by b;
count(*)
2
Warnings:
Expand All @@ -44,41 +44,10 @@ a b
Warnings:
Warning 4112 Attempt to read unversioned field `b` in historical query
Warning 4112 Attempt to read unversioned field `b` in historical query
select * from t group by a having a=2 for system_time as of timestamp now(6);
a b
Warnings:
Warning 4112 Attempt to read unversioned field `b` in historical query
select * from t group by b having b=2 for system_time as of timestamp now(6);
select * from t for system_time as of timestamp now(6) group by a having a=2;
a b
Warnings:
Warning 4112 Attempt to read unversioned field `b` in historical query
select a from t where b=2 for system_time as of timestamp now(6);
a
Warnings:
Warning 4112 Attempt to read unversioned field `b` in historical query
select a from t where b=NULL for system_time as of timestamp now(6);
a
Warnings:
Warning 4112 Attempt to read unversioned field `b` in historical query
select a from t where b is NULL for system_time as of timestamp now(6);
a
1
3
Warnings:
Warning 4112 Attempt to read unversioned field `b` in historical query
select count(*), b from t group by b having b=NULL for system_time as of timestamp now(6);
count(*) b
Warnings:
Warning 4112 Attempt to read unversioned field `b` in historical query
select a, b from t;
a b
1 2
3 4
select count(*) from t for system_time as of timestamp now(6) group by b;
count(*)
2
Warnings:
Warning 4112 Attempt to read unversioned field `b` in historical query
select * from t for system_time as of timestamp now(6) group by b having b=2;
a b
Warnings:
Expand All @@ -101,6 +70,10 @@ select count(*), b from t for system_time as of timestamp now(6) group by b havi
count(*) b
Warnings:
Warning 4112 Attempt to read unversioned field `b` in historical query
select a, b from t;
a b
1 2
3 4
create or replace table t (
a int,
b int not null without system versioning
Expand Down
40 changes: 30 additions & 10 deletions mysql-test/suite/versioning/r/select.result
Expand Up @@ -144,28 +144,47 @@ NULL NULL 2 1
NULL NULL 3 1
delete from t1;
delete from t2;
select t1.x as IJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x
for system_time as of timestamp @t0;
explain extended select * from (select t1.x as IJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
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)
Warnings:
Note 1003 select `test`.`t1`.`x` AS `IJ2_x1`,`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` > @`t0` and `test`.`t1`.`sys_trx_start` <= @`t0` and `test`.`t1`.`sys_trx_end` > @`t0` and `test`.`t1`.`sys_trx_start` <= @`t0` and `test`.`t2`.`sys_trx_end` > @`t0` and `test`.`t2`.`sys_trx_start` <= @`t0`
explain extended select * from (select t1.x as LJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`x` AS `LJ2_x1`,`test`.`t1`.`y` AS `y1`,`test`.`t2`.`x` AS `x2`,`test`.`t2`.`y` AS `y2` from `test`.`t1` FOR SYSTEM_TIME ALL left join `test`.`t2` FOR SYSTEM_TIME ALL on(`test`.`t2`.`x` = `test`.`t1`.`x` and `test`.`t2`.`sys_trx_end` > @`t0` and `test`.`t2`.`sys_trx_start` <= @`t0`) where `test`.`t1`.`sys_trx_end` > @`t0` and `test`.`t1`.`sys_trx_start` <= @`t0` and `test`.`t1`.`sys_trx_end` > @`t0` and `test`.`t1`.`sys_trx_start` <= @`t0`
explain extended select * from (select t1.x as RJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
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)
Warnings:
Note 1003 select `test`.`t1`.`x` AS `RJ2_x1`,`test`.`t1`.`y` AS `y1`,`test`.`t2`.`x` AS `x2`,`test`.`t2`.`y` AS `y2` from `test`.`t2` FOR SYSTEM_TIME ALL join `test`.`t1` FOR SYSTEM_TIME ALL where `test`.`t1`.`x` = `test`.`t2`.`x` and `test`.`t1`.`sys_trx_end` > @`t0` and `test`.`t1`.`sys_trx_start` <= @`t0` and `test`.`t1`.`sys_trx_end` > @`t0` and `test`.`t1`.`sys_trx_start` <= @`t0` and `test`.`t2`.`sys_trx_end` > @`t0` and `test`.`t2`.`sys_trx_start` <= @`t0`
select * from (select t1.x as IJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
IJ2_x1 y1 x2 y2
1 1 1 2
1 2 1 2
1 3 1 2
select t1.x as LJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x
for system_time as of timestamp @t0;
select * from (select t1.x as LJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
LJ2_x1 y1 x2 y2
1 1 1 2
1 2 1 2
1 3 1 2
4 4 NULL NULL
5 5 NULL NULL
select t1.x as RJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x
for system_time as of timestamp @t0;
select * from (select t1.x as RJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
RJ2_x1 y1 x2 y2
1 1 1 2
1 2 1 2
1 3 1 2
NULL NULL 2 1
NULL NULL 3 1
drop table t1;
drop table t2;
create table t1(
Expand Down Expand Up @@ -280,8 +299,9 @@ select * from t1, t2 for system_time all;
x y
1 1
2 1
select * from t1 for system_time all, t2 for system_time all for system_time all;
ERROR HY000: Unused clause: 'SYSTEM_TIME'
select * from (select * from t1 for system_time all, t2 for system_time all)
for system_time all as t;
ERROR HY000: SYSTEM_TIME is not allowed outside historical `t`
### Issue #365, bug 4 (related to #226, optimized fields)
create or replace table t1 (i int, b int) with system versioning;
insert into t1 values (0, 0), (0, 0);
Expand Down
20 changes: 10 additions & 10 deletions mysql-test/suite/versioning/r/select_sp.result
Expand Up @@ -77,12 +77,12 @@ select t1.x as LJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 o
select t1.x as RJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x;
delete from t1;
delete from t2;
select t1.x as IJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x
for system_time as of timestamp @t0;
select t1.x as LJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x
for system_time as of timestamp @t0;
select t1.x as RJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x
for system_time as of timestamp @t0;
select IJ2_x1,y1,x2,y2 from (select t1.x as IJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
select LJ2_x1,y1,x2,y2 from (select t1.x as LJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
select RJ2_x1,y1,x2,y2 from (select t1.x as RJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
drop table t1;
drop table t2;
end~~
Expand Down Expand Up @@ -207,8 +207,6 @@ RJ2_x1 y1 x2 y2
1 1 1 2
1 2 1 2
1 3 1 2
NULL NULL 2 1
NULL NULL 3 1
create table t1(
A int
) with system versioning;
Expand Down Expand Up @@ -321,8 +319,10 @@ select * from t1, t2 for system_time all;
x y
1 1
2 1
select * from t1 for system_time all, t2 for system_time all for system_time all;
ERROR HY000: Unused clause: 'SYSTEM_TIME'
select * from (select * from t1 for system_time all, t2 for system_time all) for system_time all as t;
ERROR HY000: SYSTEM_TIME is not allowed outside historical `t`
select * from (t1 for system_time all join t2 for system_time all) for system_time all;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
drop view v1;
drop table t1, t2;
call innodb_verify_vtq(27);
Expand Down
23 changes: 12 additions & 11 deletions mysql-test/suite/versioning/r/simple.result
Expand Up @@ -42,31 +42,32 @@ where d.dept_id = 10
and d.dept_id = e.dept_id;
emp_id dept_id name salary dept_id name
1 10 bill 2000 10 accounting
select * from emp e, dept d
select * from
emp for system_time from timestamp @ts_1 to timestamp @ts_2 e,
dept for system_time from timestamp @ts_1 to timestamp @ts_2 d
where d.dept_id = 10
and d.dept_id = e.dept_id
for system_time from timestamp @ts_1 to timestamp @ts_2;
and d.dept_id = e.dept_id;
emp_id dept_id name salary sys_trx_start sys_trx_end dept_id name sys_trx_start sys_trx_end
set statement versioning_asof_timestamp=@ts_0 for
select * from emp e, dept d
where d.dept_id = 10
and d.dept_id = e.dept_id
for system_time as of timestamp @ts_0;
and d.dept_id = e.dept_id;
emp_id dept_id name salary dept_id name
set statement versioning_asof_timestamp=@ts_1 for
select * from emp e, dept d
where d.dept_id = 10
and d.dept_id = e.dept_id
for system_time as of timestamp @ts_1;
and d.dept_id = e.dept_id;
emp_id dept_id name salary dept_id name
set statement versioning_asof_timestamp=@ts_2 for
select * from emp e, dept d
where d.dept_id = 10
and d.dept_id = e.dept_id
for system_time as of timestamp @ts_2;
and d.dept_id = e.dept_id;
emp_id dept_id name salary dept_id name
1 10 bill 1000 10 accounting
set statement versioning_asof_timestamp=@ts_3 for
select * from emp e, dept d
where d.dept_id = 10
and d.dept_id = e.dept_id
for system_time as of timestamp @ts_3;
and d.dept_id = e.dept_id;
emp_id dept_id name salary dept_id name
1 10 bill 2000 10 accounting
drop table emp, dept;
4 changes: 2 additions & 2 deletions mysql-test/suite/versioning/t/cte.test
Expand Up @@ -94,8 +94,8 @@ insert emp values (4, 'john', 1);
insert addr values (4, 'Paris');
with ancestors as (select * from emp natural join addr) select * from ancestors;
with ancestors as (select * from emp natural join addr) select * from ancestors for system_time all;
with ancestors as (select * from emp natural join addr where 1 for system_time all) select * from ancestors;
select * from emp natural join addr where 1 for system_time all;
with ancestors as (select * from (select * from emp natural join addr) for system_time all as t) select * from ancestors;
select * from (select * from emp natural join addr) for system_time all as t;

drop table emp;
drop table dept;
Expand Down
17 changes: 7 additions & 10 deletions mysql-test/suite/versioning/t/derived.test
Expand Up @@ -57,19 +57,18 @@ as
select * from ancestors";
prepare stmt from @tmp; execute stmt; drop prepare stmt;

#385
with recursive
ancestors
as
(
select e.emp_id, e.name, e.mgr
from emp as e
from emp for system_time as of timestamp @ts 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
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;
set @tmp= "
Expand All @@ -78,14 +77,12 @@ ancestors
as
(
select e.emp_id, e.name, e.mgr
from emp as e
from emp for system_time as of timestamp @ts 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
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; execute stmt; drop prepare stmt;
Expand All @@ -112,7 +109,7 @@ with s1 as (select * from t1 for system_time as of timestamp @t0, t2) select * f
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;
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;
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;

Expand All @@ -130,7 +127,7 @@ 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;
select * from (select * from t1 for system_time all) for system_time all as dt0;
--error ER_VERS_SYSTEM_TIME_CLASH
select * from vt1 for system_time all;
--error ER_VERS_SYSTEM_TIME_CLASH
Expand Down
13 changes: 3 additions & 10 deletions mysql-test/suite/versioning/t/optimized.test
Expand Up @@ -9,23 +9,16 @@ select * from t;
select a from t for system_time as of timestamp now(6);
select a, b, b+0 from t for system_time as of timestamp now(6);
select * from t for system_time as of timestamp now(6);
select count(*) from t group by b for system_time as of timestamp now(6);
select count(*) from t for system_time as of timestamp now(6) group by b;
select * from t for system_time as of timestamp now(6) order by b asc;
select * from t for system_time as of timestamp now(6) order by b desc;
select * from t group by a having a=2 for system_time as of timestamp now(6);
select * from t group by b having b=2 for system_time as of timestamp now(6);
select a from t where b=2 for system_time as of timestamp now(6);
select a from t where b=NULL for system_time as of timestamp now(6);
select a from t where b is NULL for system_time as of timestamp now(6);
select count(*), b from t group by b having b=NULL for system_time as of timestamp now(6);
select a, b from t;

select count(*) from t for system_time as of timestamp now(6) group by b;
select * from t for system_time as of timestamp now(6) group by a having a=2;
select * from t for system_time as of timestamp now(6) group by b having b=2;
select a from t for system_time as of timestamp now(6) where b=2;
select a from t for system_time as of timestamp now(6) where b=NULL;
select a from t for system_time as of timestamp now(6) where b is NULL;
select count(*), b from t for system_time as of timestamp now(6) group by b having b=NULL;
select a, b from t;

create or replace table t (
a int,
Expand Down

0 comments on commit ca6454b

Please sign in to comment.