From f9714ef6f48172778cafc4eb307b83a3a28190cd Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Wed, 15 Nov 2017 23:24:45 +0300 Subject: [PATCH] SQL: open TRT only after versioned write [#305] --- sql/handler.cc | 23 ++++++----------------- sql/handler.h | 12 +----------- sql/sql_class.cc | 7 +++++++ sql/sql_class.h | 3 +++ storage/innobase/handler/ha_innodb.cc | 9 +++++++++ storage/innobase/handler/ha_innodb.h | 2 ++ storage/innobase/handler/handler0alter.cc | 3 +++ 7 files changed, 31 insertions(+), 28 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index a345fc09e16..e3a02abedee 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1416,22 +1416,13 @@ int ha_commit_trans(THD *thd, bool all) if (rw_trans || thd->lex->sql_command == SQLCOM_ALTER_TABLE) { - for (Ha_trx_info *hi= ha_info; hi; hi= hi->next()) + if (opt_transaction_registry && thd->vers_update_trt) { - handlerton *ht= hi->ht(); - if (opt_transaction_registry && - (ht->flags & HTON_NATIVE_SYS_VERSIONING) && - (thd->lex->sql_command == SQLCOM_ALTER_TABLE ? - hi->is_trx_tmp_read_write() : - hi->is_trx_read_write())) - { - TR_table trt(thd, true); - if (trt.update()) - goto err; - if (all) - commit_one_phase_2(thd, false, &thd->transaction.stmt, false); - break; - } + TR_table trt(thd, true); + if (trt.update()) + goto err; + if (all) + commit_one_phase_2(thd, false, &thd->transaction.stmt, false); } } @@ -4075,8 +4066,6 @@ void handler::mark_trx_read_write_internal() */ if (table_share == NULL || table_share->tmp_table == NO_TMP_TABLE) ha_info->set_trx_read_write(); - else - ha_info->set_trx_tmp_read_write(); } } diff --git a/sql/handler.h b/sql/handler.h index fe64ab97deb..ac2716b4070 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1582,21 +1582,11 @@ public: DBUG_ASSERT(is_started()); m_flags|= (int) TRX_READ_WRITE; } - void set_trx_tmp_read_write() - { - DBUG_ASSERT(is_started()); - m_flags|= (int) TRX_TMP_READ_WRITE; - } bool is_trx_read_write() const { DBUG_ASSERT(is_started()); return m_flags & (int) TRX_READ_WRITE; } - bool is_trx_tmp_read_write() const - { - DBUG_ASSERT(is_started()); - return m_flags & (int) (TRX_READ_WRITE | TRX_TMP_READ_WRITE); - } bool is_started() const { return m_ht != NULL; } /** Mark this transaction read-write if the argument is read-write. */ void coalesce_trx_with(const Ha_trx_info *stmt_trx) @@ -1621,7 +1611,7 @@ public: return m_ht; } private: - enum { TRX_READ_ONLY= 0, TRX_READ_WRITE= 1, TRX_TMP_READ_WRITE= 2 }; + enum { TRX_READ_ONLY= 0, TRX_READ_WRITE= 1 }; /** Auxiliary, used for ha_list management */ Ha_trx_info *m_next; /** diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 076bd40af51..9d31e822320 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -716,6 +716,11 @@ Time_zone * thd_get_timezone(THD * thd) return thd->variables.time_zone; } +void thd_vers_update_trt(THD * thd) +{ + thd->vers_update_trt= true; +} + THD::THD(my_thread_id id, bool is_wsrep_applier) :Statement(&main_lex, &main_mem_root, STMT_CONVENTIONAL_EXECUTION, /* statement id */ 0), @@ -1348,6 +1353,8 @@ void THD::init(void) wsrep_skip_wsrep_GTID = false; #endif /* WITH_WSREP */ + vers_update_trt = false; + if (variables.sql_log_bin) variables.option_bits|= OPTION_BIN_LOG; else diff --git a/sql/sql_class.h b/sql/sql_class.h index 9431257d046..29ed2121642 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -4542,6 +4542,9 @@ public: /* Handling of timeouts for commands */ thr_timer_t query_timer; + + bool vers_update_trt; + public: void set_query_timer() { diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index ba6dc0a0964..74d969290dc 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -8380,6 +8380,9 @@ no_commit: /* Step-5: Execute insert graph that will result in actual insert. */ error = row_insert_for_mysql((byte*) record, m_prebuilt, vers_set_fields); + if (m_prebuilt->trx->vers_update_trt) + thd_vers_update_trt(m_user_thd); + DEBUG_SYNC(m_user_thd, "ib_after_row_insert"); /* Step-6: Handling of errors related to auto-increment. */ @@ -9199,6 +9202,9 @@ ha_innobase::update_row( error = row_insert_for_mysql((byte*) old_row, m_prebuilt, ROW_INS_HISTORICAL); } + if (m_prebuilt->trx->vers_update_trt) + thd_vers_update_trt(m_user_thd); + if (error == DB_SUCCESS && autoinc) { /* A value for an AUTO_INCREMENT column was specified in the UPDATE statement. */ @@ -9318,6 +9324,9 @@ ha_innobase::delete_row( error = row_update_for_mysql(m_prebuilt, vers_set_fields); + if (m_prebuilt->trx->vers_update_trt) + thd_vers_update_trt(m_user_thd); + innobase_srv_conc_exit_innodb(m_prebuilt); /* Tell the InnoDB server that there might be work for diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h index d7f5d36a680..a9dc934e21b 100644 --- a/storage/innobase/handler/ha_innodb.h +++ b/storage/innobase/handler/ha_innodb.h @@ -586,6 +586,8 @@ bool thd_is_strict_mode(const MYSQL_THD thd); */ extern void mysql_bin_log_commit_pos(THD *thd, ulonglong *out_pos, const char **out_file); +extern void thd_vers_update_trt(THD * thd); + /** Get the partition_info working copy. @param thd Thread object. @return NULL or pointer to partition_info working copy. */ diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 984c5f908b1..9d52133867d 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -7079,6 +7079,9 @@ ok_exit: ctx->m_stage, add_v, eval_table, ha_alter_info->handler_flags & Alter_inplace_info::ALTER_DROP_HISTORICAL); + if (m_prebuilt->trx->vers_update_trt) + thd_vers_update_trt(m_user_thd); + #ifndef DBUG_OFF oom: #endif /* !DBUG_OFF */