Commit 91c8b43e authored by Aleksey Midenkov's avatar Aleksey Midenkov

Parser: syntax for query system_time [closes #230]

Eliminated `QUERY FOR`.
parent 60e456df
......@@ -82,13 +82,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 query for system_time all) select * from ancestors;
with ancestors as (select * from emp natural join addr system_time all) 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 query for system_time all;
select * from emp natural join addr system_time all;
emp_id name mgr address
1 bill 0 Moscow
2 bill 1 New York
......
......@@ -148,13 +148,13 @@ 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
select * from (select *, t1.sys_trx_start from t2 for system_time as of now, t1) as s4 query for system_time as of timestamp @t0;
select * from (select *, t1.sys_trx_start from t2 for system_time as of now, t1) as s4 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 now, 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 now, t1) select * from s6 query for system_time as of timestamp @t0;
with s6 as (select *, t1.sys_trx_start from t2 for system_time as of now, t1) select * from s6 system_time as of timestamp @t0;
y x
10 1
set @q= concat("create view vt1 as select * from t1 for system_time as of timestamp '", @t0, "'");
......@@ -170,7 +170,7 @@ x y
select * from (select *, vt1.sys_trx_end from t2, vt1) as s0;
y x
10 1
select * from (select *, vt1.sys_trx_start from t2 for system_time as of now, vt1) as s0 query for system_time as of timestamp @t0;
select * from (select *, vt1.sys_trx_start from t2 for system_time as of now, vt1) as s0 system_time as of timestamp @t0;
y x
10 1
drop table t1, t2;
......
......@@ -25,7 +25,7 @@ a b
3 NULL
Warnings:
Warning 4075 Attempt to read unversioned field `b` in historical query
select count(*) from t group by b query for system_time as of timestamp now(6);
select count(*) from t group by b system_time as of timestamp now(6);
count(*)
2
Warnings:
......@@ -42,29 +42,29 @@ a b
3 NULL
Warnings:
Warning 4075 Attempt to read unversioned field `b` in historical query
select * from t group by a having a=2 query for system_time as of timestamp now(6);
select * from t group by a having a=2 system_time as of timestamp now(6);
a b
Warnings:
Warning 4075 Attempt to read unversioned field `b` in historical query
select * from t group by b having b=2 query for system_time as of timestamp now(6);
select * from t group by b having b=2 system_time as of timestamp now(6);
a b
Warnings:
Warning 4075 Attempt to read unversioned field `b` in historical query
select a from t where b=2 query for system_time as of timestamp now(6);
select a from t where b=2 system_time as of timestamp now(6);
a
Warnings:
Warning 4075 Attempt to read unversioned field `b` in historical query
select a from t where b=NULL query for system_time as of timestamp now(6);
select a from t where b=NULL system_time as of timestamp now(6);
a
Warnings:
Warning 4075 Attempt to read unversioned field `b` in historical query
select a from t where b is NULL query for system_time as of timestamp now(6);
select a from t where b is NULL system_time as of timestamp now(6);
a
1
3
Warnings:
Warning 4075 Attempt to read unversioned field `b` in historical query
select count(*), b from t group by b having b=NULL query for system_time as of timestamp now(6);
select count(*), b from t group by b having b=NULL system_time as of timestamp now(6);
count(*) b
Warnings:
Warning 4075 Attempt to read unversioned field `b` in historical query
......
......@@ -146,11 +146,11 @@ 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
query for system_time as of timestamp @t0;
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
query for system_time as of timestamp @t0;
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
query for system_time as of timestamp @t0;
system_time as of timestamp @t0;
drop table t1;
drop table t2;
end~~
......@@ -333,7 +333,7 @@ A
create or replace table t1 (x int);
insert into t1 values (1);
select * from t1 for system_time all;
ERROR HY000: System Versioning required: `FOR SYSTEM_TIME` query
ERROR HY000: System Versioning required: t1
create or replace table t1 (x int) with system versioning;
insert into t1 values (1);
select * from t1 for system_time all for update;
......@@ -431,13 +431,13 @@ create or replace table t2 (y int) with system versioning;
insert into t1 values (1), (2), (3);
delete from t1 where x = 3;
insert into t2 values (1);
select * from t1, t2 query for system_time all;
select * from t1, t2 system_time all;
x y
1 1
2 1
3 1
select * from t1 for system_time all, t2 for system_time all query for system_time all;
ERROR HY000: Unused clause: 'QUERY FOR SYSTEM_TIME'
select * from t1 for system_time all, t2 for system_time all system_time all;
ERROR HY000: Unused clause: 'SYSTEM_TIME'
drop view v1;
drop table t1, t2;
call innodb_verify_vtq(27);
......
......@@ -44,28 +44,28 @@ emp_id dept_id name salary dept_id name
select * from emp e, dept d
where d.dept_id = 10
and d.dept_id = e.dept_id
query for system_time from timestamp @ts_1 to timestamp @ts_2;
system_time from timestamp @ts_1 to timestamp @ts_2;
emp_id dept_id name salary sys_trx_start sys_trx_end dept_id name sys_trx_start sys_trx_end
select * from emp e, dept d
where d.dept_id = 10
and d.dept_id = e.dept_id
query for system_time as of timestamp @ts_0;
system_time as of timestamp @ts_0;
emp_id dept_id name salary dept_id name
select * from emp e, dept d
where d.dept_id = 10
and d.dept_id = e.dept_id
query for system_time as of timestamp @ts_1;
system_time as of timestamp @ts_1;
emp_id dept_id name salary dept_id name
select * from emp e, dept d
where d.dept_id = 10
and d.dept_id = e.dept_id
query for system_time as of timestamp @ts_2;
system_time as of timestamp @ts_2;
emp_id dept_id name salary dept_id name
1 10 bill 1000 10 accounting
select * from emp e, dept d
where d.dept_id = 10
and d.dept_id = e.dept_id
query for system_time as of timestamp @ts_3;
system_time as of timestamp @ts_3;
emp_id dept_id name salary dept_id name
1 10 bill 2000 10 accounting
drop table emp, dept;
create table t (a int);
truncate t for system_time all;
ERROR HY000: System Versioning required: `FOR SYSTEM_TIME` query
ERROR HY000: Unused clause: 'SYSTEM_TIME'
create procedure truncate_history_of_t()
begin
prepare stmt from 'truncate t for system_time timestamp between \'1-1-1\' and now(6)';
......
......@@ -76,8 +76,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 query for system_time all) select * from ancestors;
select * from emp natural join addr query for system_time all;
with ancestors as (select * from emp natural join addr system_time all) select * from ancestors;
select * from emp natural join addr system_time all;
drop table emp;
drop table dept;
......
......@@ -108,9 +108,9 @@ 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;
# system_time propagation from outer to inner
select * from (select *, t1.sys_trx_start from t2 for system_time as of now, t1) as s4 query for system_time as of timestamp @t0;
select * from (select *, t1.sys_trx_start from t2 for system_time as of now, t1) as s4 system_time as of timestamp @t0;
with s5 as (select *, t1.sys_trx_start from t2 for system_time as of now, 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 now, t1) select * from s6 query for system_time as of timestamp @t0;
with s6 as (select *, t1.sys_trx_start from t2 for system_time as of now, t1) select * from s6 system_time as of timestamp @t0;
# VIEW instead of t1
set @q= concat("create view vt1 as select * from t1 for system_time as of timestamp '", @t0, "'");
......@@ -123,7 +123,7 @@ select * from (select * from vt1, t2) as s0;
# leading table selection
select * from (select *, vt1.sys_trx_end from t2, vt1) as s0;
# system_time propagation from outer to inner
select * from (select *, vt1.sys_trx_start from t2 for system_time as of now, vt1) as s0 query for system_time as of timestamp @t0;
select * from (select *, vt1.sys_trx_start from t2 for system_time as of now, vt1) as s0 system_time as of timestamp @t0;
drop table t1, t2;
drop view vt1;
......@@ -9,15 +9,15 @@ 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 query for system_time as of timestamp now(6);
select count(*) from t group by b system_time as of timestamp now(6);
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 query for system_time as of timestamp now(6);
select * from t group by b having b=2 query for system_time as of timestamp now(6);
select a from t where b=2 query for system_time as of timestamp now(6);
select a from t where b=NULL query for system_time as of timestamp now(6);
select a from t where b is NULL query for system_time as of timestamp now(6);
select count(*), b from t group by b having b=NULL query for system_time as of timestamp now(6);
select * from t group by a having a=2 system_time as of timestamp now(6);
select * from t group by b having b=2 system_time as of timestamp now(6);
select a from t where b=2 system_time as of timestamp now(6);
select a from t where b=NULL system_time as of timestamp now(6);
select a from t where b is NULL system_time as of timestamp now(6);
select count(*), b from t group by b having b=NULL system_time as of timestamp now(6);
select a, b from t;
drop table t;
......@@ -99,11 +99,11 @@ begin
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
query for system_time as of timestamp @t0;
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
query for system_time as of timestamp @t0;
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
query for system_time as of timestamp @t0;
system_time as of timestamp @t0;
drop table t1;
drop table t2;
......@@ -195,10 +195,10 @@ create or replace table t2 (y int) with system versioning;
insert into t1 values (1), (2), (3);
delete from t1 where x = 3;
insert into t2 values (1);
select * from t1, t2 query for system_time all;
select * from t1, t2 system_time all;
--error ER_VERS_UNUSED_CLAUSE
select * from t1 for system_time all, t2 for system_time all query for system_time all;
select * from t1 for system_time all, t2 for system_time all system_time all;
drop view v1;
drop table t1, t2;
......
......@@ -45,26 +45,26 @@ where d.dept_id = 10
select * from emp e, dept d
where d.dept_id = 10
and d.dept_id = e.dept_id
query for system_time from timestamp @ts_1 to timestamp @ts_2;
system_time from timestamp @ts_1 to timestamp @ts_2;
select * from emp e, dept d
where d.dept_id = 10
and d.dept_id = e.dept_id
query for system_time as of timestamp @ts_0;
system_time as of timestamp @ts_0;
select * from emp e, dept d
where d.dept_id = 10
and d.dept_id = e.dept_id
query for system_time as of timestamp @ts_1;
system_time as of timestamp @ts_1;
select * from emp e, dept d
where d.dept_id = 10
and d.dept_id = e.dept_id
query for system_time as of timestamp @ts_2;
system_time as of timestamp @ts_2;
select * from emp e, dept d
where d.dept_id = 10
and d.dept_id = e.dept_id
query for system_time as of timestamp @ts_3;
system_time as of timestamp @ts_3;
drop table emp, dept;
-- source include/have_innodb.inc
create table t (a int);
--error ER_VERSIONING_REQUIRED
--error ER_VERS_UNUSED_CLAUSE
truncate t for system_time all;
delimiter ~~;
......
......@@ -1368,21 +1368,6 @@ int MYSQLlex(YYSTYPE *yylval, THD *thd)
return FOR_SYM;
}
break;
case QUERY_SYM:
{
CHARSET_INFO *cs= thd->charset();
const char *p= lip->get_ptr();
while (my_isspace(cs, *p))
++p;
if (lip->get_end_of_query() - p > 3 && my_isspace(cs, p[3]) &&
0 == strncasecmp(p, "for", 3))
{
token= lex_one_token(yylval, thd);
lip->add_digest_token(token, yylval);
return QUERY_FOR_SYM;
}
return QUERY_SYM;
}
default:
break;
}
......
......@@ -708,7 +708,7 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
versioned_tables++;
else if (table->vers_conditions)
{
my_error(ER_VERSIONING_REQUIRED, MYF(0), "`FOR SYSTEM_TIME` query");
my_error(ER_VERSIONING_REQUIRED, MYF(0), table->alias);
DBUG_RETURN(-1);
}
}
......@@ -717,7 +717,7 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
{
if (slex->vers_conditions)
{
my_error(ER_VERSIONING_REQUIRED, MYF(0), "`FOR SYSTEM_TIME` query");
my_error(ER_VERS_UNUSED_CLAUSE, MYF(0), "SYSTEM_TIME");
DBUG_RETURN(-1);
}
DBUG_RETURN(0);
......@@ -1014,7 +1014,7 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
if (!slex->vers_conditions.used && slex->vers_conditions)
{
my_error(ER_VERS_UNUSED_CLAUSE, MYF(0), "QUERY FOR SYSTEM_TIME");
my_error(ER_VERS_UNUSED_CLAUSE, MYF(0), "SYSTEM_TIME");
DBUG_RETURN(-1);
}
......
......@@ -1355,7 +1355,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token PURGE
%token QUARTER_SYM
%token QUERY_SYM
%token QUERY_FOR_SYM /* INTERNAL */
%token QUICK
%token RAISE_SYM /* Oracle-PLSQL-R */
%token RANGE_SYM /* SQL-2003-R */
......@@ -8804,7 +8803,7 @@ table_expression:
opt_group_clause
opt_having_clause
opt_window_clause
opt_query_for_system_time_clause
opt_system_time_clause
;
opt_table_expression:
......@@ -8850,10 +8849,10 @@ trans_or_timestamp:
}
;
opt_query_for_system_time_clause:
opt_system_time_clause:
/* empty */
{}
| QUERY_FOR_SYM SYSTEM_TIME_SYM for_system_time_expr
| SYSTEM_TIME_SYM system_time_expr
{
DBUG_ASSERT(Select);
Select->vers_conditions= Lex->vers_conditions;
......@@ -8865,13 +8864,13 @@ opt_for_system_time_clause:
{
$$= false;
}
| FOR_SYSTEM_TIME_SYM for_system_time_expr
| FOR_SYSTEM_TIME_SYM system_time_expr
{
$$= true;
}
;
for_system_time_expr:
system_time_expr:
AS OF_SYM trans_or_timestamp simple_expr
{
Lex->vers_conditions.init(FOR_SYSTEM_TIME_AS_OF, $3, $4);
......
......@@ -763,7 +763,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token PURGE
%token QUARTER_SYM
%token QUERY_SYM
%token QUERY_FOR_SYM /* INTERNAL */
%token QUICK
%token RAISE_SYM /* Oracle-PLSQL-R */
%token RANGE_SYM /* SQL-2003-R */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment