From ca6454bcfe2da8f2a639ae6cf223b626ad116100 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 11 Dec 2017 14:09:58 +0100 Subject: [PATCH] for now, remove FOR SYSTEM_TIME at the end of the query 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. --- mysql-test/suite/versioning/r/cte.result | 4 +- mysql-test/suite/versioning/r/derived.result | 20 ++++------ .../suite/versioning/r/optimized.result | 39 +++--------------- mysql-test/suite/versioning/r/select.result | 40 ++++++++++++++----- .../suite/versioning/r/select_sp.result | 20 +++++----- mysql-test/suite/versioning/r/simple.result | 23 ++++++----- mysql-test/suite/versioning/t/cte.test | 4 +- mysql-test/suite/versioning/t/derived.test | 17 ++++---- mysql-test/suite/versioning/t/optimized.test | 13 ++---- mysql-test/suite/versioning/t/select.test | 26 ++++++++---- mysql-test/suite/versioning/t/select_sp.test | 18 +++++---- mysql-test/suite/versioning/t/simple.test | 23 ++++++----- sql/sql_yacc.yy | 33 +++------------ 13 files changed, 124 insertions(+), 156 deletions(-) diff --git a/mysql-test/suite/versioning/r/cte.result b/mysql-test/suite/versioning/r/cte.result index 3043bcb4093c0..50d9361d81626 100644 --- a/mysql-test/suite/versioning/r/cte.result +++ b/mysql-test/suite/versioning/r/cte.result @@ -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 diff --git a/mysql-test/suite/versioning/r/derived.result b/mysql-test/suite/versioning/r/derived.result index d63230748571b..ad7d26644dccc 100644 --- a/mysql-test/suite/versioning/r/derived.result +++ b/mysql-test/suite/versioning/r/derived.result @@ -91,34 +91,29 @@ 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; @@ -126,7 +121,6 @@ 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; @@ -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; @@ -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` diff --git a/mysql-test/suite/versioning/r/optimized.result b/mysql-test/suite/versioning/r/optimized.result index 4c86b6abbc200..8be67793e12a3 100644 --- a/mysql-test/suite/versioning/r/optimized.result +++ b/mysql-test/suite/versioning/r/optimized.result @@ -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: @@ -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: @@ -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 diff --git a/mysql-test/suite/versioning/r/select.result b/mysql-test/suite/versioning/r/select.result index 23d4202a5a4b3..311d7eccc451f 100644 --- a/mysql-test/suite/versioning/r/select.result +++ b/mysql-test/suite/versioning/r/select.result @@ -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( @@ -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); diff --git a/mysql-test/suite/versioning/r/select_sp.result b/mysql-test/suite/versioning/r/select_sp.result index 01b511ffc684e..c3e152c46e5e0 100644 --- a/mysql-test/suite/versioning/r/select_sp.result +++ b/mysql-test/suite/versioning/r/select_sp.result @@ -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~~ @@ -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; @@ -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); diff --git a/mysql-test/suite/versioning/r/simple.result b/mysql-test/suite/versioning/r/simple.result index 8f5fd57ea4b8b..344960e5ab3a9 100644 --- a/mysql-test/suite/versioning/r/simple.result +++ b/mysql-test/suite/versioning/r/simple.result @@ -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; diff --git a/mysql-test/suite/versioning/t/cte.test b/mysql-test/suite/versioning/t/cte.test index 488e7de5dfc33..257d8aebafab3 100644 --- a/mysql-test/suite/versioning/t/cte.test +++ b/mysql-test/suite/versioning/t/cte.test @@ -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; diff --git a/mysql-test/suite/versioning/t/derived.test b/mysql-test/suite/versioning/t/derived.test index 1e86cb9f824ae..b8fbe746534c0 100644 --- a/mysql-test/suite/versioning/t/derived.test +++ b/mysql-test/suite/versioning/t/derived.test @@ -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= " @@ -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; @@ -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; @@ -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 diff --git a/mysql-test/suite/versioning/t/optimized.test b/mysql-test/suite/versioning/t/optimized.test index 311b0aeeb318e..93dd6ed6fc6c3 100644 --- a/mysql-test/suite/versioning/t/optimized.test +++ b/mysql-test/suite/versioning/t/optimized.test @@ -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, diff --git a/mysql-test/suite/versioning/t/select.test b/mysql-test/suite/versioning/t/select.test index f06fca1dbe494..9816dd1fb471c 100644 --- a/mysql-test/suite/versioning/t/select.test +++ b/mysql-test/suite/versioning/t/select.test @@ -84,12 +84,21 @@ select t1.x as RJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 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; +#384 +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; +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; +#383 +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; + +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; +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; +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; drop table t1; drop table t2; @@ -179,8 +188,9 @@ delete from t1 where x = 3; insert into t2 values (1); select * from t1, t2 for system_time all; ---error ER_VERS_UNUSED_CLAUSE -select * from t1 for system_time all, t2 for system_time all for system_time all; +--error ER_VERS_SYSTEM_TIME_CLASH +select * from (select * from t1 for system_time all, t2 for system_time all) +for system_time all as t; --echo ### Issue #365, bug 4 (related to #226, optimized fields) create or replace table t1 (i int, b int) with system versioning; diff --git a/mysql-test/suite/versioning/t/select_sp.test b/mysql-test/suite/versioning/t/select_sp.test index 199e19484b574..b402b21f1006e 100644 --- a/mysql-test/suite/versioning/t/select_sp.test +++ b/mysql-test/suite/versioning/t/select_sp.test @@ -93,12 +93,12 @@ begin 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; @@ -192,8 +192,10 @@ delete from t1 where x = 3; insert into t2 values (1); select * from t1, t2 for system_time all; ---error ER_VERS_UNUSED_CLAUSE -select * from t1 for system_time all, t2 for system_time all for system_time all; +--error ER_VERS_SYSTEM_TIME_CLASH +select * from (select * from t1 for system_time all, t2 for system_time all) for system_time all as t; +--error ER_PARSE_ERROR +select * from (t1 for system_time all join t2 for system_time all) for system_time all; drop view v1; drop table t1, t2; diff --git a/mysql-test/suite/versioning/t/simple.test b/mysql-test/suite/versioning/t/simple.test index 5cda9380153f0..f80ed605992c1 100644 --- a/mysql-test/suite/versioning/t/simple.test +++ b/mysql-test/suite/versioning/t/simple.test @@ -44,29 +44,30 @@ select * from emp e, dept d where d.dept_id = 10 and d.dept_id = e.dept_id; -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; +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; +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; +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; +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; drop table emp, dept; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index ed6ef979fd8ca..41db8bbead403 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -892,10 +892,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %parse-param { THD *thd } %lex-param { THD *thd } /* - Currently there are 125 shift/reduce conflicts. + Currently there are 122 shift/reduce conflicts. We should not introduce new conflicts any more. */ -%expect 125 +%expect 122 /* Comments for TOKENS. @@ -9138,7 +9138,6 @@ table_expression: opt_group_clause opt_having_clause opt_window_clause - opt_system_time_clause ; opt_table_expression: @@ -9188,31 +9187,6 @@ opt_trans_or_timestamp: } ; -opt_system_time_clause: - /* empty */ - {} - | FOR_SYSTEM_TIME_SYM system_time_expr - { - DBUG_ASSERT(Select); - int used= 0; - if (Lex->vers_conditions) - { - for (TABLE_LIST *table= Select->table_list.first; table; table= table->next_local) - { - if (!table->vers_conditions) - { - table->vers_conditions= Lex->vers_conditions; - used++; - } - } - if (!used) - { - my_yyabort_error((ER_VERS_UNUSED_CLAUSE, MYF(0), "SYSTEM_TIME")); - } - } - } - ; - opt_for_system_time_clause: /* empty */ { @@ -11862,7 +11836,10 @@ table_primary_derived: !$$->derived->first_select()->next_select()) $$->select_lex->add_where_field($$->derived->first_select()); if ($5) + { + MYSQL_YYABORT_UNLESS(!$3); $$->vers_conditions= Lex->vers_conditions; + } } /* Represents derived table with WITH clause */ | '(' get_select_lex subselect_start