MySQL 8.4.2
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

 trx_t ()=default
 Default constructor. More...
 
bool is_read_uncommitted () const
 
bool releases_gap_locks_at_prepare () const
 
bool skip_gap_locks () const
 
bool allow_semi_consistent () const
 
bool releases_non_matching_rows () const
 Checks if this transaction releases locks on non matching records due to low isolation level. More...
 

Public Attributes

TrxMutex mutex
 Mutex protecting the fields state and lock (except some fields of lock, which are protected by lock_sys latches) More...
 
uint32_t in_depth
 Track nested TrxInInnoDB count. More...
 
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...
 
std::atomic< trx_state_tstate
 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
 false: a normal transaction true: a recovered transaction More...
 
std::atomic< std::thread::idkilled_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...
 
isolation_level_t isolation_level
 Current isolation level. 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...
 
uint32_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 More...
 
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...
 
std::atomic< std::chrono::system_clock::time_point > start_time
 Time the state last time became TRX_STATE_ACTIVE. 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...
 
uint32_t n_mysql_tables_in_use
 number of Innobase tables used in the processing of the current SQL statement in MySQL More...
 
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
 True iff in trx_sys->rw_trx_list. 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
 DB_SUCCESS if no error, otherwise error number. 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...
 
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
 
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...
 
std::atomic_uint64_t 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...
 
bool purge_sys_trx
 This flag is set for trx_t objects used by the purge sys. More...
 
char * detailed_error
 detailed error message for last error, or empty. More...
 
Flush_observerflush_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

Constructor & Destructor Documentation

◆ trx_t()

trx_t::trx_t ( )
default

Default constructor.

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

◆ releases_gap_locks_at_prepare()

bool trx_t::releases_gap_locks_at_prepare ( ) const
inline

◆ releases_non_matching_rows()

bool trx_t::releases_non_matching_rows ( ) const
inline

Checks if this transaction releases locks on non matching records due to low isolation level.

Returns
true iff in this transaction's isolation level locks on records which do not match the WHERE clause are released

◆ 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

◆ 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

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

DB_SUCCESS if no error, otherwise error number.

Accessed without any mutex only by the thread doing the transaction or, if it is suspended (waiting for a lock), by the thread holding this->mutex which has changed trx->lock.wait_lock to nullptr and will wake up the transaction.

◆ flush_log_later

bool trx_t::flush_log_later

◆ flush_observer

Flush_observer* trx_t::flush_observer

flush observer

◆ flush_tables

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

uint32_t trx_t::in_depth

Track nested TrxInInnoDB count.

◆ in_innodb

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

True iff 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

false: a normal transaction true: a recovered transaction

Set to true when srv_is_being_started for recovered transactions. Set to false without any protection in trx_init (where no other thread should access this object anyway). Can be read safely when holding trx_sys->mutex and trx belongs to rw_trx_list, as trx_init can not be called until trx leaves rw_trx_list which requires the trx_sys->mutex.

◆ is_registered

bool trx_t::is_registered

◆ isolation_level

isolation_level_t trx_t::isolation_level

Current isolation level.

◆ killed_by

std::atomic<std::thread::id> 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 latches 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 latches)

◆ 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

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

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

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.

◆ purge_sys_trx

bool trx_t::purge_sys_trx

This flag is set for trx_t objects used by the purge sys.

We use the flag when validating mysql_trx_list in trx_sys_before_pre_dd_shutdown_validate. Purge threads can have allocated trx_t objects visible in the mysql_trx_list at this point during shutdown, this is acceptable so we need a way to signal this fact.

◆ 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

std::atomic<std::chrono::system_clock::time_point> trx_t::start_time
Initial value:
{
std::chrono::system_clock::time_point{}}

Time the state last time became TRX_STATE_ACTIVE.

◆ state

std::atomic<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

std::atomic_uint64_t 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

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: