mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-14645: AS OF TIMESTAMP is misused as TRX_ID
Remove 1668efb722
that introduced a special magic
behavior for UNIX_TIMESTAMP() in the AS OF context
This commit is contained in:
@@ -211,12 +211,12 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
|
|||||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where
|
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where
|
||||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join)
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join)
|
||||||
Query A:
|
Query A:
|
||||||
Note 1003 select `test`.`t1`.`x` AS `x`,`test`.`t1`.`y` AS `y1`,`test`.`t2`.`x` AS `x2`,`test`.`t2`.`y` AS `y2` from `test`.`t1` FOR SYSTEM_TIME ALL join `test`.`t2` FOR SYSTEM_TIME ALL where `test`.`t1`.`x` = `test`.`t2`.`x` and `test`.`t1`.`row_end` > <cache>(cast(current_timestamp(6) as datetime(6))) and `test`.`t1`.`row_start` <= <cache>(cast(current_timestamp(6) as datetime(6))) and `test`.`t2`.`row_end` > <cache>(cast(current_timestamp(6) as datetime(6))) and `test`.`t2`.`row_start` <= <cache>(cast(current_timestamp(6) as datetime(6)))
|
Note 1003 select `test`.`t1`.`x` AS `x`,`test`.`t1`.`y` AS `y1`,`test`.`t2`.`x` AS `x2`,`test`.`t2`.`y` AS `y2` from `test`.`t1` FOR SYSTEM_TIME ALL join `test`.`t2` FOR SYSTEM_TIME ALL where `test`.`t1`.`x` = `test`.`t2`.`x` and `test`.`t1`.`row_end` > <cache>(current_timestamp(6)) and `test`.`t1`.`row_start` <= <cache>(current_timestamp(6)) and `test`.`t2`.`row_end` > <cache>(current_timestamp(6)) and `test`.`t2`.`row_start` <= <cache>(current_timestamp(6))
|
||||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where
|
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where
|
||||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join)
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join)
|
||||||
Query B:
|
Query B:
|
||||||
Note 1003 select `test`.`t1`.`x` AS `x`,`test`.`t1`.`y` AS `y1`,`test`.`t2`.`x` AS `x2`,`test`.`t2`.`y` AS `y2` from `test`.`t1` FOR SYSTEM_TIME ALL join `test`.`t2` FOR SYSTEM_TIME ALL where `test`.`t1`.`x` = `test`.`t2`.`x` and `test`.`t1`.`row_end` > <cache>(cast(current_timestamp(6) as datetime(6))) and `test`.`t1`.`row_start` <= <cache>(cast(current_timestamp(6) as datetime(6))) and `test`.`t2`.`row_end` > <cache>(cast(current_timestamp(6) as datetime(6))) and `test`.`t2`.`row_start` <= <cache>(cast(current_timestamp(6) as datetime(6)))
|
Note 1003 select `test`.`t1`.`x` AS `x`,`test`.`t1`.`y` AS `y1`,`test`.`t2`.`x` AS `x2`,`test`.`t2`.`y` AS `y2` from `test`.`t1` FOR SYSTEM_TIME ALL join `test`.`t2` FOR SYSTEM_TIME ALL where `test`.`t1`.`x` = `test`.`t2`.`x` and `test`.`t1`.`row_end` > <cache>(current_timestamp(6)) and `test`.`t1`.`row_start` <= <cache>(current_timestamp(6)) and `test`.`t2`.`row_end` > <cache>(current_timestamp(6)) and `test`.`t2`.`row_start` <= <cache>(current_timestamp(6))
|
||||||
Fine result: queries A and B are equal.
|
Fine result: queries A and B are equal.
|
||||||
## LEFT JOIN: t1, t2 versioned
|
## LEFT JOIN: t1, t2 versioned
|
||||||
select * from (
|
select * from (
|
||||||
|
@@ -153,21 +153,21 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
|
|||||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where
|
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where
|
||||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join)
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join)
|
||||||
Warnings:
|
Warnings:
|
||||||
Note 1003 select `test`.`t1`.`x` AS `IJ2_x1`,`test`.`t1`.`y` AS `y1`,`test`.`t2`.`x` AS `x2`,`test`.`t2`.`y` AS `y2` from `test`.`t1` FOR SYSTEM_TIME ALL join `test`.`t2` FOR SYSTEM_TIME ALL where `test`.`t1`.`x` = `test`.`t2`.`x` and `test`.`t1`.`row_end` > <cache>(cast(@`t0` as datetime(6))) and `test`.`t1`.`row_start` <= <cache>(cast(@`t0` as datetime(6))) and `test`.`t2`.`row_end` > <cache>(cast(@`t0` as datetime(6))) and `test`.`t2`.`row_start` <= <cache>(cast(@`t0` as datetime(6)))
|
Note 1003 select `test`.`t1`.`x` AS `IJ2_x1`,`test`.`t1`.`y` AS `y1`,`test`.`t2`.`x` AS `x2`,`test`.`t2`.`y` AS `y2` from `test`.`t1` FOR SYSTEM_TIME ALL join `test`.`t2` FOR SYSTEM_TIME ALL where `test`.`t1`.`x` = `test`.`t2`.`x` and `test`.`t1`.`row_end` > @`t0` and `test`.`t1`.`row_start` <= @`t0` and `test`.`t2`.`row_end` > @`t0` and `test`.`t2`.`row_start` <= @`t0`
|
||||||
explain extended select * from (select t1.x as LJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x)
|
explain extended select * from (select t1.x as LJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x)
|
||||||
for system_time as of timestamp @t0 as t;
|
for system_time as of timestamp @t0 as t;
|
||||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00
|
||||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
|
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join)
|
||||||
Warnings:
|
Warnings:
|
||||||
Note 1003 select `test`.`t1`.`x` AS `LJ2_x1`,`test`.`t1`.`y` AS `y1`,`test`.`t2`.`x` AS `x2`,`test`.`t2`.`y` AS `y2` from `test`.`t1` FOR SYSTEM_TIME ALL left join `test`.`t2` FOR SYSTEM_TIME ALL on(`test`.`t2`.`x` = `test`.`t1`.`x` and `test`.`t1`.`row_end` > <cache>(cast(@`t0` as datetime(6))) and `test`.`t1`.`row_start` <= <cache>(cast(@`t0` as datetime(6))) and `test`.`t2`.`row_end` > <cache>(cast(@`t0` as datetime(6))) and `test`.`t2`.`row_start` <= <cache>(cast(@`t0` as datetime(6)))) where 1
|
Note 1003 select `test`.`t1`.`x` AS `LJ2_x1`,`test`.`t1`.`y` AS `y1`,`test`.`t2`.`x` AS `x2`,`test`.`t2`.`y` AS `y2` from `test`.`t1` FOR SYSTEM_TIME ALL left join `test`.`t2` FOR SYSTEM_TIME ALL on(`test`.`t2`.`x` = `test`.`t1`.`x` and `test`.`t1`.`row_end` > @`t0` and `test`.`t1`.`row_start` <= @`t0` and `test`.`t2`.`row_end` > @`t0` and `test`.`t2`.`row_start` <= @`t0`) where 1
|
||||||
explain extended select * from (select t1.x as RJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x)
|
explain extended select * from (select t1.x as RJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x)
|
||||||
for system_time as of timestamp @t0 as t;
|
for system_time as of timestamp @t0 as t;
|
||||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
|
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00
|
||||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join)
|
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join)
|
||||||
Warnings:
|
Warnings:
|
||||||
Note 1003 select `test`.`t1`.`x` AS `RJ2_x1`,`test`.`t1`.`y` AS `y1`,`test`.`t2`.`x` AS `x2`,`test`.`t2`.`y` AS `y2` from `test`.`t2` FOR SYSTEM_TIME ALL left join `test`.`t1` FOR SYSTEM_TIME ALL on(`test`.`t1`.`x` = `test`.`t2`.`x` and `test`.`t1`.`row_end` > <cache>(cast(@`t0` as datetime(6))) and `test`.`t1`.`row_start` <= <cache>(cast(@`t0` as datetime(6))) and `test`.`t2`.`row_end` > <cache>(cast(@`t0` as datetime(6))) and `test`.`t2`.`row_start` <= <cache>(cast(@`t0` as datetime(6)))) where 1
|
Note 1003 select `test`.`t1`.`x` AS `RJ2_x1`,`test`.`t1`.`y` AS `y1`,`test`.`t2`.`x` AS `x2`,`test`.`t2`.`y` AS `y2` from `test`.`t2` FOR SYSTEM_TIME ALL left join `test`.`t1` FOR SYSTEM_TIME ALL on(`test`.`t1`.`x` = `test`.`t2`.`x` and `test`.`t1`.`row_end` > @`t0` and `test`.`t1`.`row_start` <= @`t0` and `test`.`t2`.`row_end` > @`t0` and `test`.`t2`.`row_start` <= @`t0`) where 1
|
||||||
select * from (select t1.x as IJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x)
|
select * from (select t1.x as IJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x)
|
||||||
for system_time as of timestamp @t0 as t;
|
for system_time as of timestamp @t0 as t;
|
||||||
IJ2_x1 y1 x2 y2
|
IJ2_x1 y1 x2 y2
|
||||||
|
@@ -226,7 +226,6 @@ select x from t1 for system_time as of transaction @trx_start;
|
|||||||
select x from t1 for system_time as of @ts;
|
select x from t1 for system_time as of @ts;
|
||||||
select x from t1 for system_time as of @trx_start;
|
select x from t1 for system_time as of @trx_start;
|
||||||
|
|
||||||
|
|
||||||
--echo ### Issue #365, bug 4 (related to #226, optimized fields)
|
--echo ### Issue #365, bug 4 (related to #226, optimized fields)
|
||||||
create or replace table t1 (i int, b int) with system versioning;
|
create or replace table t1 (i int, b int) with system versioning;
|
||||||
insert into t1 values (0, 0), (0, 0);
|
insert into t1 values (0, 0), (0, 0);
|
||||||
|
@@ -1005,31 +1005,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Item_longlong_typecast :public Item_int_func
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Item_longlong_typecast(THD *thd, Item *a): Item_int_func(thd, a)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
const char *func_name() const { return "cast_as_longlong"; }
|
|
||||||
const char *cast_type() const { return "longlong"; }
|
|
||||||
const Type_handler *type_handler() const { return &type_handler_longlong; }
|
|
||||||
longlong val_int()
|
|
||||||
{
|
|
||||||
return args[0]->val_int();
|
|
||||||
}
|
|
||||||
void fix_length_and_dec_generic() {}
|
|
||||||
void fix_length_and_dec()
|
|
||||||
{
|
|
||||||
args[0]->type_handler()->Item_longlong_typecast_fix_length_and_dec(this);
|
|
||||||
}
|
|
||||||
bool need_parentheses_in_default() { return true; }
|
|
||||||
Item *get_copy(THD *thd)
|
|
||||||
{ return get_item_copy<Item_longlong_typecast>(thd, this); }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Item_func_additive_op :public Item_num_op
|
class Item_func_additive_op :public Item_num_op
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -2642,27 +2642,6 @@ bool Item_datetime_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Item_datetime_from_unixtime_typecast::fix_length_and_dec()
|
|
||||||
{
|
|
||||||
Item_datetime_typecast::fix_length_and_dec();
|
|
||||||
|
|
||||||
switch (args[0]->result_type())
|
|
||||||
{
|
|
||||||
case INT_RESULT:
|
|
||||||
case REAL_RESULT:
|
|
||||||
case DECIMAL_RESULT:
|
|
||||||
{
|
|
||||||
Query_arena_stmt on_stmt_arena(thd);
|
|
||||||
Item_func_from_unixtime *a= new (thd->mem_root) Item_func_from_unixtime(thd, args[0]);
|
|
||||||
a->fix_length_and_dec();
|
|
||||||
args[0]= a;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
MAKEDATE(a,b) is a date function that creates a date value
|
MAKEDATE(a,b) is a date function that creates a date value
|
||||||
from a year and day value.
|
from a year and day value.
|
||||||
|
@@ -1192,20 +1192,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Item_datetime_from_unixtime_typecast :public Item_datetime_typecast
|
|
||||||
{
|
|
||||||
THD *thd;
|
|
||||||
public:
|
|
||||||
Item_datetime_from_unixtime_typecast(THD *_thd, Item *a, uint dec_arg):
|
|
||||||
Item_datetime_typecast(_thd, a, dec_arg), thd(_thd) {}
|
|
||||||
const char *func_name() const { return "cast_as_datetime_from_unixtime"; }
|
|
||||||
const char *cast_type() const { return "datetime"; }
|
|
||||||
void fix_length_and_dec();
|
|
||||||
Item *get_copy(THD *thd)
|
|
||||||
{ return get_item_copy<Item_datetime_from_unixtime_typecast>(thd, this); }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class Item_func_makedate :public Item_datefunc
|
class Item_func_makedate :public Item_datefunc
|
||||||
{
|
{
|
||||||
bool check_arguments() const
|
bool check_arguments() const
|
||||||
|
@@ -867,28 +867,14 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables, COND **where_expr
|
|||||||
TABLE *t= table->table;
|
TABLE *t= table->table;
|
||||||
if (t->versioned(VERS_TIMESTAMP))
|
if (t->versioned(VERS_TIMESTAMP))
|
||||||
{
|
{
|
||||||
if (vers_conditions)
|
MYSQL_TIME max_time;
|
||||||
{
|
|
||||||
vers_conditions.start.add_typecast(thd, t->s->versioned);
|
|
||||||
vers_conditions.end.add_typecast(thd, t->s->versioned);
|
|
||||||
}
|
|
||||||
switch (vers_conditions.type)
|
switch (vers_conditions.type)
|
||||||
{
|
{
|
||||||
case SYSTEM_TIME_UNSPECIFIED:
|
case SYSTEM_TIME_UNSPECIFIED:
|
||||||
if (t->vers_start_field()->real_type() != MYSQL_TYPE_LONGLONG)
|
|
||||||
{
|
|
||||||
MYSQL_TIME max_time;
|
|
||||||
thd->variables.time_zone->gmt_sec_to_TIME(&max_time, TIMESTAMP_MAX_VALUE);
|
thd->variables.time_zone->gmt_sec_to_TIME(&max_time, TIMESTAMP_MAX_VALUE);
|
||||||
max_time.second_part= TIME_MAX_SECOND_PART;
|
max_time.second_part= TIME_MAX_SECOND_PART;
|
||||||
curr= newx Item_datetime_literal(thd, &max_time,
|
curr= newx Item_datetime_literal(thd, &max_time, TIME_SECOND_PART_DIGITS);
|
||||||
TIME_SECOND_PART_DIGITS);
|
|
||||||
cond1= newx Item_func_eq(thd, row_end, curr);
|
cond1= newx Item_func_eq(thd, row_end, curr);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
curr= newx Item_int(thd, ULONGLONG_MAX);
|
|
||||||
cond1= newx Item_func_eq(thd, row_end, curr);
|
|
||||||
}
|
|
||||||
cond1= or_items(thd, cond1, newx Item_func_isnull(thd, row_end));
|
cond1= or_items(thd, cond1, newx Item_func_isnull(thd, row_end));
|
||||||
break;
|
break;
|
||||||
case SYSTEM_TIME_AS_OF:
|
case SYSTEM_TIME_AS_OF:
|
||||||
|
@@ -4590,14 +4590,6 @@ bool Type_handler::
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Type_handler::
|
|
||||||
Item_longlong_typecast_fix_length_and_dec(Item_longlong_typecast *item) const
|
|
||||||
{
|
|
||||||
item->fix_length_and_dec_generic();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_SPATIAL
|
#ifdef HAVE_SPATIAL
|
||||||
|
|
||||||
bool Type_handler_geometry::
|
bool Type_handler_geometry::
|
||||||
|
@@ -55,7 +55,6 @@ class Item_char_typecast;
|
|||||||
class Item_time_typecast;
|
class Item_time_typecast;
|
||||||
class Item_date_typecast;
|
class Item_date_typecast;
|
||||||
class Item_datetime_typecast;
|
class Item_datetime_typecast;
|
||||||
class Item_longlong_typecast;
|
|
||||||
class Item_func_plus;
|
class Item_func_plus;
|
||||||
class Item_func_minus;
|
class Item_func_minus;
|
||||||
class Item_func_mul;
|
class Item_func_mul;
|
||||||
@@ -1332,8 +1331,6 @@ public:
|
|||||||
Item_date_typecast_fix_length_and_dec(Item_date_typecast *item) const;
|
Item_date_typecast_fix_length_and_dec(Item_date_typecast *item) const;
|
||||||
virtual bool
|
virtual bool
|
||||||
Item_datetime_typecast_fix_length_and_dec(Item_datetime_typecast *item) const;
|
Item_datetime_typecast_fix_length_and_dec(Item_datetime_typecast *item) const;
|
||||||
virtual bool
|
|
||||||
Item_longlong_typecast_fix_length_and_dec(Item_longlong_typecast *item) const;
|
|
||||||
|
|
||||||
virtual bool
|
virtual bool
|
||||||
Item_func_plus_fix_length_and_dec(Item_func_plus *func) const= 0;
|
Item_func_plus_fix_length_and_dec(Item_func_plus *func) const= 0;
|
||||||
|
22
sql/table.cc
22
sql/table.cc
@@ -8910,28 +8910,6 @@ void Vers_history_point::fix_item()
|
|||||||
item->decimals= 6;
|
item->decimals= 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vers_history_point::add_typecast(THD *thd, enum vers_sys_type_t defunit)
|
|
||||||
{
|
|
||||||
if (item)
|
|
||||||
{
|
|
||||||
if (!unit)
|
|
||||||
unit= defunit;
|
|
||||||
switch (unit)
|
|
||||||
{
|
|
||||||
case VERS_TIMESTAMP:
|
|
||||||
item= new (thd->mem_root) Item_datetime_from_unixtime_typecast(
|
|
||||||
thd, item, MAX_DATETIME_PRECISION);
|
|
||||||
break;
|
|
||||||
case VERS_TRX_ID:
|
|
||||||
item= new (thd->mem_root) Item_longlong_typecast(thd, item);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
DBUG_ASSERT(0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Vers_history_point::print(String *str, enum_query_type query_type,
|
void Vers_history_point::print(String *str, enum_query_type query_type,
|
||||||
const char *prefix, size_t plen)
|
const char *prefix, size_t plen)
|
||||||
{
|
{
|
||||||
|
@@ -1840,7 +1840,6 @@ public:
|
|||||||
void empty() { unit= VERS_UNDEFINED; item= NULL; }
|
void empty() { unit= VERS_UNDEFINED; item= NULL; }
|
||||||
void print(String *str, enum_query_type, const char *prefix, size_t plen);
|
void print(String *str, enum_query_type, const char *prefix, size_t plen);
|
||||||
void resolve_unit(bool timestamps_only);
|
void resolve_unit(bool timestamps_only);
|
||||||
void add_typecast(THD *thd, enum vers_sys_type_t defunit);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct vers_select_conds_t
|
struct vers_select_conds_t
|
||||||
|
Reference in New Issue
Block a user