Skip to content

Commit

Permalink
SQL: regression fix: make NOW a valid identifier again [#363]
Browse files Browse the repository at this point in the history
* again, as in 10.2, NOW is a keyword only if followed by parentheses
* use AS OF CURRENT_TIMESTAMP or AS OF NOW()
* AS OF CURRENT_TIMESTAMP and AS OF NOW() mean AS OF NOW(6),
  not AS OF NOW(0), (same behavior as in a DEFAULT clause)
  • Loading branch information
vuvova authored and midenok committed Dec 8, 2017
1 parent d384513 commit ea1ccfa
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 66 deletions.
4 changes: 3 additions & 1 deletion mysql-test/r/parser.result
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ create table MIN(a int);
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 'MIN(a int)' at line 1
create table MIN (a int);
drop table MIN;
create table NOW(a int);
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 'NOW(a int)' at line 1
create table NOW (a int);
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 'NOW (a int)' at line 1
drop table NOW;
create table POSITION(a int);
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 'POSITION(a int)' at line 1
create table POSITION (a int);
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/versioning/r/cte.result
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ from emp for system_time as of timestamp @ts_1 as e,
ancestors as a
where e.mgr = a.emp_id
)
select * from ancestors for system_time as of now;
select * from ancestors for system_time as of current_timestamp;
emp_id name mgr salary
1 bill NULL 1000
30 jane 1 750
Expand Down
8 changes: 4 additions & 4 deletions mysql-test/suite/versioning/r/derived.result
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,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 for system_time as of timestamp @t0;
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 now, t1) select * from s5 for system_time as of timestamp @t0;
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 now, t1) select * from s6 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;
y x
10 1
set @q= concat("create view vt1 as select * from t1 for system_time as of timestamp '", @t0, "'");
Expand All @@ -174,7 +174,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 for system_time as of timestamp @t0;
select * from (select *, vt1.sys_trx_start from t2 for system_time as of current_timestamp, vt1) as s0 for system_time as of timestamp @t0;
y x
10 1
drop table t1, t2;
Expand Down
32 changes: 16 additions & 16 deletions mysql-test/suite/versioning/r/partition.result
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ x
create or replace table t1 (x int)
partition by system_time (
partition p0 versioning,
partition pn as of now);
partition pn as of current_timestamp);
ERROR HY000: System Versioning required: t1
create or replace table t1 (x int);
alter table t1
partition by system_time (
partition p0 versioning,
partition pn as of now);
partition pn as of current_timestamp);
Got one of the listed errors
create or replace table t1 (x int)
with system versioning
partition by system_time (
partition p0 as of now);
partition p0 as of current_timestamp);
ERROR HY000: Wrong partitions consistency for `t1`: must have at least one 'VERSIONING' and exactly one last 'AS OF NOW'
create or replace table t1 (x int)
with system versioning
partition by system_time (
partition p0 as of now,
partition p1 as of now);
partition p0 as of current_timestamp,
partition p1 as of current_timestamp);
ERROR HY000: Wrong partitions consistency for `t1`: must have at least one 'VERSIONING' and exactly one last 'AS OF NOW'
create or replace table t1 (x int)
with system versioning
Expand All @@ -58,16 +58,16 @@ ERROR HY000: Wrong partitions consistency for `t1`: must have at least one 'VERS
create or replace table t1 (x int)
with system versioning
partition by system_time (
partition pn as of now,
partition pn as of current_timestamp,
partition p0 versioning);
ERROR HY000: Wrong partitions consistency for `t1`: must have at least one 'VERSIONING' and exactly one last 'AS OF NOW'
create or replace table t1 (x int)
with system versioning
partition by system_time (
partition p0 versioning,
partition pn as of now);
partition pn as of current_timestamp);
alter table t1 add partition (
partition p1 as of now);
partition p1 as of current_timestamp);
ERROR HY000: Wrong partitions consistency for `t1`: must have at least one 'VERSIONING' and exactly one last 'AS OF NOW'
alter table t1 add partition (
partition p1 versioning);
Expand All @@ -84,7 +84,7 @@ t1 CREATE TABLE `t1` (
PARTITION BY SYSTEM_TIME
(PARTITION `p0` VERSIONING ENGINE = ${INNODB_OR_MYISAM},
PARTITION `p1` VERSIONING ENGINE = ${INNODB_OR_MYISAM},
PARTITION `pn` AS OF NOW ENGINE = ${INNODB_OR_MYISAM})
PARTITION `pn` AS OF CURRENT_TIMESTAMP ENGINE = ${INNODB_OR_MYISAM})
insert into t1 values (1), (2);
alter table t1 drop partition pn;
ERROR HY000: Wrong partitions consistency for `t1`: must have at least one 'VERSIONING' and exactly one last 'AS OF NOW'
Expand All @@ -99,7 +99,7 @@ create or replace table t1 (x int)
with system versioning
partition by system_time (
partition p0 versioning,
partition pn as of now);
partition pn as of current_timestamp);
set @now= now(6);
insert into t1 values (1);
set @ts_start= sys_commit_ts('sys_trx_start');
Expand Down Expand Up @@ -180,14 +180,14 @@ with system versioning
partition by system_time limit 0 (
partition p0 versioning,
partition p1 versioning,
partition pn as of now);
partition pn as of current_timestamp);
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'LIMIT'
create or replace table t1 (x int)
with system versioning
partition by system_time limit 1 (
partition p0 versioning,
partition p1 versioning,
partition pn as of now);
partition pn as of current_timestamp);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
Expand All @@ -199,7 +199,7 @@ t1 CREATE TABLE `t1` (
PARTITION BY SYSTEM_TIME LIMIT 1
(PARTITION `p0` VERSIONING ENGINE = ${INNODB_OR_MYISAM},
PARTITION `p1` VERSIONING ENGINE = ${INNODB_OR_MYISAM},
PARTITION `pn` AS OF NOW ENGINE = ${INNODB_OR_MYISAM})
PARTITION `pn` AS OF CURRENT_TIMESTAMP ENGINE = ${INNODB_OR_MYISAM})
alter table t1 drop partition non_existent;
ERROR HY000: Error in list of partitions to DROP
insert into t1 values (1), (2);
Expand Down Expand Up @@ -229,14 +229,14 @@ with system versioning
partition by system_time interval 0 second (
partition p0 versioning,
partition p1 versioning,
partition pn as of now);
partition pn as of current_timestamp);
ERROR HY000: Wrong parameters for partitioned `t1`: wrong value for 'INTERVAL'
create or replace table t1 (x int)
with system versioning
partition by system_time interval 1 second (
partition p0 versioning,
partition p1 versioning,
partition pn as of now);
partition pn as of current_timestamp);
insert into t1 values (1), (2), (3);
select * from t1 partition (pn);
x
Expand All @@ -263,7 +263,7 @@ subpartition by key (x)
subpartitions 2 (
partition p0 versioning,
partition p1 versioning,
partition pn as of now);
partition pn as of current_timestamp);
insert into t1 (x) values (1), (2), (3);
select * from t1 partition (pnsp0);
x
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/versioning/t/cte.test
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ as
ancestors as a
where e.mgr = a.emp_id
)
select * from ancestors for system_time as of now;
select * from ancestors for system_time as of current_timestamp;

