Databases 21 min read

Unveiling InnoDB’s Transaction Struct: 63 Variables Explained

This article dissects the InnoDB transaction structure defined in storage/innobase/include/trx0trx.h, detailing each of the 63 variables—including their types, purpose, and interaction with MySQL’s transaction coordinator—so readers can grasp how InnoDB ensures data consistency and manages transaction state.

dbaplus Community
dbaplus Community
dbaplus Community
Unveiling InnoDB’s Transaction Struct: 63 Variables Explained

InnoDB is MySQL’s transactional storage engine that provides non‑blocking consistent reads, redo/undo logs, dead‑lock detection and a rich set of locks.

Examining the source of InnoDB reveals that opening a transaction requires handling 63 distinct variables, each with its own type and semantics.

Source file

storage/innobase/include/trx0trx.h

magic_n – type ulint (defined as unsigned long).

mutex – type ib_mutex_t. Used to protect the fields state and lock (except some lock fields protected by lock_sys‑>mutex).

state – type trx_state_t. Transaction states include TRX_STATE_NOT_STARTED, TRX_STATE_ACTIVE, TRX_STATE_PREPARED, TRX_STATE_COMMITTED_IN_MEMORY (alias COMMITTED).

lock – type trx_lock_t. Holds information about transaction locks and state; protected by trx‑>mutex, lock_sys‑>mutex or both.

is_recovered – type ulint. 0 = normal transaction, 1 = recovered and must be rolled back; protected by trx_sys‑>mutex when the transaction is in the in_rw_trx_list.

op_info – type const char*. Holds operation‑specific information.

isolation_level – type ulint. Values: READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE.

is_registered:1 – type unsigned. Set to 1 after the transaction registers with the XA coordinator via trans_register_ha(), cleared on commit or rollback.

check_unique_secondary – type ulint. Usually TRUE; set to FALSE when the user disables secondary‑index unique‑key checks to speed up inserts.

support_xa – type ulint. When FALSE, the XA two‑phase commit steps are skipped, saving CPU time and about 150 bytes of undo‑log space.

flush_log_later – type ulint. In two‑phase commit, the log flush is deferred until after the prepare_commit mutex is released.

must_flush_log_later – type ulint. Set to TRUE in trx_commit() if flush_log_later was true and the transaction made modifications; forces a log flush in trx_commit_complete_for_mysql().

duplicates – type ulint. Flags such as TRX_DUP_IGNORE or TRX_DUP_REPLACE.

has_search_latch – type ulint. TRUE if the transaction holds the search system latch in S‑mode.

search_latch_timeout – type ulint. Controls how many new searches are waited for in row0sel.cc before re‑acquiring the latch, reducing contention.

dict_operation – type trx_dict_op_t. Indicates the operation type: 0 = no table‑structure change, 1 = alter table, 2 = modify index.

declared_to_be_inside_innodb – type ulint. TRUE if the transaction has been declared inside InnoDB via srv_conc_enter_innodb.

n_tickets_to_enter_innodb – type ulint. Counts tickets for entering InnoDB; decremented when srv_conc_innodb_enter is called.

dict_operation_lock_mode – type ulint. Lock mode for dict_operation_lock: 0, RW_S_LATCH or RW_X_LATCH.

no – type trx_id_t. Transaction serialization number, set just before the transaction reaches COMMITTED_IN_MEMORY; protected by trx_sys‑>mutex.

start_time – type time_t. Timestamp when the transaction last entered TRX_STATE_ACTIVE.

id – type trx_id_t. The transaction identifier.

XID – type XID. X/Open XA transaction identifier for branch tracking.

commit_lsn – type lsn_t ( typedef ib_uint64_t lsn_t). Log sequence number at commit time.

table_id – type table_id_t. Table to drop when dict_operation == TRX_DICT_OP_TABLE, otherwise 0.

mysql_thd – type THD*. Pointer to the MySQL thread handling this transaction (or NULL).

mysql_log_file_name – type const char*. Name of the latest binlog file when binary logging is enabled.

mysql_log_offset – type ib_int64_t. End offset of the binlog entry.

n_mysql_tables_in_use – type ulint. Number of InnoDB tables used by the current SQL statement.

mysql_n_tables_locked – type ulint. Number of tables locked by the current statement, excluding those locked for consistent read.

trx_list – type UT_LIST_NODE_T(trx_t). List of all transactions, protected by trx_sys‑>mutex.

mysql_trx_list – type UT_LIST_NODE_T(trx_t). List of transactions created for MySQL, also protected by trx_sys‑>mutex.

error_state – type dberr_t. 0 if no error; otherwise holds the error number (set only by the owning thread).

error_info – type const dict_index_t*. Points to the problematic index when a duplicate‑key error occurs.

error_key_num – type ulint. MySQL key number of the index that caused a duplicate‑key error.

sess – type sess_t*. Session associated with the transaction (or NULL).

graph – type que_t*. Current query running in the session; may survive a commit if it belongs to a stored procedure.

global_read_view_heap – type mem_heap_t*. Memory heap for the global read view.

global_read_view – type read_view_t*. Consistent read view linked to the transaction (or NULL).

read_view – type read_view_t*. Consistent read view used by the transaction or cursor.

trx_savepoints – type UT_LIST_BASE_NODE_T(trx_named_savept_t). List of savepoints created with SAVEPOINT, ordered oldest first.

undo_mutex – type ib_mutex_t. Protects fields in the undo section (except last_sql_stat_start).

undo_no – type undo_no_t ( typedef ib_id_t undo_no_t). Sequential number for undo log records, representing the number of rows modified/inserted.

last_sql_stat_start – type trx_savept_t. Undo number when the last SQL statement started; used to roll back on error.

rseg – type trx_rseg_t*. Rollback segment assigned to the transaction (or NULL).

insert_undo – type trx_undo_t*. Pointer to the insert undo log (or NULL if no inserts).

update_undo – type trx_undo_t*. Pointer to the update undo log (or NULL if no updates).

roll_limit – type undo_no_t. Minimum undo number to process during a rollback.

pages_undone – type ulint. Number of undo‑log pages undone since the last truncation.

undo_no_arr – type trx_undo_arr_t*. Array of undo numbers currently being processed by a rollback.

n_autoinc_rows – type ulint. Number of AUTO‑INC rows required by the statement, useful for multi‑row INSERTs.

autoinc_locks – type ib_vector_t*. AUTOINC locks held by the transaction; also appear in trx_locks list and must be freed when the transaction is destroyed.

read_only – type ibool. TRUE if the transaction is read‑only; such transactions are not assigned an UNDO log.

auto_commit – type ibool. TRUE if the transaction runs in autocommit mode.

will_lock – type ulint. Counter incremented each time the MySQL layer determines a lock will be acquired.

ddl – type bool. TRUE if the transaction is started for a DDL operation.

fts_trx – type fts_trx_t*. Full‑text search information; NULL if the transaction has not modified FTS‑indexed tables.

fts_next_doc_id – type doc_id_t. Document ID used for updates in FTS.

flush_tables – type ulint. Count of tables being flushed when a FLUSH TABLES statement is covered.

api_trx – type bool. TRUE if the transaction was started via the InnoDB API.

api_auto_commit – type bool. Indicates automatic commit when using the API.

read_write – type bool. Indicates whether the transaction performs read‑write operations.

detailed_error[256] – type char. Buffer for a detailed error message of the last error.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

transactiondatabaseInnoDBmysqlinternals
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.