MySQL  8.0.19
Source Code Documentation
trx_t Struct Reference

#include <trx0trx.h>

Public Types

enum  isolation_level_t { READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE }
 

Public Member Functions

bool is_read_uncommitted () const
 
bool skip_gap_locks () const
 
bool allow_semi_consistent () const
 

Public Attributes

TrxMutex mutex
 Mutex protecting the fields state and lock (except some fields of lock, which are protected by lock_sys->mutex) More...
 
ib_uint32_t in_depth
 Track nested TrxInInnoDB count. More...
 
ib_uint32_t in_innodb
 if the thread is executing in the InnoDB context count > 0. More...
 
bool abort
 if this flag is set then this transaction must abort when it can More...
 
trx_id_t id
 transaction id More...
 
trx_id_t no
 transaction serialization number: max trx id shortly before the transaction is moved to COMMITTED_IN_MEMORY state. More...
 
trx_state_t state
 State of the trx from the point of view of concurrency control and the valid state transitions. More...
 
bool skip_lock_inheritance
 
ReadViewread_view
 consistent read view used in the transaction, or NULL if not yet set More...
 
 trx_list
 list of transactions; protected by trx_sys->mutex. More...
 
 no_list
 Required during view creation to check for the view limit for transactions that are committing. More...
 
trx_lock_t lock
 Information about the transaction locks and state. More...
 
bool is_recovered
 0=normal transaction, 1=recovered, must be rolled back, protected by trx_sys->mutex when trx->in_rw_trx_list holds More...
 
os_thread_id_t killed_by
 The thread ID that wants to kill this transaction asynchronously. More...
 
const char * op_info
 English text describing the current operation, or an empty string. More...
 
ulint isolation_level
 TRX_ISO_REPEATABLE_READ, ... More...
 
bool check_foreigns
 normally TRUE, but if the user wants to suppress foreign key checks, (in table imports, for example) we set this FALSE More...
 
bool is_registered
 
bool 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 More...
 
bool flush_log_later
 
bool 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() More...
 
bool has_search_latch
 TRUE if this trx has latched the search system latch in S-mode. More...
 
trx_dict_op_t dict_operation
 
bool ddl_operation
 True if this trx involves dd table change. More...
 
bool ddl_must_flush
 True if this trx involves dd table change, and must flush. More...
 
bool in_truncate
 
bool 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 More...
 
ib_uint32_t n_tickets_to_enter_innodb
 this can be > 0 only when declared_to_... More...
 
ib_uint32_t dict_operation_lock_mode
 0, RW_S_LATCH, or RW_X_LATCH: the latch mode trx currently holds on dict_operation_lock. More...
 
time_t start_time
 time the state last time became TRX_STATE_ACTIVE More...
 
int32_t age
 Weight/Age of the transaction in the record lock wait queue. More...
 
uint64_t age_updated
 For tracking if Weight/age has been updated. More...
 
lsn_t commit_lsn
 lsn at the time of the commit More...
 
THDmysql_thd
 MySQL thread handle corresponding to this trx, or NULL. More...
 
const char * 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 More...
 
uint64_t mysql_log_offset
 if MySQL binlog is used, this field contains the end offset of the binlog entry More...
 
ib_uint32_t n_mysql_tables_in_use
 number of Innobase tables used in the processing of the current SQL statement in MySQL More...
 
ib_uint32_t mysql_n_tables_locked
 how many tables the current SQL statement uses, except those in consistent read More...
 
bool in_rw_trx_list
 The following two fields are mutually exclusive. More...
 
 mysql_trx_list
 list of transactions created for MySQL; protected by trx_sys->mutex More...
 
bool in_mysql_trx_list
 true if in trx_sys->mysql_trx_list More...
 
dberr_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 More...
 
const dict_index_terror_index
 if the error number indicates a duplicate key error, a pointer to the problematic index is stored here More...
 
