diff --git a/mysql-test/r/parser.result b/mysql-test/r/parser.result index c57e2c2c803..f197fbe6a19 100644 --- a/mysql-test/r/parser.result +++ b/mysql-test/r/parser.result @@ -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); diff --git a/mysql-test/suite/versioning/r/cte.result b/mysql-test/suite/versioning/r/cte.result index 12532041857..20fe0c1a081 100644 --- a/mysql-test/suite/versioning/r/cte.result +++ b/mysql-test/suite/versioning/r/cte.result @@ -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 diff --git a/mysql-test/suite/versioning/r/derived.result b/mysql-test/suite/versioning/r/derived.result index 9f110ba0c29..d2a909ebf44 100644 --- a/mysql-test/suite/versioning/r/derived.result +++ b/mysql-test/suite/versioning/r/derived.result @@ -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; diff --git a/mysql-test/suite/versioning/r/partition.result b/mysql-test/suite/versioning/r/partition.result index 3c6445eeb8d..58ac879c3e2 100644 --- a/mysql-test/suite/versioning/r/partition.result +++ b/mysql-test/suite/versioning/r/partition.result @@ -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 diff --git a/mysql-test/suite/versioning/t/cte.test b/mysql-test/suite/versioning/t/cte.test index 084b4feec57..bc7caec9e71 100644 --- a/mysql-test/suite/versioning/t/cte.test +++ b/mysql-test/suite/versioning/t/cte.test @@ -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 diff --git a/mysql-test/suite/versioning/t/derived.test b/mysql-test/suite/versioning/t/derived.test index 35abebb7743..9e3bd367064 100644 --- a/mysql-test/suite/versioning/t/derived.test +++ b/mysql-test/suite/versioning/t/derived.test @@ -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; diff --git a/mysql-test/suite/versioning/t/partition.test b/mysql-test/suite/versioning/t/partition.test index cbc02d44e31..7abaf591a4e 100644 --- a/mysql-test/suite/versioning/t/partition.test +++ b/mysql-test/suite/versioning/t/partition.test @@ -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); diff --git a/mysql-test/t/parser.test b/mysql-test/t/parser.test index 3be42eb0595..98eaa7a7774 100644 --- a/mysql-test/t/parser.test +++ b/mysql-test/t/parser.test @@ -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); diff --git a/sql/lex.h b/sql/lex.h index f0ee16dea57..25b6b834a55 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -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)}, diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 700b25419e8..55d906bb3b4 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -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")); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 41d0070ddfd..47400338a31 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -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); diff --git a/sql/table.h b/sql/table.h index 869469f18a0..55218837510 100644 --- a/sql/table.h +++ b/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);