/* Expected 3 rows */
with recursive
Expand Down
8 changes: 4 additions & 4 deletions mysql-test/suite/versioning/t/derived.test
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,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 for 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 for system_time as of timestamp @t0;
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;
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;

# VIEW instead of t1
set @q= concat("create view vt1 as select * from t1 for system_time as of timestamp '", @t0, "'");
Expand All @@ -127,7 +127,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 for system_time as of timestamp @t0;
select * from (select *, vt1.sys_trx_start from t2 for system_time as of current_timestamp, vt1) as s0 for system_time as of timestamp @t0;

drop table t1, t2;
drop view vt1;
28 changes: 14 additions & 14 deletions mysql-test/suite/versioning/t/partition.test
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ select * from t1 partition (p1) for system_time all;
create or replace table t1 (x int)
partition by system_time (
partition p0 versioning,
partition pn as of now);
partition pn as of current_timestamp);

create or replace table t1 (x int);
--error ER_VERSIONING_REQUIRED,ER_VERSIONING_REQUIRED
alter table t1
partition by system_time (
partition p0 versioning,
partition pn as of now);
partition pn as of current_timestamp);

--error ER_VERS_WRONG_PARTS
create or replace table t1 (x int)
with system versioning
partition by system_time (
partition p0 as of now);
partition p0 as of current_timestamp);