ulint error_key_num
 if the index creation fails to a duplicate key error, a mysql key number of that index is stored here More...
 
sess_tsess
 session of the trx, NULL if none More...
 
que_tgraph
 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 More...
 
 trx_savepoints
 savepoints set with SAVEPOINT ..., oldest first More...
 
UndoMutex 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! More...
 
undo_no_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 More...
 
space_id_t undo_rseg_space
 space id where last undo record was written More...
 
trx_savept_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! More...
 
trx_rsegs_t rsegs
 
undo_no_t roll_limit
 least undo number to undo during a partial rollback; 0 otherwise More...
 
bool in_rollback
 true when the transaction is executing a partial or full rollback More...
 
ulint pages_undone
 number of undo log pages undone since the last undo log truncation More...
 
ulint n_autoinc_rows
 no. More...
 
bool read_only
 true if transaction is flagged as a READ-ONLY transaction. More...
 
bool auto_commit
 true if it is an autocommit More...
 
ib_uint32_t will_lock
 Will acquire some locks. More...
 
fts_trx_tfts_trx
 FTS information, or NULL if transaction hasn't modified tables with FTS indexes (yet). More...
 
doc_id_t fts_next_doc_id
 
ib_uint32_t flush_tables
 if "covering" the FLUSH TABLES", count of tables being flushed. More...
 
bool internal
 true if it is a system/internal transaction background task. More...
 
bool persists_gtid
 Transaction persists GTID. More...
 
ulint start_line
 Track where it was started from. More...
 
const char * start_file
 Filename where it was started. More...
 
lint n_ref
 Count of references, protected by trx_t::mutex. More...
 
ulint version
 Version of this instance. More...
 
XIDxid
 X/Open XA transaction identification to identify a transaction branch. More...
 
trx_mod_tables_t mod_tables
 List of tables that were modified by this transaction. More...
 
bool api_trx
 trx started by InnoDB API More...
 
bool api_auto_commit
 automatic commit More...
 
bool read_write
 if read and write operation More...
 
char * detailed_error
 detailed error message for last error, or empty. More...
 
FlushObserverflush_observer
 flush observer More...
 
bool is_dd_trx
 True if the transaction is used for doing Non-locking Read-only Read Committed on DD tables. More...
 
ulint magic_n
 

Member Enumeration Documentation

◆ isolation_level_t

Enumerator
READ_UNCOMMITTED 

dirty read: non-locking SELECTs are performed so that we do not look at a possible earlier version of a record; thus they are not 'consistent' reads under this isolation level; otherwise like level 2

READ_COMMITTED 

somewhat Oracle-like isolation, except that in range UPDATE and DELETE we must block phantom rows with next-key locks; SELECT ...

FOR UPDATE and ... LOCK IN SHARE MODE only lock the index records, NOT the gaps before them, and thus allow free inserting; each consistent read reads its own snapshot

REPEATABLE_READ 

this is the default; all consistent reads in the same trx read the same snapshot; full next-key locking used in locking reads to block insertions into gaps

SERIALIZABLE 

all plain SELECTs are converted to LOCK IN SHARE MODE reads

Member Function Documentation

◆ allow_semi_consistent()

bool trx_t::allow_semi_consistent ( ) const
inline

◆ is_read_uncommitted()

bool trx_t::is_read_uncommitted ( ) const
inline

◆ skip_gap_locks()

bool trx_t::skip_gap_locks ( ) const
inline

Member Data Documentation

◆ abort

bool trx_t::abort

if this flag is set then this transaction must abort when it can

◆ age

int32_t trx_t::age

Weight/Age of the transaction in the record lock wait queue.

◆ age_updated

uint64_t trx_t::age_updated

For tracking if Weight/age has been updated.

◆ api_auto_commit

bool trx_t::api_auto_commit

automatic commit

◆ api_trx

bool trx_t::api_trx

trx started by InnoDB API

◆ auto_commit

