Commit f9714ef6 authored by Aleksey Midenkov's avatar Aleksey Midenkov

SQL: open TRT only after versioned write [#305]

parent a1e5b4a3
...@@ -1416,22 +1416,13 @@ int ha_commit_trans(THD *thd, bool all) ...@@ -1416,22 +1416,13 @@ int ha_commit_trans(THD *thd, bool all)
if (rw_trans || thd->lex->sql_command == SQLCOM_ALTER_TABLE) 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(); TR_table trt(thd, true);
if (opt_transaction_registry && if (trt.update())
(ht->flags & HTON_NATIVE_SYS_VERSIONING) && goto err;
(thd->lex->sql_command == SQLCOM_ALTER_TABLE ? if (all)
hi->is_trx_tmp_read_write() : commit_one_phase_2(thd, false, &thd->transaction.stmt, false);
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;
}
} }
} }
...@@ -4075,8 +4066,6 @@ void handler::mark_trx_read_write_internal() ...@@ -4075,8 +4066,6 @@ void handler::mark_trx_read_write_internal()
*/ */
if (table_share == NULL || table_share->tmp_table == NO_TMP_TABLE) if (table_share == NULL || table_share->tmp_table == NO_TMP_TABLE)
ha_info->set_trx_read_write(); ha_info->set_trx_read_write();
else
ha_info->set_trx_tmp_read_write();
} }
} }
......
...@@ -1582,21 +1582,11 @@ class Ha_trx_info ...@@ -1582,21 +1582,11 @@ class Ha_trx_info
DBUG_ASSERT(is_started()); DBUG_ASSERT(is_started());
m_flags|= (int) TRX_READ_WRITE; 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 bool is_trx_read_write() const
{ {
DBUG_ASSERT(is_started()); DBUG_ASSERT(is_started());
return m_flags & (int) TRX_READ_WRITE; 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; } bool is_started() const { return m_ht != NULL; }
/** Mark this transaction read-write if the argument is read-write. */ /** Mark this transaction read-write if the argument is read-write. */
void coalesce_trx_with(const Ha_trx_info *stmt_trx) void coalesce_trx_with(const Ha_trx_info *stmt_trx)
...@@ -1621,7 +1611,7 @@ class Ha_trx_info ...@@ -1621,7 +1611,7 @@ class Ha_trx_info
return m_ht; return m_ht;
} }
private: 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 */ /** Auxiliary, used for ha_list management */
Ha_trx_info *m_next; Ha_trx_info *m_next;
/** /**
......
...@@ -716,6 +716,11 @@ Time_zone * thd_get_timezone(THD * thd) ...@@ -716,6 +716,11 @@ Time_zone * thd_get_timezone(THD * thd)
return thd->variables.time_zone; 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) THD::THD(my_thread_id id, bool is_wsrep_applier)
:Statement(&main_lex, &main_mem_root, STMT_CONVENTIONAL_EXECUTION, :Statement(&main_lex, &main_mem_root, STMT_CONVENTIONAL_EXECUTION,
/* statement id */ 0), /* statement id */ 0),
...@@ -1348,6 +1353,8 @@ void THD::init(void) ...@@ -1348,6 +1353,8 @@ void THD::init(void)
wsrep_skip_wsrep_GTID = false; wsrep_skip_wsrep_GTID = false;
#endif /* WITH_WSREP */ #endif /* WITH_WSREP */
vers_update_trt = false;
if (variables.sql_log_bin) if (variables.sql_log_bin)
variables.option_bits|= OPTION_BIN_LOG; variables.option_bits|= OPTION_BIN_LOG;
else else
......
...@@ -4542,6 +4542,9 @@ class THD :public Statement, ...@@ -4542,6 +4542,9 @@ class THD :public Statement,
/* Handling of timeouts for commands */ /* Handling of timeouts for commands */
thr_timer_t query_timer; thr_timer_t query_timer;
bool vers_update_trt;
public: public:
void set_query_timer() void set_query_timer()
{ {
......
...@@ -8380,6 +8380,9 @@ ha_innobase::write_row( ...@@ -8380,6 +8380,9 @@ ha_innobase::write_row(
/* Step-5: Execute insert graph that will result in actual insert. */ /* Step-5: Execute insert graph that will result in actual insert. */
error = row_insert_for_mysql((byte*) record, m_prebuilt, vers_set_fields); 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"); DEBUG_SYNC(m_user_thd, "ib_after_row_insert");
/* Step-6: Handling of errors related to auto-increment. */ /* Step-6: Handling of errors related to auto-increment. */
...@@ -9199,6 +9202,9 @@ ha_innobase::update_row( ...@@ -9199,6 +9202,9 @@ ha_innobase::update_row(
error = row_insert_for_mysql((byte*) old_row, m_prebuilt, ROW_INS_HISTORICAL); 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) { if (error == DB_SUCCESS && autoinc) {
/* A value for an AUTO_INCREMENT column /* A value for an AUTO_INCREMENT column
was specified in the UPDATE statement. */ was specified in the UPDATE statement. */
...@@ -9318,6 +9324,9 @@ ha_innobase::delete_row( ...@@ -9318,6 +9324,9 @@ ha_innobase::delete_row(
error = row_update_for_mysql(m_prebuilt, vers_set_fields); 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); innobase_srv_conc_exit_innodb(m_prebuilt);
/* Tell the InnoDB server that there might be work for /* Tell the InnoDB server that there might be work for
......
...@@ -586,6 +586,8 @@ bool thd_is_strict_mode(const MYSQL_THD thd); ...@@ -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 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. /** Get the partition_info working copy.
@param thd Thread object. @param thd Thread object.
@return NULL or pointer to partition_info working copy. */ @return NULL or pointer to partition_info working copy. */
......
...@@ -7079,6 +7079,9 @@ ha_innobase::inplace_alter_table( ...@@ -7079,6 +7079,9 @@ ha_innobase::inplace_alter_table(
ctx->m_stage, add_v, eval_table, ctx->m_stage, add_v, eval_table,
ha_alter_info->handler_flags & Alter_inplace_info::ALTER_DROP_HISTORICAL); 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 #ifndef DBUG_OFF
oom: oom:
#endif /* !DBUG_OFF */ #endif /* !DBUG_OFF */
......
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