diff --git a/mysql-test/suite/versioning/r/select.result b/mysql-test/suite/versioning/r/select.result index 8557992432c1c..a09c4c19ee0bb 100644 --- a/mysql-test/suite/versioning/r/select.result +++ b/mysql-test/suite/versioning/r/select.result @@ -356,6 +356,12 @@ create or replace table t1 (a int, b int, key idx(a)) with system versioning; insert into t1 values (1, 1), (2, 2); select * from t1 where (a, 2) in ((1, 1), (2, 2)) and b = 1; a b +### Issue #398, NOW is now non-magic +create or replace table t1 (x int) with system versioning; +select * from t1 for system_time as of current_timestamp; +x +select * from t1 for system_time as of now; +ERROR 42S22: Unknown column 'now' in 'where clause' drop view v1; drop table t1, t2; call innodb_verify_vtq(32); diff --git a/mysql-test/suite/versioning/t/select.test b/mysql-test/suite/versioning/t/select.test index 68678146ccc6a..7b99cd9d13f01 100644 --- a/mysql-test/suite/versioning/t/select.test +++ b/mysql-test/suite/versioning/t/select.test @@ -242,6 +242,12 @@ create or replace table t1 (a int, b int, key idx(a)) with system versioning; insert into t1 values (1, 1), (2, 2); select * from t1 where (a, 2) in ((1, 1), (2, 2)) and b = 1; +--echo ### Issue #398, NOW is now non-magic +create or replace table t1 (x int) with system versioning; +select * from t1 for system_time as of current_timestamp; +--error ER_BAD_FIELD_ERROR +select * from t1 for system_time as of now; + drop view v1; drop table t1, t2; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index dca4b60dc4d32..3fe9c1c3d17d3 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -895,6 +895,10 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr if (vers_conditions) { + /* TODO: do resolve fix_length_and_dec(), fix_fields(). This requires + storing vers_conditions as Item and make some magic related to + UNIT_TIMESTAMP/UNIT_TRX_ID at stage of fix_fields() + (this is large refactoring). */ vers_conditions.resolve_units(timestamps_only); if (timestamps_only && (vers_conditions.unit_start == UNIT_TRX_ID || vers_conditions.unit_end == UNIT_TRX_ID)) diff --git a/sql/table.cc b/sql/table.cc index 5ca8e32a6a20c..bf6084ccd865f 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -8879,15 +8879,21 @@ void vers_select_conds_t::resolve_units(bool timestamps_only) DBUG_ASSERT(start); if (unit_start == UNIT_AUTO) { - unit_start= (!timestamps_only && (start->result_type() == INT_RESULT || - start->result_type() == REAL_RESULT)) ? - UNIT_TRX_ID : UNIT_TIMESTAMP; + if (start->type() == Item::FIELD_ITEM) + unit_start= UNIT_TIMESTAMP; + else + unit_start= (!timestamps_only && (start->result_type() == INT_RESULT || + start->result_type() == REAL_RESULT)) ? + UNIT_TRX_ID : UNIT_TIMESTAMP; } if (end && unit_end == UNIT_AUTO) { - unit_end= (!timestamps_only && (end->result_type() == INT_RESULT || - end->result_type() == REAL_RESULT)) ? - UNIT_TRX_ID : UNIT_TIMESTAMP; + if (start->type() == Item::FIELD_ITEM) + unit_start= UNIT_TIMESTAMP; + else + unit_end= (!timestamps_only && (end->result_type() == INT_RESULT || + end->result_type() == REAL_RESULT)) ? + UNIT_TRX_ID : UNIT_TIMESTAMP; } }