bool trx_t::auto_commit

true if it is an autocommit

◆ check_foreigns

bool 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

◆ check_unique_secondary

bool 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

◆ commit_lsn

lsn_t trx_t::commit_lsn

lsn at the time of the commit

◆ ddl_must_flush

bool trx_t::ddl_must_flush

True if this trx involves dd table change, and must flush.

◆ ddl_operation

bool trx_t::ddl_operation

True if this trx involves dd table change.

◆ declared_to_be_inside_innodb

bool 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

◆ detailed_error

char* trx_t::detailed_error

detailed error message for last error, or empty.

◆ dict_operation

trx_dict_op_t trx_t::dict_operation
See also
enum trx_dict_op_t

◆ dict_operation_lock_mode

ib_uint32_t 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.

◆ error_index

const dict_index_t* trx_t::error_index

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

◆ error_key_num

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

◆ error_state

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

◆ flush_log_later

bool trx_t::flush_log_later

◆ flush_observer

FlushObserver* trx_t::flush_observer

flush observer

◆ flush_tables

ib_uint32_t trx_t::flush_tables

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

◆ fts_next_doc_id

doc_id_t trx_t::fts_next_doc_id

◆ fts_trx

fts_trx_t* trx_t::fts_trx

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

◆ graph

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

◆ has_search_latch

bool trx_t::has_search_latch

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

This now can only be true in row_search_mvcc, the btr search latch must has been released before exiting, and this flag would be set to false

◆ id

trx_id_t trx_t::id

transaction id

◆ in_depth

ib_uint32_t trx_t::in_depth

Track nested TrxInInnoDB count.

◆ in_innodb

ib_uint32_t trx_t::in_innodb

if the thread is executing in the InnoDB context count > 0.

◆ in_mysql_trx_list

bool trx_t::in_mysql_trx_list

true if in trx_sys->mysql_trx_list

◆ in_rollback

bool trx_t::in_rollback

true when the transaction is executing a partial or full rollback

◆ in_rw_trx_list

bool trx_t::in_rw_trx_list

The following two fields are mutually exclusive.

true if in trx_sys->rw_trx_list

◆ in_truncate

bool trx_t::in_truncate

◆ internal

bool trx_t::internal

true if it is a system/internal transaction background task.

Such transactions are always treated as read-write.

◆ is_dd_trx

bool trx_t::is_dd_trx

True if the transaction is used for doing Non-locking Read-only Read Committed on DD tables.

◆ is_recovered

bool 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

◆ is_registered

bool trx_t::is_registered

◆ isolation_level

ulint trx_t::isolation_level

TRX_ISO_REPEATABLE_READ, ...

◆ killed_by

os_thread_id_t trx_t::killed_by

The thread ID that wants to kill this transaction asynchronously.

This is required because we recursively enter the handlerton methods and need to distinguish between the kill thread and the transaction thread.

Note: We need to be careful w.r.t the Thread Pool. The thread doing the kill should not leave InnoDB between the mark and the actual async kill because the running thread can change.

◆ last_sql_stat_start

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!

◆ lock

trx_lock_t trx_t::lock

Information about the transaction locks and state.

Protected by trx->mutex or lock_sys->mutex or both

◆ magic_n

ulint trx_t::magic_n

◆ mod_tables

trx_mod_tables_t trx_t::mod_tables

List of tables that were modified by this transaction.

◆ must_flush_log_later

bool 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()

◆ mutex

TrxMutex trx_t::mutex
mutable

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

◆ mysql_log_file_name

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

◆ mysql_log_offset

uint64_t trx_t::mysql_log_offset

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

◆ mysql_n_tables_locked

ib_uint32_t trx_t::mysql_n_tables_locked

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

◆ mysql_thd

THD* trx_t::mysql_thd

MySQL thread handle corresponding to this trx, or NULL.

◆ mysql_trx_list

trx_t::mysql_trx_list

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

◆ n_autoinc_rows

ulint trx_t::n_autoinc_rows

no.

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

◆ n_mysql_tables_in_use

ib_uint32_t trx_t::n_mysql_tables_in_use

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

◆ n_ref

lint trx_t::n_ref

Count of references, protected by trx_t::mutex.

We can't release the locks nor commit the transaction until this reference is 0. We can change the state to COMMITTED_IN_MEMORY to signify that it is no longer "active".

◆ n_tickets_to_enter_innodb

ib_uint32_t 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

◆ no

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.

◆ no_list

trx_t::no_list

Required during view creation to check for the view limit for transactions that are committing.

◆ op_info

const char* trx_t::op_info

English text describing the current operation, or an empty string.

◆ pages_undone

ulint trx_t::pages_undone

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

◆ persists_gtid

bool trx_t::persists_gtid

Transaction persists GTID.

◆ read_only

bool trx_t::read_only

true if transaction is flagged as a READ-ONLY transaction.

if auto_commit && will_lock == 0 then it will be handled as a AC-NL-RO-SELECT (Auto Commit Non-Locking Read Only Select). A read only transaction will not be assigned an UNDO log.

◆ read_view

ReadView* trx_t::read_view

consistent read view used in the transaction, or NULL if not yet set

◆ read_write

bool trx_t::read_write

if read and write operation

◆ roll_limit

undo_no_t trx_t::roll_limit

least undo number to undo during a partial rollback; 0 otherwise

◆ rsegs

trx_rsegs_t trx_t::rsegs

◆ sess

sess_t* trx_t::sess

session of the trx, NULL if none

◆ skip_lock_inheritance

bool trx_t::skip_lock_inheritance

◆ start_file

const char* trx_t::start_file

Filename where it was started.

◆ start_line

ulint trx_t::start_line

Track where it was started from.

◆ start_time

time_t trx_t::start_time

time the state last time became TRX_STATE_ACTIVE

◆ state

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:

TRX_STATE_NOT_STARTED TRX_STATE_FORCED_ROLLBACK TRX_STATE_ACTIVE TRX_STATE_PREPARED TRX_STATE_COMMITTED_IN_MEMORY (alias below COMMITTED)

Valid state transitions are:

Regular transactions: NOT_STARTED -> ACTIVE -> COMMITTED -> NOT_STARTED

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

XA (2PC): NOT_STARTED -> ACTIVE -> PREPARED -> COMMITTED -> NOT_STARTED

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

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

Disconnected XA can become recovered: ... -> ACTIVE -> PREPARED (connected) -> PREPARED (disconnected) Disconnected means from mysql e.g due to the mysql client disconnection. 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 (no trx_sys->mutex needed).

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

All transactions, unless they are determined to be ac-nl-ro, explicitly tagged as read-only or read-write, will first be put on the read-only transaction list. Only when a !read-only transaction in the read-only list tries to acquire an X or IX lock on a table do we remove it from the read-only list and put it on the read-write list. During this switch we assign it a rollback segment.

When a transaction is NOT_STARTED, it can be in_mysql_trx_list if it is a user transaction. It cannot be in 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 rw_trx_list.

Transitions to COMMITTED are protected by 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.

◆ trx_list

trx_t::trx_list

list of transactions; protected by trx_sys->mutex.

◆ trx_savepoints

trx_t::trx_savepoints

savepoints set with SAVEPOINT ..., oldest first

◆ undo_mutex

UndoMutex 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

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

◆ undo_rseg_space

space_id_t trx_t::undo_rseg_space

space id where last undo record was written

◆ version

ulint trx_t::version

Version of this instance.

It is incremented each time the instance is re-used in trx_start_low(). It is used to track whether a transaction has been restarted since it was tagged for asynchronous rollback.

◆ will_lock

ib_uint32_t trx_t::will_lock

Will acquire some locks.

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

◆ xid

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: