diff --git a/mysql-test/suite/versioning/r/truncate_history.result b/mysql-test/suite/versioning/r/truncate_history.result index 4194406fa16..e0bf8816483 100644 --- a/mysql-test/suite/versioning/r/truncate_history.result +++ b/mysql-test/suite/versioning/r/truncate_history.result @@ -149,6 +149,7 @@ a 2 select * from t for system_time before timestamp @ts1; a +1 select * from t for system_time before transaction 2000; a 1 @@ -158,13 +159,11 @@ select * from t for system_time all; a 11 22 -1 2 truncate t for system_time before timestamp now(6); select * from t for system_time all; a 11 22 -2 drop table t; drop procedure truncate_history_of_t; diff --git a/sql/sql_class.h b/sql/sql_class.h index e3601f141fa..303992c40d8 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -710,6 +710,7 @@ typedef struct system_variables st_vers_current_time vers_current_time; my_bool vers_force; ulong vers_hide; + my_bool vers_innodb_algorithm_simple; } SV; /** diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 45dc3ea4583..578fdc753a7 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -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) { 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); 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) { @@ -839,8 +840,9 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr, DBUG_RETURN(-1); } } - else if (vers_simple_select && vers_conditions.unit == UNIT_TIMESTAMP - && vers_conditions.type != FOR_SYSTEM_TIME_UNSPECIFIED) + else if (thd->variables.vers_innodb_algorithm_simple && + vers_conditions.unit == UNIT_TIMESTAMP && + vers_conditions.type != FOR_SYSTEM_TIME_UNSPECIFIED) { DBUG_ASSERT(table->table->s && 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; - // Temporary tables of type HEAP can be created from INNODB tables and - // thus will have uint64 type of sys_trx_(start|end) field. + // Temporary tables of can be created from INNODB tables and thus will + // have uint64 type of sys_trx_(start|end) field. // They need special handling. TABLE *t= table->table; - if ((t->s->table_category == TABLE_CATEGORY_TEMPORARY - ? t->vers_start_field()->type() != MYSQL_TYPE_LONGLONG - : t->versioned_by_sql()) || - vers_simple_select) + if (tmp_from_ib || t->versioned_by_sql() || + thd->variables.vers_innodb_algorithm_simple) { switch (vers_conditions.type) { case FOR_SYSTEM_TIME_UNSPECIFIED: - if (table->table->versioned_by_sql()) + if (table->table->versioned_by_sql() && !tmp_from_ib) { MYSQL_TIME max_time; thd->variables.time_zone->gmt_sec_to_TIME(&max_time, TIMESTAMP_MAX_VALUE); diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 0b80684cd77..f1a674388fc 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -400,6 +400,12 @@ static Sys_var_enum Sys_vers_hide( "NEVER: don't hide system fields", 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( "binlog_cache_size", "The size of the transactional cache for " "updates to transactional engines for the binary log. " diff --git a/storage/heap/ha_heap.cc b/storage/heap/ha_heap.cc index e87c878d11b..b37ddd1bcb7 100644 --- a/storage/heap/ha_heap.cc +++ b/storage/heap/ha_heap.cc @@ -27,6 +27,9 @@ #include "heapdef.h" #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, TABLE_SHARE *table, MEM_ROOT *mem_root); @@ -56,6 +59,8 @@ int heap_init(void *p) heap_hton->panic= heap_panic; heap_hton->flags= HTON_CAN_RECREATE; + heap_hton->vers_query_trx_id = vtq_query_trx_id; + return 0; }