mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 02:05:57 +01:00
SQL: regression fix: make NOW a valid identifier again [#363]
* 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)
This commit is contained in:
parent
d3845132fc
commit
ea1ccfa500
12 changed files with 79 additions and 66 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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, "'");
|
||||
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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'
|
||||
|
@ -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');
|
||||
|
@ -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` (
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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, "'");
|
||||
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)},
|
||||
|
@ -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)},
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -739,6 +739,32 @@ bool LEX::set_bincmp(CHARSET_INFO *cs, bool bin)
|
|||
MYSQL_YYABORT; \
|
||||
} while(0)
|
||||
|
||||
|
||||
inline void vers_select_conds_t::init(
|
||||
vers_range_type_t t,
|
||||
vers_range_unit_t u_start= UNIT_AUTO,
|
||||
Item * s= NULL,
|
||||
vers_range_unit_t u_end= UNIT_AUTO,
|
||||
Item * e= NULL)
|
||||
{
|
||||
type= t;
|
||||
unit_start= u_start;
|
||||
unit_end= u_end;
|
||||
start= fix_dec(s);
|
||||
end= fix_dec(e);
|
||||
import_outer= from_inner= false;
|
||||
}
|
||||
|
||||
inline Item *vers_select_conds_t::fix_dec(Item *item)
|
||||
{
|
||||
if (item && item->decimals == 0 && item->type() == Item::FUNC_ITEM &&
|
||||
((Item_func*)item)->functype() == Item_func::NOW_FUNC)
|
||||
item->decimals= 6;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
Virtual_column_info *add_virtual_expression(THD *thd, Item *expr)
|
||||
{
|
||||
Virtual_column_info *v= new (thd->mem_root) Virtual_column_info();
|
||||
|
@ -870,10 +896,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
|
|||
%parse-param { THD *thd }
|
||||
%lex-param { THD *thd }
|
||||
/*
|
||||
Currently there are 124 shift/reduce conflicts.
|
||||
Currently there are 123 shift/reduce conflicts.
|
||||
We should not introduce new conflicts any more.
|
||||
*/
|
||||
%expect 124
|
||||
%expect 123
|
||||
|
||||
/*
|
||||
Comments for TOKENS.
|
||||
|
@ -9032,13 +9058,6 @@ system_time_expr:
|
|||
{
|
||||
Lex->vers_conditions.init(FOR_SYSTEM_TIME_AS_OF, $3, $4);
|
||||
}
|
||||
| AS OF_SYM NOW_SYM
|
||||
{
|
||||
Item *item= new (thd->mem_root) Item_func_now_local(thd, 6);
|
||||
if (item == NULL)
|
||||
MYSQL_YYABORT;
|
||||
Lex->vers_conditions.init(FOR_SYSTEM_TIME_AS_OF, UNIT_TIMESTAMP, item);
|
||||
}
|
||||
| ALL
|
||||
{
|
||||
Lex->vers_conditions.init(FOR_SYSTEM_TIME_ALL);
|
||||
|
|
18
sql/table.h
18
sql/table.h
|
@ -1871,20 +1871,10 @@ struct vers_select_conds_t
|
|||
start= end= NULL;
|
||||
}
|
||||
|
||||
void init(
|
||||
vers_range_type_t t,
|
||||
vers_range_unit_t u_start= UNIT_AUTO,
|
||||
Item * s= NULL,
|
||||
vers_range_unit_t u_end= UNIT_AUTO,
|
||||
Item * e= NULL)
|
||||
{
|
||||
type= t;
|
||||
unit_start= u_start;
|
||||
unit_end= u_end;
|
||||
start= s;
|
||||
end= e;
|
||||
import_outer= from_inner= false;
|
||||
}
|
||||
inline Item *fix_dec(Item *item);
|
||||
|
||||
inline void init( vers_range_type_t t, vers_range_unit_t u_start,
|
||||
Item * s, vers_range_unit_t u_end, Item * e);
|
||||
|
||||
bool init_from_sysvar(THD *thd);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue