2785 Davi Arnaut 2008-12-15
Move checks for OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN to a separate
helper function.
modified:
sql/ha_ndbcluster.cc
sql/log.cc
sql/sql_cache.cc
sql/sql_class.cc
sql/sql_class.h
sql/sql_parse.cc
sql/transaction.cc
2784 Davi Arnaut 2008-12-13
WL#4284, post-merge fix: Increase code portability and fix warning.
modified:
sql/mdl.cc
sql/mdl.h
sql/sql_trigger.cc
=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc 2008-10-16 13:52:18 +0000
+++ b/sql/ha_ndbcluster.cc 2008-12-15 14:39:03 +0000
@@ -4872,7 +4872,7 @@ int ha_ndbcluster::start_statement(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();
@@ -4941,7 +4941,7 @@ int ha_ndbcluster::init_handler_for_stat
}
#endif
- if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
+ if (thd->in_multi_stmt_transaction())
{
const void *key= m_table;
HASH_SEARCH_STATE state;
@@ -5025,7 +5025,7 @@ int ha_ndbcluster::external_lock(THD *th
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! */
@@ -5044,7 +5044,7 @@ int ha_ndbcluster::external_lock(THD *th
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)
{
@@ -5151,8 +5151,7 @@ static int ndbcluster_commit(handlerton
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
@@ -5241,8 +5240,7 @@ static int ndbcluster_rollback(handlerto
DBUG_ENTER("ndbcluster_rollback");
DBUG_ASSERT(ndb);
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()))
{
/* Ignore end-of-statement until real rollback or commit is called */
DBUG_PRINT("info", ("Rollback before start or end-of-statement only"));
@@ -8485,7 +8483,7 @@ ndbcluster_cache_retrieval_allowed(THD *
ulonglong *engine_data)
{
Uint64 commit_count;
- bool is_autocommit= !(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
+ bool is_autocommit= !(thd->in_multi_stmt_transaction());
char *dbname= full_name;
char *tabname= dbname+strlen(dbname)+1;
#ifndef DBUG_OFF
@@ -8560,7 +8558,7 @@ ha_ndbcluster::register_query_cache_tabl
#ifndef DBUG_OFF
char buff[22];
#endif
- bool is_autocommit= !(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN));
+ bool is_autocommit= !(thd->in_multi_stmt_transaction());
DBUG_ENTER("ha_ndbcluster::register_query_cache_table");
DBUG_PRINT("enter",("dbname: %s, tabname: %s, is_autocommit: %d",
m_dbname, m_tabname, is_autocommit));
=== modified file 'sql/log.cc'
--- a/sql/log.cc 2008-12-12 15:40:34 +0000
+++ b/sql/log.cc 2008-12-15 14:39:03 +0000
@@ -2642,7 +2642,7 @@ binlog_end_trans(THD *thd, binlog_trx_da
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())
{
trx_data->reset();
@@ -2760,8 +2760,7 @@ static int binlog_commit(handlerton *hto
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,
@@ -5504,7 +5503,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);
/*
=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc 2008-12-04 16:50:07 +0000
+++ b/sql/sql_cache.cc 2008-12-15 14:39:03 +0000
@@ -1351,7 +1351,7 @@ def_week_frmt: %lu",
}
DBUG_PRINT("qcache", ("Query have result %p", 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",
@@ -1509,8 +1509,7 @@ void Query_cache::invalidate(THD *thd, T
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);
@@ -1591,8 +1590,7 @@ void Query_cache::invalidate(THD *thd, T
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);
@@ -1610,8 +1608,7 @@ void Query_cache::invalidate(THD *thd, c
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
@@ -3463,7 +3460,7 @@ Query_cache::is_cacheable(THD *thd, size
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"));
=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc 2008-12-12 11:36:54 +0000
+++ b/sql/sql_class.cc 2008-12-15 14:39:03 +0000
@@ -1177,8 +1177,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;
=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h 2008-12-08 22:29:38 +0000
+++ b/sql/sql_class.h 2008-12-15 14:39:03 +0000
@@ -1946,6 +1946,21 @@ public:
{
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();
=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc 2008-12-12 15:40:34 +0000
+++ b/sql/sql_parse.cc 2008-12-15 14:39:03 +0000
@@ -5459,7 +5459,7 @@ void mysql_reset_thd_for_next_command(TH
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;
=== modified file 'sql/transaction.cc'
--- a/sql/transaction.cc 2008-12-04 16:50:07 +0000
+++ b/sql/transaction.cc 2008-12-15 14:39:03 +0000
@@ -165,8 +165,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)
@@ -304,8 +303,8 @@ bool trans_savepoint(THD *thd, LEX_STRIN
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);
| Thread |
|---|
| • bzr push into mysql-6.0-runtime branch (davi:2784 to 2785) | Davi Arnaut | 15 Dec |