Skip to content

Commit

Permalink
SQL: unit resolution Item_field not yet accessible [fixes #398]
Browse files Browse the repository at this point in the history
  • Loading branch information
midenok committed Dec 14, 2017
1 parent 1668efb commit f96815f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
6 changes: 6 additions & 0 deletions mysql-test/suite/versioning/r/select.result
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions mysql-test/suite/versioning/t/select.test
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions sql/sql_select.cc
Expand Up @@ -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))
Expand Down
18 changes: 12 additions & 6 deletions sql/table.cc
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit f96815f

Please sign in to comment.