Skip to content

Commit

Permalink
MDEV-15004 parser greedily parses AS OF TIMESTAMP
Browse files Browse the repository at this point in the history
* TIMESTAMP precedence fixed.
  • Loading branch information
midenok authored and vuvova committed Feb 23, 2018
1 parent e2f70d6 commit f1bd02d
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 31 deletions.
6 changes: 3 additions & 3 deletions mysql-test/suite/versioning/r/delete.result
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ select sys_start into @sys_start from t1;
delete from t1;
select * from t1;
select x = 1 as A, sys_start = @sys_start as B, sys_end > sys_start as C
from t1 for system_time between timestamp '0-0-0' and timestamp '2038-01-19 04:14:07';
from t1 for system_time all;
drop table t1;
end~~
create or replace procedure test_03(
Expand Down Expand Up @@ -91,8 +91,8 @@ select x as t2_x from t2;
delete t1, t2 from t1 join t2 where t1.x = t2.x;
select x as t1_x from t1;
select x as t2_x from t2;
select x as t1_x_all from t1 for system_time between timestamp '0-0-0' and timestamp '2038-01-19 04:14:07';
select x as t2_x_all from t2 for system_time between timestamp '0-0-0' and timestamp '2038-01-19 04:14:07';
select x as t1_x_all from t1 for system_time all;
select x as t2_x_all from t2 for system_time all;
drop table t1;
drop table t2;
end~~
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/suite/versioning/r/foreign.result
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ update parent set id=id+1;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`))
delete from child;
update parent set id=id+1;
select * from child for system_time from timestamp '1-1-1' to timestamp now(6);
select * from child for system_time from timestamp 0 to timestamp now(6);
parent_id
1
1
Expand Down Expand Up @@ -165,7 +165,7 @@ delete from child where parent_id = 1;
delete from parent where id = 1;
select * from child;
parent_id
select * from child for system_time from timestamp '1-1-1' to timestamp now(6);
select * from child for system_time from timestamp 0 to timestamp now(6);
parent_id
1
1
Expand Down
12 changes: 11 additions & 1 deletion mysql-test/suite/versioning/r/select.result
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ a b
select * from (select * from (select * from t1 cross join t2) as tmp1) as tmp2;
a b
1 2
select * from (select * from t1 cross join t2 for system_time as of timestamp '0-0-0') as tmp;
select * from (select * from t1 cross join t2 for system_time as of timestamp ('0-0-0')) as tmp;
a b
create or replace table t1(a1 int) with system versioning;
create or replace table t2(a2 int) with system versioning;
Expand Down Expand Up @@ -475,6 +475,16 @@ f1 f2 f3 f1 f2 f3 f4
3 3 NULL NULL 3 1 1
3 3 NULL NULL 3 2 1
4 NULL NULL NULL NULL NULL NULL
### MDEV-15004 parser greedily parses AS OF TIMESTAMP
select timestamp'2016-02-30 08:07:06';
ERROR HY000: Incorrect DATETIME value: '2016-02-30 08:07:06'
select * from t1 for system_time as of timestamp'2016-02-30 08:07:06';
ERROR HY000: Incorrect DATETIME value: '2016-02-30 08:07:06'
select timestamp('2003-12-31 12:00:00','12:00:00');
timestamp('2003-12-31 12:00:00','12:00:00')
2004-01-01 00:00:00
select * from t1 for system_time as of timestamp('2003-12-31 12:00:00','12:00:00');
f1
drop view v1;
drop table t1, t2, t3, t4;
call verify_vtq_dummy(34);
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/versioning/r/select2.result
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ a b
select * from (select * from (select * from t1 cross join t2) as tmp1) as tmp2;
a b
1 2
select * from (select * from t1 cross join t2 for system_time as of timestamp '0-0-0') as tmp;
select * from (select * from t1 cross join t2 for system_time as of timestamp ('0-0-0')) as tmp;
a b
create or replace table t1(a1 int) with system versioning;
create or replace table t2(a2 int) with system versioning;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/versioning/r/view.result
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ create or replace view vt12 as select * from t1 cross join t2;
select * from vt12;
a b
1 2
create or replace view vt12 as select * from t1 for system_time as of timestamp '0-0-0' cross join t2;
create or replace view vt12 as select * from t1 for system_time as of timestamp ('0-0-0') cross join t2;
select * from vt12;
a b
# VIEW improvements [#183]
Expand Down
6 changes: 3 additions & 3 deletions mysql-test/suite/versioning/t/delete.test
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ begin
delete from t1;
select * from t1;
select x = 1 as A, sys_start = @sys_start as B, sys_end > sys_start as C
from t1 for system_time between timestamp '0-0-0' and timestamp '2038-01-19 04:14:07';
from t1 for system_time all;
drop table t1;
end~~

Expand Down Expand Up @@ -96,8 +96,8 @@ begin
delete t1, t2 from t1 join t2 where t1.x = t2.x;
select x as t1_x from t1;
select x as t2_x from t2;
select x as t1_x_all from t1 for system_time between timestamp '0-0-0' and timestamp '2038-01-19 04:14:07';
select x as t2_x_all from t2 for system_time between timestamp '0-0-0' and timestamp '2038-01-19 04:14:07';
select x as t1_x_all from t1 for system_time all;
select x as t2_x_all from t2 for system_time all;
drop table t1;
drop table t2;
end~~
Expand Down
6 changes: 3 additions & 3 deletions mysql-test/suite/versioning/t/foreign.test
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ insert into child values(1);
update parent set id=id+1;
delete from child;
update parent set id=id+1;
select * from child for system_time from timestamp '1-1-1' to timestamp now(6);
select * from child for system_time from timestamp 0 to timestamp now(6);

drop table child;
drop table parent;
Expand Down Expand Up @@ -188,7 +188,7 @@ delete from child where parent_id = 1;
--echo ## FIXME END
delete from parent where id = 1;
select * from child;
select * from child for system_time from timestamp '1-1-1' to timestamp now(6);
select * from child for system_time from timestamp 0 to timestamp now(6);
delete from child;

insert into parent values(1);
Expand All @@ -198,7 +198,7 @@ if (0)
{
update parent set id=id+1;
select * from child;
select * from child for system_time from timestamp '1-1-1' to timestamp now(6);
select * from child for system_time from timestamp 0 to timestamp now(6);
}
## FIXME END

Expand Down
9 changes: 8 additions & 1 deletion mysql-test/suite/versioning/t/select.test
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ insert into t1 values (1);
insert into t2 values (2);
select * from (select * from t1 cross join t2) as tmp;
select * from (select * from (select * from t1 cross join t2) as tmp1) as tmp2;
select * from (select * from t1 cross join t2 for system_time as of timestamp '0-0-0') as tmp;
select * from (select * from t1 cross join t2 for system_time as of timestamp ('0-0-0')) as tmp;

create or replace table t1(a1 int) with system versioning;
create or replace table t2(a2 int) with system versioning;
Expand Down Expand Up @@ -297,6 +297,13 @@ select * from
left join t2 as t2a left join (t3 as t3a inner join t1) on t2a.f2 = t3a.f3 on t1a.f1 = t2a.f2
left join (t2 join t3 inner join t4) on t2a.f2 = t1a.f1;

--echo ### MDEV-15004 parser greedily parses AS OF TIMESTAMP
--error ER_WRONG_VALUE
select timestamp'2016-02-30 08:07:06';
--error ER_WRONG_VALUE
select * from t1 for system_time as of timestamp'2016-02-30 08:07:06';
select timestamp('2003-12-31 12:00:00','12:00:00');
select * from t1 for system_time as of timestamp('2003-12-31 12:00:00','12:00:00');

drop view v1;
drop table t1, t2, t3, t4;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/versioning/t/select2.test
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ insert into t1 values (1);
insert into t2 values (2);
select * from (select * from t1 cross join t2) as tmp;
select * from (select * from (select * from t1 cross join t2) as tmp1) as tmp2;
select * from (select * from t1 cross join t2 for system_time as of timestamp '0-0-0') as tmp;
select * from (select * from t1 cross join t2 for system_time as of timestamp ('0-0-0')) as tmp;

create or replace table t1(a1 int) with system versioning;
create or replace table t2(a2 int) with system versioning;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/versioning/t/view.test
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ insert into t1 values (1);
insert into t2 values (2);
create or replace view vt12 as select * from t1 cross join t2;
select * from vt12;
create or replace view vt12 as select * from t1 for system_time as of timestamp '0-0-0' cross join t2;
create or replace view vt12 as select * from t1 for system_time as of timestamp ('0-0-0') cross join t2;
select * from vt12;

--echo # VIEW improvements [#183]
Expand Down
43 changes: 29 additions & 14 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -884,10 +884,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
%parse-param { THD *thd }
%lex-param { THD *thd }
/*
Currently there are 125 shift/reduce conflicts.
Currently there are 139 shift/reduce conflicts.
We should not introduce new conflicts any more.
*/
%expect 125
%expect 139

/*
Comments for TOKENS.
Expand Down Expand Up @@ -1776,6 +1776,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
percentile_function
inverse_distribution_function_def
function_call_keyword
function_call_keyword_timestamp
function_call_nonkeyword
function_call_generic
function_call_conflict kill_expr
Expand Down Expand Up @@ -9200,7 +9201,15 @@ opt_history_unit:
;

history_point:
opt_history_unit simple_expr
temporal_literal
{
$$= Vers_history_point(VERS_TIMESTAMP, $1);
}
| function_call_keyword_timestamp
{
$$= Vers_history_point(VERS_TIMESTAMP, $1);
}
| opt_history_unit simple_expr
{
$$= Vers_history_point($1, $2);
}
Expand Down Expand Up @@ -10099,6 +10108,21 @@ simple_expr:
}
;

function_call_keyword_timestamp:
TIMESTAMP '(' expr ')'
{
$$= new (thd->mem_root) Item_datetime_typecast(thd, $3,
AUTO_SEC_PART_DIGITS);
if ($$ == NULL)
MYSQL_YYABORT;
}
| TIMESTAMP '(' expr ',' expr ')'
{
$$= new (thd->mem_root) Item_func_add_time(thd, $3, $5, 1, 0);
if ($$ == NULL)
MYSQL_YYABORT;
}
;
/*
Function call syntax using official SQL 2003 keywords.
Because the function name is an official token,
Expand Down Expand Up @@ -10222,18 +10246,9 @@ function_call_keyword:
if ($$ == NULL)
MYSQL_YYABORT;
}
| TIMESTAMP '(' expr ')'
{
$$= new (thd->mem_root) Item_datetime_typecast(thd, $3,
AUTO_SEC_PART_DIGITS);
if ($$ == NULL)
MYSQL_YYABORT;
}
| TIMESTAMP '(' expr ',' expr ')'
| function_call_keyword_timestamp
{
$$= new (thd->mem_root) Item_func_add_time(thd, $3, $5, 1, 0);
if ($$ == NULL)
MYSQL_YYABORT;
$$= $1;
}
| TRIM '(' expr ')'
{
Expand Down

0 comments on commit f1bd02d

Please sign in to comment.