1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

SQL: Default 'simple' algorithm for InnoDB 'AS OF' [closes #175]

This commit is contained in:
kevg
2017-04-11 19:37:48 +03:00
committed by Aleksey Midenkov
parent a1d42a6f20
commit ecc6cd95c4
5 changed files with 25 additions and 14 deletions

View File

@ -149,6 +149,7 @@ a
2 2
select * from t for system_time before timestamp @ts1; select * from t for system_time before timestamp @ts1;
a a
1
select * from t for system_time before transaction 2000; select * from t for system_time before transaction 2000;
a a
1 1
@ -158,13 +159,11 @@ select * from t for system_time all;
a a
11 11
22 22
1
2 2
truncate t for system_time before timestamp now(6); truncate t for system_time before timestamp now(6);
select * from t for system_time all; select * from t for system_time all;
a a
11 11
22 22
2
drop table t; drop table t;
drop procedure truncate_history_of_t; drop procedure truncate_history_of_t;

View File

@ -710,6 +710,7 @@ typedef struct system_variables
st_vers_current_time vers_current_time; st_vers_current_time vers_current_time;
my_bool vers_force; my_bool vers_force;
ulong vers_hide; ulong vers_hide;
my_bool vers_innodb_algorithm_simple;
} SV; } SV;
/** /**

View File

@ -771,8 +771,6 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
} }
} }
const static bool vers_simple_select= false;
for (table= tables; table; table= table->next_local) for (table= tables; table; table= table->next_local)
{ {
if (table->table && table->table->versioned()) if (table->table && table->table->versioned())
@ -831,7 +829,10 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
newx Item_field(thd, &slex->context, table->db, table->alias, fend); newx Item_field(thd, &slex->context, table->db, table->alias, fend);
Item *row_end2= row_end; Item *row_end2= row_end;
if (table->table->versioned_by_sql()) bool tmp_from_ib=
table->table->s->table_category == TABLE_CATEGORY_TEMPORARY &&
table->table->vers_start_field()->type() == MYSQL_TYPE_LONGLONG;
if (table->table->versioned_by_sql() && !tmp_from_ib)
{ {
if (vers_conditions.unit == UNIT_TRX_ID) if (vers_conditions.unit == UNIT_TRX_ID)
{ {
@ -839,8 +840,9 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
} }
else if (vers_simple_select && vers_conditions.unit == UNIT_TIMESTAMP else if (thd->variables.vers_innodb_algorithm_simple &&
&& vers_conditions.type != FOR_SYSTEM_TIME_UNSPECIFIED) vers_conditions.unit == UNIT_TIMESTAMP &&
vers_conditions.type != FOR_SYSTEM_TIME_UNSPECIFIED)
{ {
DBUG_ASSERT(table->table->s && table->table->s->db_plugin); DBUG_ASSERT(table->table->s && table->table->s->db_plugin);
handlerton *hton= plugin_hton(table->table->s->db_plugin); handlerton *hton= plugin_hton(table->table->s->db_plugin);
@ -859,19 +861,17 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
} }
Item *cond1= 0, *cond2= 0, *curr= 0; Item *cond1= 0, *cond2= 0, *curr= 0;
// Temporary tables of type HEAP can be created from INNODB tables and // Temporary tables of can be created from INNODB tables and thus will
// thus will have uint64 type of sys_trx_(start|end) field. // have uint64 type of sys_trx_(start|end) field.
// They need special handling. // They need special handling.
TABLE *t= table->table; TABLE *t= table->table;
if ((t->s->table_category == TABLE_CATEGORY_TEMPORARY if (tmp_from_ib || t->versioned_by_sql() ||
? t->vers_start_field()->type() != MYSQL_TYPE_LONGLONG thd->variables.vers_innodb_algorithm_simple)
: t->versioned_by_sql()) ||
vers_simple_select)
{ {
switch (vers_conditions.type) switch (vers_conditions.type)
{ {
case FOR_SYSTEM_TIME_UNSPECIFIED: case FOR_SYSTEM_TIME_UNSPECIFIED:
if (table->table->versioned_by_sql()) if (table->table->versioned_by_sql() && !tmp_from_ib)
{ {
MYSQL_TIME max_time; 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);

View File

@ -400,6 +400,12 @@ static Sys_var_enum Sys_vers_hide(
"NEVER: don't hide system fields", "NEVER: don't hide system fields",
SESSION_VAR(vers_hide), CMD_LINE(OPT_ARG), vers_hide_keywords, DEFAULT(VERS_HIDE_AUTO)); SESSION_VAR(vers_hide), CMD_LINE(OPT_ARG), vers_hide_keywords, DEFAULT(VERS_HIDE_AUTO));
static Sys_var_mybool Sys_vers_innodb_algorithm_simple(
"vers_innodb_algorithm_simple",
"Use simple algorithm of timestamp handling in InnoDB instead of TRX_SEES",
SESSION_VAR(vers_innodb_algorithm_simple), CMD_LINE(OPT_ARG),
DEFAULT(TRUE));
static Sys_var_ulonglong Sys_binlog_cache_size( static Sys_var_ulonglong Sys_binlog_cache_size(
"binlog_cache_size", "The size of the transactional cache for " "binlog_cache_size", "The size of the transactional cache for "
"updates to transactional engines for the binary log. " "updates to transactional engines for the binary log. "

View File

@ -27,6 +27,9 @@
#include "heapdef.h" #include "heapdef.h"
#include "sql_base.h" // enum_tdc_remove_table_type #include "sql_base.h" // enum_tdc_remove_table_type
bool vtq_query_trx_id(THD *thd, void *out, ulonglong in_trx_id,
vtq_field_t field);
static handler *heap_create_handler(handlerton *hton, static handler *heap_create_handler(handlerton *hton,
TABLE_SHARE *table, TABLE_SHARE *table,
MEM_ROOT *mem_root); MEM_ROOT *mem_root);
@ -56,6 +59,8 @@ int heap_init(void *p)
heap_hton->panic= heap_panic; heap_hton->panic= heap_panic;
heap_hton->flags= HTON_CAN_RECREATE; heap_hton->flags= HTON_CAN_RECREATE;
heap_hton->vers_query_trx_id = vtq_query_trx_id;
return 0; return 0;
} }