--error ER_VERS_WRONG_PARTS
create or replace table t1 (x int)
with system versioning
partition by system_time (
partition p0 as of now,
partition p1 as of now);
partition p0 as of current_timestamp,
partition p1 as of current_timestamp);

--error ER_VERS_WRONG_PARTS
create or replace table t1 (x int)
Expand All @@ -59,19 +59,19 @@ partition by system_time (
create or replace table t1 (x int)
with system versioning
partition by system_time (
partition pn as of now,
partition pn as of current_timestamp,
partition p0 versioning);

create or replace table t1 (x int)
with system versioning
partition by system_time (
partition p0 versioning,
partition pn as of now);
partition pn as of current_timestamp);

# alter table
--error ER_VERS_WRONG_PARTS
alter table t1 add partition (
partition p1 as of now);
partition p1 as of current_timestamp);

alter table t1 add partition (
partition p1 versioning);
Expand All @@ -94,7 +94,7 @@ create or replace table t1 (x int)
with system versioning
partition by system_time (
partition p0 versioning,
partition pn as of now);
partition pn as of current_timestamp);

set @now= now(6);
insert into t1 values (1);
Expand Down Expand Up @@ -158,14 +158,14 @@ with system versioning
partition by system_time limit 0 (
partition p0 versioning,
partition p1 versioning,
partition pn as of now);
partition pn as of current_timestamp);

create or replace table t1 (x int)
with system versioning
partition by system_time limit 1 (
partition p0 versioning,
partition p1 versioning,
partition pn as of now);
partition pn as of current_timestamp);

--replace_result InnoDB ${INNODB_OR_MYISAM} MyISAM ${INNODB_OR_MYISAM} "bigint(20) unsigned" ${SYS_TRX_TYPE} timestamp(6) ${SYS_TRX_TYPE}
show create table t1;
Expand All @@ -190,14 +190,14 @@ with system versioning
partition by system_time interval 0 second (
partition p0 versioning,
partition p1 versioning,
partition pn as of now);
partition pn as of current_timestamp);

create or replace table t1 (x int)
with system versioning
partition by system_time interval 1 second (
partition p0 versioning,
partition p1 versioning,
partition pn as of now);
partition pn as of current_timestamp);

insert into t1 values (1), (2), (3);
select * from t1 partition (pn);
Expand All @@ -217,7 +217,7 @@ subpartition by key (x)
subpartitions 2 (
partition p0 versioning,
partition p1 versioning,
partition pn as of now);
partition pn as of current_timestamp);

insert into t1 (x) values (1), (2), (3);
select * from t1 partition (pnsp0);
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/t/parser.test
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ create table MIN (a int);
drop table MIN;

--error ER_PARSE_ERROR
create table NOW(a int);
create table NOW (a int);
drop table NOW;

--error ER_PARSE_ERROR
create table POSITION(a int);
Expand Down
2 changes: 1 addition & 1 deletion sql/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ static SYMBOL symbols[] = {
{ "NONE", SYM(NONE_SYM)},
{ "NOT", SYM(NOT_SYM)},
{ "NOTFOUND", SYM(NOTFOUND_SYM)},
{ "NOW", SYM(NOW_SYM)},
{ "NO_WRITE_TO_BINLOG", SYM(NO_WRITE_TO_BINLOG)},
{ "NULL", SYM(NULL_SYM)},
{ "NUMBER", SYM(NUMBER_SYM)},
Expand Down Expand Up @@ -746,6 +745,7 @@ static SYMBOL sql_functions[] = {
{ "MEDIAN", SYM(MEDIAN_SYM)},
{ "MID", SYM(SUBSTRING)}, /* unireg function */
{ "MIN", SYM(MIN_SYM)},
{ "NOW", SYM(NOW_SYM)},
{ "NTH_VALUE", SYM(NTH_VALUE_SYM)},
{ "NTILE", SYM(NTILE_SYM)},
{ "POSITION", SYM(POSITION_SYM)},
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2221,7 +2221,7 @@ static int add_partition_values(String *str, partition_info *part_info,
switch (p_elem->type())
{
case partition_element::AS_OF_NOW:
err+= str->append(STRING_WITH_LEN(" AS OF NOW"));
err+= str->append(STRING_WITH_LEN(" AS OF CURRENT_TIMESTAMP"));
break;
case partition_element::VERSIONING:
err+= str->append(STRING_WITH_LEN(" VERSIONING"));
Expand Down
Loading

0 comments on commit ea1ccfa

Please sign in to comment.