Commit 411a8195 authored by Konstantin Osipov's avatar Konstantin Osipov

------------------------------------------------------------

revno: 2617.22.4
committer: Davi Arnaut <Davi.Arnaut@Sun.COM>
branch nick: mysql-6.0-runtime
timestamp: Mon 2009-01-26 15:19:14 -0200
message:
Move checks for OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN to a separate
helper function.


sql/ha_ndbcluster.cc:
  Use helper method to check transaction mode.
sql/log.cc:
  Use helper method to check transaction mode.
sql/sql_cache.cc:
  Use helper method to check transaction mode.
sql/sql_class.cc:
  Use helper method to check transaction mode.
sql/sql_class.h:
  Add helper method to check whether session is in a multi-statement
  transaction.
sql/sql_parse.cc:
  Use helper method to check transaction mode.
sql/transaction.cc:
  Use helper method to check transaction mode.
parent cd155be5
......@@ -4512,7 +4512,7 @@ int ha_ndbcluster::start_statement(THD *thd,
trans_register_ha(thd, FALSE, ndbcluster_hton);
if (!thd_ndb->trans)
{
if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
if (thd->in_multi_stmt_transaction())
trans_register_ha(thd, TRUE, ndbcluster_hton);
DBUG_PRINT("trans",("Starting transaction"));
thd_ndb->trans= ndb->startTransaction();
......@@ -4582,7 +4582,7 @@ int ha_ndbcluster::init_handler_for_statement(THD *thd, Thd_ndb *thd_ndb)
}
#endif
if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
if (thd->in_multi_stmt_transaction())
{
const void *key= m_table;
HASH_SEARCH_STATE state;
......@@ -4666,7 +4666,7 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type)
if (ndb_cache_check_time && m_rows_changed)
{
DBUG_PRINT("info", ("Rows has changed and util thread is running"));
if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
if (thd->in_multi_stmt_transaction())
{
DBUG_PRINT("info", ("Add share to list of tables to be invalidated"));
/* NOTE push_back allocates memory using transactions mem_root! */
......@@ -4685,7 +4685,7 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type)
DBUG_PRINT("trans", ("Last external_lock"));
PRINT_OPTION_FLAGS(thd);
if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
if (!thd->in_multi_stmt_transaction())
{
if (thd_ndb->trans)
{
......@@ -4795,8 +4795,7 @@ static int ndbcluster_commit(handlerton *hton, THD *thd, bool all)
PRINT_OPTION_FLAGS(thd);
DBUG_PRINT("enter", ("Commit %s", (all ? "all" : "stmt")));
thd_ndb->start_stmt_count= 0;
if (trans == NULL || (!all &&
thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
if (trans == NULL || (!all && thd->in_multi_stmt_transaction()))
{
/*
An odditity in the handler interface is that commit on handlerton
......@@ -4866,7 +4865,7 @@ static int ndbcluster_rollback(handlerton *hton, THD *thd, bool all)
DBUG_ASSERT(ndb);
thd_ndb->start_stmt_count= 0;
if (trans == NULL || (!all &&
thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
thd->in_multi_stmt_transaction()))
{
/* Ignore end-of-statement until real rollback or commit is called */
DBUG_PRINT("info", ("Rollback before start or end-of-statement only"));
......@@ -8041,17 +8040,15 @@ ndbcluster_cache_retrieval_allowed(THD *thd,
ulonglong *engine_data)
{
Uint64 commit_count;
bool is_autocommit= !(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
char *dbname= full_name;
char *tabname= dbname+strlen(dbname)+1;
#ifndef DBUG_OFF
char buff[22], buff2[22];
#endif
DBUG_ENTER("ndbcluster_cache_retrieval_allowed");
DBUG_PRINT("enter", ("dbname: %s, tabname: %s, is_autocommit: %d",
dbname, tabname, is_autocommit));
DBUG_PRINT("enter", ("dbname: %s, tabname: %s", dbname, tabname));
if (!is_autocommit)
if (thd->in_multi_stmt_transaction())
{
DBUG_PRINT("exit", ("No, don't use cache in transaction"));
DBUG_RETURN(FALSE);
......@@ -8116,12 +8113,10 @@ ha_ndbcluster::register_query_cache_table(THD *thd,
#ifndef DBUG_OFF
char buff[22];
#endif
bool is_autocommit= !(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
DBUG_ENTER("ha_ndbcluster::register_query_cache_table");
DBUG_PRINT("enter",("dbname: %s, tabname: %s, is_autocommit: %d",
m_dbname, m_tabname, is_autocommit));
DBUG_PRINT("enter",("dbname: %s, tabname: %s", m_dbname, m_tabname));
if (!is_autocommit)
if (thd->in_multi_stmt_transaction())
{
DBUG_PRINT("exit", ("Can't register table during transaction"));
DBUG_RETURN(FALSE);
......
......@@ -1503,7 +1503,7 @@ binlog_end_trans(THD *thd, binlog_trx_data *trx_data,
transaction cache to remove the statement.
*/
thd->binlog_remove_pending_rows_event(TRUE);
if (all || !(thd->options & (OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT)))
if (all || !thd->in_multi_stmt_transaction())
{
if (trx_data->has_incident())
mysql_bin_log.write_incident(thd, TRUE);
......@@ -1571,8 +1571,7 @@ static int binlog_commit(handlerton *hton, THD *thd, bool all)
Otherwise, we accumulate the statement
*/
ulonglong const in_transaction=
thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN);
bool const in_transaction= thd->in_multi_stmt_transaction();
DBUG_PRINT("debug",
("all: %d, empty: %s, in_transaction: %s, all.modified_non_trans_table: %s, stmt.modified_non_trans_table: %s",
all,
......@@ -3903,7 +3902,7 @@ THD::binlog_start_trans_and_stmt()
trx_data->before_stmt_pos == MY_OFF_T_UNDEF)
{
this->binlog_set_stmt_begin();
if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
if (in_multi_stmt_transaction())
trans_register_ha(this, TRUE, binlog_hton);
trans_register_ha(this, FALSE, binlog_hton);
/*
......
......@@ -1517,7 +1517,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
}
DBUG_PRINT("qcache", ("Query have result 0x%lx", (ulong) query));
if ((thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
if (thd->in_multi_stmt_transaction() &&
(query->tables_type() & HA_CACHE_TBL_TRANSACT))
{
DBUG_PRINT("qcache",
......@@ -1674,8 +1674,7 @@ void Query_cache::invalidate(THD *thd, TABLE_LIST *tables_used,
if (is_disabled())
DBUG_VOID_RETURN;
using_transactions= using_transactions &&
(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
using_transactions= using_transactions && thd->in_multi_stmt_transaction();
for (; tables_used; tables_used= tables_used->next_local)
{
DBUG_ASSERT(!using_transactions || tables_used->table!=0);
......@@ -1759,8 +1758,7 @@ void Query_cache::invalidate(THD *thd, TABLE *table,
if (is_disabled())
DBUG_VOID_RETURN;
using_transactions= using_transactions &&
(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
using_transactions= using_transactions && thd->in_multi_stmt_transaction();
if (using_transactions &&
(table->file->table_cache_type() == HA_CACHE_TBL_TRANSACT))
thd->add_changed_table(table);
......@@ -1778,8 +1776,7 @@ void Query_cache::invalidate(THD *thd, const char *key, uint32 key_length,
if (is_disabled())
DBUG_VOID_RETURN;
using_transactions= using_transactions &&
(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
using_transactions= using_transactions && thd->in_multi_stmt_transaction();
if (using_transactions) // used for innodb => has_transactions() is TRUE
thd->add_changed_table(key, key_length);
else
......@@ -3549,7 +3546,7 @@ Query_cache::is_cacheable(THD *thd, size_t query_len, const char *query,
tables_type)))
DBUG_RETURN(0);
if ((thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
if (thd->in_multi_stmt_transaction() &&
((*tables_type)&HA_CACHE_TBL_TRANSACT))
{
DBUG_PRINT("qcache", ("not in autocommin mode"));
......
......@@ -1412,8 +1412,7 @@ void THD::add_changed_table(TABLE *table)
{
DBUG_ENTER("THD::add_changed_table(table)");
DBUG_ASSERT((options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
table->file->has_transactions());
DBUG_ASSERT(in_multi_stmt_transaction() && table->file->has_transactions());
add_changed_table(table->s->table_cache_key.str,
(long) table->s->table_cache_key.length);
DBUG_VOID_RETURN;
......
......@@ -2008,6 +2008,21 @@ class THD :public Statement,
{
return server_status & SERVER_STATUS_IN_TRANS;
}
/**
Returns TRUE if session is in a multi-statement transaction mode.
OPTION_NOT_AUTOCOMMIT: When autocommit is off, a multi-statement
transaction is implicitly started on the first statement after a
previous transaction has been ended.
OPTION_BEGIN: Regardless of the autocommit status, a multi-statement
transaction can be explicitly started with the statements "START
TRANSACTION", "BEGIN [WORK]", "[COMMIT | ROLLBACK] AND CHAIN", etc.
*/
inline bool in_multi_stmt_transaction()
{
return options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN);
}
inline bool fill_derived_tables()
{
return !stmt_arena->is_stmt_prepare() && !lex->only_view_structure();
......
......@@ -5306,7 +5306,7 @@ void mysql_reset_thd_for_next_command(THD *thd)
OPTION_STATUS_NO_TRANS_UPDATE | OPTION_KEEP_LOG to not get warnings
in ha_rollback_trans() about some tables couldn't be rolled back.
*/
if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
if (!thd->in_multi_stmt_transaction())
{
thd->options&= ~OPTION_KEEP_LOG;
thd->transaction.all.modified_non_trans_table= FALSE;
......
......@@ -163,8 +163,7 @@ bool trans_commit_implicit(THD *thd)
if (trans_check(thd))
DBUG_RETURN(TRUE);
if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN |
OPTION_TABLE_LOCK))
if (thd->in_multi_stmt_transaction() || (thd->options & OPTION_TABLE_LOCK))
{
/* Safety if one did "drop table" on locked tables */
if (!thd->locked_tables_mode)
......@@ -299,8 +298,8 @@ bool trans_savepoint(THD *thd, LEX_STRING name)
SAVEPOINT **sv, *newsv;
DBUG_ENTER("trans_savepoint");
if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN) ||
thd->in_sub_stmt) || !opt_using_transactions)
if (!(thd->in_multi_stmt_transaction() || thd->in_sub_stmt) ||
!opt_using_transactions)
DBUG_RETURN(FALSE);
sv= find_savepoint(thd, name);
......
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