Commit f96815fe authored by Aleksey Midenkov's avatar Aleksey Midenkov

SQL: unit resolution Item_field not yet accessible [fixes #398]

parent 1668efb7
......@@ -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);
......
......@@ -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;
......
......@@ -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))
......
......@@ -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;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment