InnoDB Plugin  1.0
Data Fields
trx_t Struct Reference

#include <trx0trx.h>

Collaboration diagram for trx_t:
Collaboration graph

Data Fields

ulint magic_n
ib_mutex_t mutex
trx_state_t state
trx_lock_t lock
ulint is_recovered
const char * op_info
ulint isolation_level
ulint check_foreigns
unsigned is_registered:1
unsigned owns_prepare_mutex:1
ulint check_unique_secondary
ulint support_xa
ulint flush_log_later
ulint must_flush_log_later
ulint duplicates
ulint has_search_latch
ulint search_latch_timeout
trx_dict_op_t dict_operation
ulint declared_to_be_inside_innodb
ulint n_tickets_to_enter_innodb
ulint dict_operation_lock_mode
trx_id_t no
time_t start_time
trx_id_t id
XID xid
lsn_t commit_lsn
table_id_t table_id
THD * mysql_thd
const char * mysql_log_file_name
ib_int64_t mysql_log_offset
ulint n_mysql_tables_in_use
ulint mysql_n_tables_locked
ut_list_node< trx_ttrx_list
ut_list_node< trx_tmysql_trx_list
ibool in_mysql_trx_list
dberr_t error_state
const dict_index_terror_info
ulint error_key_num
ut_list_base< trx_named_savept_ttrx_savepoints
ib_mutex_t undo_mutex
undo_no_t undo_no
trx_savept_t last_sql_stat_start
undo_no_t roll_limit
ulint pages_undone
ulint n_autoinc_rows
ibool read_only
ibool auto_commit
ulint will_lock
bool ddl
doc_id_t fts_next_doc_id
ulint flush_tables
ulint start_line
const char * start_file
bool api_trx
bool api_auto_commit
bool read_write
char detailed_error [256]
ibool in_ro_trx_list
ibool in_rw_trx_list

Detailed Description

The transaction handle

Normally, there is a 1:1 relationship between a transaction handle (trx) and a session (client connection). One session is associated with exactly one user transaction. There are some exceptions to this:

For DDL operations, a subtransaction is allocated that modifies the data dictionary tables. Lock waits and deadlocks are prevented by acquiring the dict_operation_lock before starting the subtransaction and releasing it after committing the subtransaction.

The purge system uses a special transaction that is not associated with any session.

If the system crashed or it was quickly shut down while there were transactions in the ACTIVE or PREPARED state, these transactions would no longer be associated with a session when the server is restarted.

A session may be served by at most one thread at a time. The serving thread of a session might change in some MySQL implementations. Therefore we do not have os_thread_get_curr_id() assertions in the code.

Normally, only the thread that is currently associated with a running transaction may access (read and modify) the trx object, and it may do so without holding any mutex. The following are exceptions to this:

trx_rollback_resurrected() may access resurrected (connectionless) transactions while the system is already processing new user transactions. The trx_sys->mutex prevents a race condition between it and lock_trx_release_locks() [invoked by trx_commit()].

trx_print_low() may access transactions not associated with the current thread. The caller must be holding trx_sys->mutex and lock_sys->mutex.

When a transaction handle is in the trx_sys->mysql_trx_list or trx_sys->trx_list, some of its fields must not be modified without holding trx_sys->mutex exclusively.

The locking code (in particular, lock_deadlock_recursive() and lock_rec_convert_impl_to_expl()) will access transactions associated to other connections. The locks of transactions are protected by lock_sys->mutex and sometimes by trx->mutex.

Field Documentation

bool trx_t::api_auto_commit

automatic commit

bool trx_t::api_trx

trx started by InnoDB API

ibool trx_t::auto_commit

TRUE if it is an autocommit

ulint trx_t::check_foreigns

normally TRUE, but if the user wants to suppress foreign key checks, (in table imports, for example) we set this FALSE

ulint trx_t::check_unique_secondary

normally TRUE, but if the user wants to speed up inserts by suppressing unique key checks for secondary indexes when we decide if we can use the insert buffer for them, we set this FALSE

lsn_t trx_t::commit_lsn

lsn at the time of the commit

bool trx_t::ddl

true if it is a transaction that is being started for a DDL operation

ulint trx_t::declared_to_be_inside_innodb

this is TRUE if we have declared this transaction in srv_conc_enter_innodb to be inside the InnoDB engine

char trx_t::detailed_error[256]

detailed error message for last error, or empty.

trx_dict_op_t trx_t::dict_operation
See Also
enum trx_dict_op
ulint trx_t::dict_operation_lock_mode

0, RW_S_LATCH, or RW_X_LATCH: the latch mode trx currently holds on dict_operation_lock. Protected by dict_operation_lock.

ulint trx_t::duplicates


const dict_index_t* trx_t::error_info

if the error number indicates a duplicate key error, a pointer to the problematic index is stored here

ulint trx_t::error_key_num

if the index creation fails to a duplicate key error, a mysql key number of that index is stored here

dberr_t trx_t::error_state

0 if no error, otherwise error number; NOTE That ONLY the thread doing the transaction is allowed to set this field: this is NOT protected by any mutex

ulint trx_t::flush_tables

if "covering" the FLUSH TABLES", count of tables being flushed.

fts_trx_t* trx_t::fts_trx

FTS information, or NULL if transaction hasn't modified tables with FTS indexes (yet).

read_view_t* trx_t::global_read_view

consistent read view associated to a transaction or NULL

mem_heap_t* trx_t::global_read_view_heap

memory heap for the global read view

que_t* trx_t::graph

query currently run in the session, or NULL if none; NOTE that the query belongs to the session, and it can survive over a transaction commit, if it is a stored procedure with a COMMIT WORK statement, for instance

ulint trx_t::has_search_latch

TRUE if this trx has latched the search system latch in S-mode

trx_id_t trx_t::id

transaction id

ibool trx_t::in_mysql_trx_list

TRUE if in trx_sys->mysql_trx_list

ibool trx_t::in_ro_trx_list

The following two fields are mutually exclusive. TRUE if in trx_sys->ro_trx_list

ibool trx_t::in_rw_trx_list

TRUE if in trx_sys->rw_trx_list

trx_undo_t* trx_t::insert_undo

pointer to the insert undo log, or NULL if no inserts performed yet

ulint trx_t::is_recovered

0=normal transaction, 1=recovered, must be rolled back, protected by trx_sys->mutex when trx->in_rw_trx_list holds

ulint trx_t::isolation_level


trx_savept_t trx_t::last_sql_stat_start

undo_no when the last sql statement was started: in case of an error, trx is rolled back down to this undo number; see note at undo_mutex!

trx_lock_t trx_t::lock

Information about the transaction locks and state. Protected by trx->mutex or lock_sys->mutex or both

ulint trx_t::must_flush_log_later

this flag is set to TRUE in trx_commit() if flush_log_later was TRUE, and there were modifications by the transaction; in that case we must flush the log in trx_commit_complete_for_mysql()

ib_mutex_t trx_t::mutex

Mutex protecting the fields state and lock (except some fields of lock, which are protected by lock_sys->mutex)

const char* trx_t::mysql_log_file_name

if MySQL binlog is used, this field contains a pointer to the latest file name; this is NULL if binlog is not used

ib_int64_t trx_t::mysql_log_offset

if MySQL binlog is used, this field contains the end offset of the binlog entry

ulint trx_t::mysql_n_tables_locked

how many tables the current SQL statement uses, except those in consistent read

THD* trx_t::mysql_thd

MySQL thread handle corresponding to this trx, or NULL

ut_list_node< trx_t > trx_t::mysql_trx_list

list of transactions created for MySQL; protected by trx_sys->mutex

ulint trx_t::n_autoinc_rows

no. of AUTO-INC rows required for an SQL statement. This is useful for multi-row INSERTs

ulint trx_t::n_mysql_tables_in_use

number of Innobase tables used in the processing of the current SQL statement in MySQL

ulint trx_t::n_tickets_to_enter_innodb

this can be > 0 only when declared_to_... is TRUE; when we come to srv_conc_innodb_enter, if the value here is > 0, we decrement this by 1

trx_id_t trx_t::no

transaction serialization number: max trx id shortly before the transaction is moved to COMMITTED_IN_MEMORY state. Protected by trx_sys_t::mutex when trx->in_rw_trx_list. Initially set to TRX_ID_MAX.

const char* trx_t::op_info

English text describing the current operation, or an empty string

ulint trx_t::pages_undone

number of undo log pages undone since the last undo log truncation

ibool trx_t::read_only

TRUE if transaction is flagged as a READ-ONLY transaction. if !auto_commit || will_lock > 0 then it will added to the list trx_sys_t::ro_trx_list. A read only transaction will not be assigned an UNDO log. Non-locking auto-commit read-only transaction will not be on either list.

read_view_t* trx_t::read_view

consistent read view used in the transaction or NULL, this read view if defined can be normal read view associated to a transaction (i.e. same as global_read_view) or read view associated to a cursor

bool trx_t::read_write

if read and write operation

undo_no_t trx_t::roll_limit

least undo number to undo during a rollback

trx_rseg_t* trx_t::rseg

rollback segment assigned to the transaction, or NULL if not assigned yet

ulint trx_t::search_latch_timeout

If we notice that someone is waiting for our S-lock on the search latch to be released, we wait in for BTR_SEA_TIMEOUT new searches until we try to keep the search latch again over calls from MySQL; this is intended to reduce contention on the search latch

sess_t* trx_t::sess

session of the trx, NULL if none

const char* trx_t::start_file

Filename where it was started

ulint trx_t::start_line

Track where it was started from

time_t trx_t::start_time

time the trx state last time became TRX_STATE_ACTIVE

trx_state_t trx_t::state
State of the trx from the point of view of concurrency control

and the valid state transitions.

Possible states:


Valid state transitions are:


Auto-commit non-locking read-only: NOT_STARTED -> ACTIVE -> NOT_STARTED


Recovered XA: NOT_STARTED -> PREPARED -> COMMITTED -> (freed)

XA (2PC) (shutdown before ROLLBACK or COMMIT): NOT_STARTED -> PREPARED -> (freed)

Latching and various transaction lists membership rules:

XA (2PC) transactions are always treated as non-autocommit.

Transitions to ACTIVE or NOT_STARTED occur when !in_rw_trx_list and !in_ro_trx_list (no trx_sys->mutex needed).

Autocommit non-locking read-only transactions move between states without holding any mutex. They are !in_rw_trx_list, !in_ro_trx_list.

When a transaction is NOT_STARTED, it can be in_mysql_trx_list if it is a user transaction. It cannot be in ro_trx_list or rw_trx_list.

ACTIVE->PREPARED->COMMITTED is only possible when trx->in_rw_trx_list. The transition ACTIVE->PREPARED is protected by trx_sys->mutex.

ACTIVE->COMMITTED is possible when the transaction is in ro_trx_list or rw_trx_list.

Transitions to COMMITTED are protected by both lock_sys->mutex and trx->mutex.

NOTE: Some of these state change constraints are an overkill, currently only required for a consistent view for printing stats. This unnecessarily adds a huge cost for the general case.

NOTE: In the future we should add read only transactions to the ro_trx_list the first time they try to acquire a lock ie. by default we treat all read-only transactions as non-locking.

ulint trx_t::support_xa

normally we do the XA two-phase commit steps, but by setting this to FALSE, one can save CPU time and about 150 bytes in the undo log size as then we skip XA steps

table_id_t trx_t::table_id

Table to drop iff dict_operation == TRX_DICT_OP_TABLE, or 0.

ut_list_node< trx_t > trx_t::trx_list

list of transactions; protected by trx_sys->mutex. The same node is used for both trx_sys_t::ro_trx_list and trx_sys_t::rw_trx_list

ut_list_base< trx_named_savept_t > trx_t::trx_savepoints

savepoints set with SAVEPOINT ..., oldest first

ib_mutex_t trx_t::undo_mutex

mutex protecting the fields in this section (down to undo_no_arr), EXCEPT last_sql_stat_start, which can be accessed only when we know that there cannot be any activity in the undo logs!

undo_no_t trx_t::undo_no

next undo log record number to assign; since the undo log is private for a transaction, this is a simple ascending sequence with no gaps; thus it represents the number of modified/inserted rows in a transaction

trx_undo_arr_t* trx_t::undo_no_arr

array of undo numbers of undo log records which are currently processed by a rollback operation

trx_undo_t* trx_t::update_undo

pointer to the update undo log, or NULL if no update performed yet

ulint trx_t::will_lock

Will acquire some locks. Increment each time we determine that a lock will be acquired by the MySQL layer.

XID trx_t::xid

X/Open XA transaction identification to identify a transaction branch

The documentation for this struct was generated from the following file: