MySQL 8.0.39
Source Code Documentation
Query_tables_list Class Reference

#include <sql_lex.h>

Inheritance diagram for Query_tables_list:
[legend]

Public Types

enum  { START_SROUTINES_HASH_SIZE = 16 }
 
enum  enum_lock_tables_state { LTS_NOT_LOCKED = 0 , LTS_LOCKED }
 Locking state of tables in this particular statement. More...
 
enum  enum_binlog_stmt_unsafe {
  BINLOG_STMT_UNSAFE_LIMIT = 0 , BINLOG_STMT_UNSAFE_SYSTEM_TABLE , BINLOG_STMT_UNSAFE_AUTOINC_COLUMNS , BINLOG_STMT_UNSAFE_UDF ,
  BINLOG_STMT_UNSAFE_SYSTEM_VARIABLE , BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION , BINLOG_STMT_UNSAFE_NONTRANS_AFTER_TRANS , BINLOG_STMT_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE ,
  BINLOG_STMT_UNSAFE_MIXED_STATEMENT , BINLOG_STMT_UNSAFE_INSERT_IGNORE_SELECT , BINLOG_STMT_UNSAFE_INSERT_SELECT_UPDATE , BINLOG_STMT_UNSAFE_WRITE_AUTOINC_SELECT ,
  BINLOG_STMT_UNSAFE_REPLACE_SELECT , BINLOG_STMT_UNSAFE_CREATE_IGNORE_SELECT , BINLOG_STMT_UNSAFE_CREATE_REPLACE_SELECT , BINLOG_STMT_UNSAFE_CREATE_SELECT_AUTOINC ,
  BINLOG_STMT_UNSAFE_UPDATE_IGNORE , BINLOG_STMT_UNSAFE_INSERT_TWO_KEYS , BINLOG_STMT_UNSAFE_AUTOINC_NOT_FIRST , BINLOG_STMT_UNSAFE_FULLTEXT_PLUGIN ,
  BINLOG_STMT_UNSAFE_SKIP_LOCKED , BINLOG_STMT_UNSAFE_NOWAIT , BINLOG_STMT_UNSAFE_XA , BINLOG_STMT_UNSAFE_DEFAULT_EXPRESSION_IN_SUBSTATEMENT ,
  BINLOG_STMT_UNSAFE_ACL_TABLE_READ_IN_DML_DDL , BINLOG_STMT_UNSAFE_CREATE_SELECT_WITH_GIPK , BINLOG_STMT_UNSAFE_COUNT
}
 All types of unsafe statements. More...
 
enum  enum_stmt_accessed_table {
  STMT_READS_TRANS_TABLE = 0 , STMT_READS_NON_TRANS_TABLE , STMT_READS_TEMP_TRANS_TABLE , STMT_READS_TEMP_NON_TRANS_TABLE ,
  STMT_WRITES_TRANS_TABLE , STMT_WRITES_NON_TRANS_TABLE , STMT_WRITES_TEMP_TRANS_TABLE , STMT_WRITES_TEMP_NON_TRANS_TABLE ,
  STMT_ACCESS_TABLE_COUNT
}
 

Public Member Functions

Query_tables_listoperator= (Query_tables_list &&)=default
 
bool is_query_tables_locked () const
 
 Query_tables_list ()=default
 
 ~Query_tables_list ()=default
 
void reset_query_tables_list (bool init)
 
void destroy_query_tables_list ()
 
void set_query_tables_list (Query_tables_list *state)
 
void add_to_query_tables (Table_ref *table)
 
bool requires_prelocking ()
 
void mark_as_requiring_prelocking (Table_ref **tables_own_last)
 
Table_reffirst_not_own_table ()
 
void chop_off_not_own_tables ()
 
bool is_stmt_unsafe () const
 Determine if this statement is marked as unsafe. More...
 
bool is_stmt_unsafe (enum_binlog_stmt_unsafe unsafe)
 
void set_stmt_unsafe (enum_binlog_stmt_unsafe unsafe_type)
 Flag the current (top-level) statement as unsafe. More...
 
void set_stmt_unsafe_flags (uint32 flags)
 Set the bits of binlog_stmt_flags determining the type of unsafeness of the current statement. More...
 
uint32 get_stmt_unsafe_flags () const
 Return a binary combination of all unsafe warnings for the statement. More...
 
bool is_stmt_row_injection () const
 Determine if this statement is a row injection. More...
 
void set_stmt_row_injection ()
 Flag the statement as a row injection. More...
 
void set_stmt_accessed_table (enum_stmt_accessed_table accessed_table)
 Sets the type of table that is about to be accessed while executing a statement. More...
 
bool stmt_accessed_table (enum_stmt_accessed_table accessed_table)
 Checks if a type of table is about to be accessed while executing a statement. More...
 
bool is_mixed_stmt_unsafe (bool in_multi_stmt_transaction_mode, bool binlog_direct, bool trx_cache_is_not_empty, uint tx_isolation)
 
bool uses_stored_routines () const
 true if the parsed tree contains references to stored procedures or functions, false otherwise More...
 
void set_using_match ()
 
bool get_using_match ()
 
void set_stmt_unsafe_with_mixed_mode ()
 
bool is_stmt_unsafe_with_mixed_mode () const
 

Static Public Member Functions

static const char * stmt_accessed_table_string (enum_stmt_accessed_table accessed_table)
 

Public Attributes

enum_sql_command sql_command
 SQL command for this statement. More...
 
Table_refquery_tables
 
Table_ref ** query_tables_last
 
Table_ref ** query_tables_own_last
 
std::unique_ptr< malloc_unordered_map< std::string, Sroutine_hash_entry * > > sroutines
 
SQL_I_List< Sroutine_hash_entrysroutines_list
 
Sroutine_hash_entry ** sroutines_list_own_last
 
uint sroutines_list_own_elements
 
enum_lock_tables_state lock_tables_state
 
uint table_count
 Number of tables which were open by open_tables() and to be locked by lock_tables(). More...
 

Static Public Attributes

static const int BINLOG_STMT_UNSAFE_ALL_FLAGS
 This has all flags from 0 (inclusive) to BINLOG_STMT_FLAG_COUNT (exclusive) set. More...
 
static const int binlog_stmt_unsafe_errcode [BINLOG_STMT_UNSAFE_COUNT]
 Maps elements of enum_binlog_stmt_unsafe to error codes. More...
 

Private Types

enum  enum_binlog_stmt_type { BINLOG_STMT_TYPE_ROW_INJECTION = 0 , BINLOG_STMT_TYPE_COUNT }
 Enumeration listing special types of statements. More...
 

Private Attributes

uint32 binlog_stmt_flags
 Bit field indicating the type of statement. More...
 
uint32 stmt_accessed_table_flag
 Bit field that determines the type of tables that are about to be be accessed while executing a statement. More...
 
bool using_match
 It will be set true if 'MATCH () AGAINST' is used in the statement. More...
 
bool stmt_unsafe_with_mixed_mode {false}
 This flag is set to true if statement is unsafe to be binlogged in STATEMENT format, when in MIXED mode. More...
 

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
START_SROUTINES_HASH_SIZE 

◆ enum_binlog_stmt_type

Enumeration listing special types of statements.

Currently, the only possible type is ROW_INJECTION.

Enumerator
BINLOG_STMT_TYPE_ROW_INJECTION 

The statement is a row injection (i.e., either a BINLOG statement or a row event executed by the slave SQL thread).

BINLOG_STMT_TYPE_COUNT 

The last element of this enumeration type.

◆ enum_binlog_stmt_unsafe

All types of unsafe statements.

Note
The int values of the enum elements are used to point to bits in two bitmaps in two different places:
  • Query_tables_list::binlog_stmt_flags
  • THD::binlog_unsafe_warning_flags

Hence in practice this is not an enum at all, but a map from symbols to bit indexes.

The ordering of elements in this enum must correspond to the order of elements in the array binlog_stmt_unsafe_errcode.

Enumerator
BINLOG_STMT_UNSAFE_LIMIT 

SELECT..LIMIT is unsafe because the set of rows returned cannot be predicted.

BINLOG_STMT_UNSAFE_SYSTEM_TABLE 

Access to log tables is unsafe because slave and master probably log different things.

BINLOG_STMT_UNSAFE_AUTOINC_COLUMNS 

Inserting into an autoincrement column in a stored routine is unsafe.

Even with just one autoincrement column, if the routine is invoked more than once slave is not guaranteed to execute the statement graph same way as the master. And since it's impossible to estimate how many times a routine can be invoked at the query pre-execution phase (see lock_tables), the statement is marked pessimistically unsafe.

BINLOG_STMT_UNSAFE_UDF 

Using a UDF (user-defined function) is unsafe.

BINLOG_STMT_UNSAFE_SYSTEM_VARIABLE 

Using most system variables is unsafe, because slave may run with different options than master.

BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION 

Using some functions is unsafe (e.g., UUID).

BINLOG_STMT_UNSAFE_NONTRANS_AFTER_TRANS 

Mixing transactional and non-transactional statements are unsafe if non-transactional reads or writes are occur after transactional reads or writes inside a transaction.

BINLOG_STMT_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE 

Mixing self-logging and non-self-logging engines in a statement is unsafe.

BINLOG_STMT_UNSAFE_MIXED_STATEMENT 

Statements that read from both transactional and non-transactional tables and write to any of them are unsafe.

BINLOG_STMT_UNSAFE_INSERT_IGNORE_SELECT 

INSERT...IGNORE SELECT is unsafe because which rows are ignored depends on the order that rows are retrieved by SELECT.

This order cannot be predicted and may differ on master and the slave.

BINLOG_STMT_UNSAFE_INSERT_SELECT_UPDATE 

INSERT...SELECT...UPDATE is unsafe because which rows are updated depends on the order that rows are retrieved by SELECT.

This order cannot be predicted and may differ on master and the slave.

BINLOG_STMT_UNSAFE_WRITE_AUTOINC_SELECT 

Query that writes to a table with auto_inc column after selecting from other tables are unsafe as the order in which the rows are retrieved by select may differ on master and slave.

BINLOG_STMT_UNSAFE_REPLACE_SELECT 

INSERT...REPLACE SELECT is unsafe because which rows are replaced depends on the order that rows are retrieved by SELECT.

This order cannot be predicted and may differ on master and the slave.

BINLOG_STMT_UNSAFE_CREATE_IGNORE_SELECT 

CREATE TABLE... IGNORE... SELECT is unsafe because which rows are ignored depends on the order that rows are retrieved by SELECT.

This order cannot be predicted and may differ on master and the slave.

BINLOG_STMT_UNSAFE_CREATE_REPLACE_SELECT 

CREATE TABLE...REPLACE... SELECT is unsafe because which rows are replaced depends on the order that rows are retrieved from SELECT.

This order cannot be predicted and may differ on master and the slave

BINLOG_STMT_UNSAFE_CREATE_SELECT_AUTOINC 

CREATE TABLE...SELECT on a table with auto-increment column is unsafe because which rows are replaced depends on the order that rows are retrieved from SELECT.

This order cannot be predicted and may differ on master and the slave

BINLOG_STMT_UNSAFE_UPDATE_IGNORE 

UPDATE...IGNORE is unsafe because which rows are ignored depends on the order that rows are updated.

This order cannot be predicted and may differ on master and the slave.

BINLOG_STMT_UNSAFE_INSERT_TWO_KEYS 

INSERT... ON DUPLICATE KEY UPDATE on a table with more than one UNIQUE KEYS is unsafe.

BINLOG_STMT_UNSAFE_AUTOINC_NOT_FIRST 

INSERT into auto-inc field which is not the first part in composed primary key.

BINLOG_STMT_UNSAFE_FULLTEXT_PLUGIN 

Using a plugin is unsafe.

BINLOG_STMT_UNSAFE_SKIP_LOCKED 
BINLOG_STMT_UNSAFE_NOWAIT 
BINLOG_STMT_UNSAFE_XA 

XA transactions and statements.

BINLOG_STMT_UNSAFE_DEFAULT_EXPRESSION_IN_SUBSTATEMENT 

If a substatement inserts into or updates a table that has a column with an unsafe DEFAULT expression, it may not have the same effect on the slave.

BINLOG_STMT_UNSAFE_ACL_TABLE_READ_IN_DML_DDL 

DML or DDL statement that reads a ACL table is unsafe, because the row are read without acquiring SE row locks.

This would allow ACL tables to be updated by concurrent thread. It would not have the same effect on the slave.

BINLOG_STMT_UNSAFE_CREATE_SELECT_WITH_GIPK 

Generating invisible primary key for a table created using CREATE TABLE... SELECT... is unsafe because order in which rows are retrieved by the SELECT determines which (if any) rows are inserted.

This order cannot be predicted and values for generated invisible primary key column may differ on source and replica when @session.binlog_format=STATEMENT.

BINLOG_STMT_UNSAFE_COUNT 

◆ enum_lock_tables_state

Locking state of tables in this particular statement.

If we under LOCK TABLES or in prelocked mode we consider tables for the statement to be "locked" if there was a call to lock_tables() (which called handler::start_stmt()) for tables of this statement and there was no matching close_thread_tables() call.

As result this state may differ significantly from one represented by Open_tables_state::lock/locked_tables_mode more, which are always "on" under LOCK TABLES or in prelocked mode.

Enumerator
LTS_NOT_LOCKED 
LTS_LOCKED 

◆ enum_stmt_accessed_table

Enumerator
STMT_READS_TRANS_TABLE 
STMT_READS_NON_TRANS_TABLE 
STMT_READS_TEMP_TRANS_TABLE 
STMT_READS_TEMP_NON_TRANS_TABLE 
STMT_WRITES_TRANS_TABLE 
STMT_WRITES_NON_TRANS_TABLE 
STMT_WRITES_TEMP_TRANS_TABLE 
STMT_WRITES_TEMP_NON_TRANS_TABLE 
STMT_ACCESS_TABLE_COUNT 

Constructor & Destructor Documentation

◆ Query_tables_list()

Query_tables_list::Query_tables_list ( )
default

◆ ~Query_tables_list()

Query_tables_list::~Query_tables_list ( )
default

Member Function Documentation

◆ add_to_query_tables()

void Query_tables_list::add_to_query_tables ( Table_ref table)
inline

◆ chop_off_not_own_tables()

void Query_tables_list::chop_off_not_own_tables ( )
inline

◆ destroy_query_tables_list()

void Query_tables_list::destroy_query_tables_list ( )

◆ first_not_own_table()

Table_ref * Query_tables_list::first_not_own_table ( )
inline

◆ get_stmt_unsafe_flags()

uint32 Query_tables_list::get_stmt_unsafe_flags ( ) const
inline

Return a binary combination of all unsafe warnings for the statement.

If the statement has been marked as unsafe by the 'flag' member of enum_binlog_stmt_unsafe, then the return value from this function has bit (1<<flag) set to 1.

◆ get_using_match()

bool Query_tables_list::get_using_match ( )
inline

◆ is_mixed_stmt_unsafe()

bool Query_tables_list::is_mixed_stmt_unsafe ( bool  in_multi_stmt_transaction_mode,
bool  binlog_direct,
bool  trx_cache_is_not_empty,
uint  tx_isolation 
)
inline

◆ is_query_tables_locked()

bool Query_tables_list::is_query_tables_locked ( ) const
inline

◆ is_stmt_row_injection()

bool Query_tables_list::is_stmt_row_injection ( ) const
inline

Determine if this statement is a row injection.

Return values
0if the statement is not a row injection
nonzeroif the statement is a row injection

◆ is_stmt_unsafe() [1/2]

bool Query_tables_list::is_stmt_unsafe ( ) const
inline

Determine if this statement is marked as unsafe.

Return values
0if the statement is not marked as unsafe.
nonzeroif the statement is marked as unsafe.

◆ is_stmt_unsafe() [2/2]

bool Query_tables_list::is_stmt_unsafe ( enum_binlog_stmt_unsafe  unsafe)
inline

◆ is_stmt_unsafe_with_mixed_mode()

bool Query_tables_list::is_stmt_unsafe_with_mixed_mode ( ) const
inline

◆ mark_as_requiring_prelocking()

void Query_tables_list::mark_as_requiring_prelocking ( Table_ref **  tables_own_last)
inline

◆ operator=()

Query_tables_list & Query_tables_list::operator= ( Query_tables_list &&  )
default

◆ requires_prelocking()

bool Query_tables_list::requires_prelocking ( )
inline

◆ reset_query_tables_list()

void Query_tables_list::reset_query_tables_list ( bool  init)

◆ set_query_tables_list()

void Query_tables_list::set_query_tables_list ( Query_tables_list state)
inline

◆ set_stmt_accessed_table()

void Query_tables_list::set_stmt_accessed_table ( enum_stmt_accessed_table  accessed_table)
inline

Sets the type of table that is about to be accessed while executing a statement.

Parameters
accessed_tableEnumeration type that defines the type of table, e.g. temporary, transactional, non-transactional.

◆ set_stmt_row_injection()

void Query_tables_list::set_stmt_row_injection ( )
inline

Flag the statement as a row injection.

A row injection is either a BINLOG statement, or a row event in the relay log executed by the slave SQL thread.

◆ set_stmt_unsafe()

void Query_tables_list::set_stmt_unsafe ( enum_binlog_stmt_unsafe  unsafe_type)
inline

Flag the current (top-level) statement as unsafe.

The flag will be reset after the statement has finished.

Parameters
unsafe_typeThe type of unsafety: one of the BINLOG_STMT_FLAG_UNSAFE_* flags in enum_binlog_stmt_flag.

◆ set_stmt_unsafe_flags()

void Query_tables_list::set_stmt_unsafe_flags ( uint32  flags)
inline

Set the bits of binlog_stmt_flags determining the type of unsafeness of the current statement.

No existing bits will be cleared, but new bits may be set.

Parameters
flagsA binary combination of zero or more bits, (1<<flag) where flag is a member of enum_binlog_stmt_unsafe.

◆ set_stmt_unsafe_with_mixed_mode()

void Query_tables_list::set_stmt_unsafe_with_mixed_mode ( )
inline

◆ set_using_match()

void Query_tables_list::set_using_match ( )
inline

◆ stmt_accessed_table()

bool Query_tables_list::stmt_accessed_table ( enum_stmt_accessed_table  accessed_table)
inline

Checks if a type of table is about to be accessed while executing a statement.

Parameters
accessed_tableEnumeration type that defines the type of table, e.g. temporary, transactional, non-transactional.
Return values
trueif the type of the table is about to be accessed
falseotherwise

◆ stmt_accessed_table_string()

static const char * Query_tables_list::stmt_accessed_table_string ( enum_stmt_accessed_table  accessed_table)
inlinestatic

◆ uses_stored_routines()

bool Query_tables_list::uses_stored_routines ( ) const
inline

true if the parsed tree contains references to stored procedures or functions, false otherwise

Member Data Documentation

◆ binlog_stmt_flags

uint32 Query_tables_list::binlog_stmt_flags
private

Bit field indicating the type of statement.

There are two groups of bits:

  • The low BINLOG_STMT_UNSAFE_COUNT bits indicate the types of unsafeness that the current statement has.
  • The next BINLOG_STMT_TYPE_COUNT bits indicate if the statement is of some special type.

This must be a member of LEX, not of THD: each stored procedure needs to remember its unsafeness state between calls and each stored procedure has its own LEX object (but no own THD object).

◆ BINLOG_STMT_UNSAFE_ALL_FLAGS

const int Query_tables_list::BINLOG_STMT_UNSAFE_ALL_FLAGS
static
Initial value:
=
@ BINLOG_STMT_UNSAFE_COUNT
Definition: sql_lex.h:2792

This has all flags from 0 (inclusive) to BINLOG_STMT_FLAG_COUNT (exclusive) set.

◆ binlog_stmt_unsafe_errcode

const int Query_tables_list::binlog_stmt_unsafe_errcode
static
Initial value:
= {
ER_BINLOG_UNSAFE_LIMIT,
ER_BINLOG_UNSAFE_SYSTEM_TABLE,
ER_BINLOG_UNSAFE_AUTOINC_COLUMNS,
ER_BINLOG_UNSAFE_UDF,
ER_BINLOG_UNSAFE_SYSTEM_VARIABLE,
ER_BINLOG_UNSAFE_SYSTEM_FUNCTION,
ER_BINLOG_UNSAFE_NONTRANS_AFTER_TRANS,
ER_BINLOG_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE,
ER_BINLOG_UNSAFE_MIXED_STATEMENT,
ER_BINLOG_UNSAFE_INSERT_IGNORE_SELECT,
ER_BINLOG_UNSAFE_INSERT_SELECT_UPDATE,
ER_BINLOG_UNSAFE_WRITE_AUTOINC_SELECT,
ER_BINLOG_UNSAFE_REPLACE_SELECT,
ER_BINLOG_UNSAFE_CREATE_IGNORE_SELECT,
ER_BINLOG_UNSAFE_CREATE_REPLACE_SELECT,
ER_BINLOG_UNSAFE_CREATE_SELECT_AUTOINC,
ER_BINLOG_UNSAFE_UPDATE_IGNORE,
ER_BINLOG_UNSAFE_INSERT_TWO_KEYS,
ER_BINLOG_UNSAFE_AUTOINC_NOT_FIRST,
ER_BINLOG_UNSAFE_FULLTEXT_PLUGIN,
ER_BINLOG_UNSAFE_SKIP_LOCKED,
ER_BINLOG_UNSAFE_NOWAIT,
ER_BINLOG_UNSAFE_XA,
ER_BINLOG_UNSAFE_DEFAULT_EXPRESSION_IN_SUBSTATEMENT,
ER_BINLOG_UNSAFE_ACL_TABLE_READ_IN_DML_DDL,
ER_CREATE_SELECT_WITH_GIPK_DISALLOWED_IN_SBR}

Maps elements of enum_binlog_stmt_unsafe to error codes.

Mapping from enum values in enum_binlog_stmt_unsafe to error codes.

Note
The order of the elements of this array must correspond to the order of elements in enum_binlog_stmt_unsafe.

Todo/fixme Bug#22860121 ER_BINLOG_UNSAFE_* FAMILY OF ERROR CODES IS UNUSED suggests to turn ER_BINLOG_UNSAFE* to private consts/messages.

◆ lock_tables_state

enum_lock_tables_state Query_tables_list::lock_tables_state

◆ query_tables

Table_ref* Query_tables_list::query_tables

◆ query_tables_last

Table_ref** Query_tables_list::query_tables_last

◆ query_tables_own_last

Table_ref** Query_tables_list::query_tables_own_last

◆ sql_command

enum_sql_command Query_tables_list::sql_command

SQL command for this statement.

Part of this class since the process of opening and locking tables for the statement needs this information to determine correct type of lock for some of the tables.

◆ sroutines

std::unique_ptr<malloc_unordered_map<std::string, Sroutine_hash_entry *> > Query_tables_list::sroutines

◆ sroutines_list

SQL_I_List<Sroutine_hash_entry> Query_tables_list::sroutines_list

◆ sroutines_list_own_elements

uint Query_tables_list::sroutines_list_own_elements

◆ sroutines_list_own_last

Sroutine_hash_entry** Query_tables_list::sroutines_list_own_last

◆ stmt_accessed_table_flag

uint32 Query_tables_list::stmt_accessed_table_flag
private

Bit field that determines the type of tables that are about to be be accessed while executing a statement.

◆ stmt_unsafe_with_mixed_mode

bool Query_tables_list::stmt_unsafe_with_mixed_mode {false}
private

This flag is set to true if statement is unsafe to be binlogged in STATEMENT format, when in MIXED mode.

Currently this flag is set to true if stored program used in statement has CREATE/DROP temporary table operation(s) as sub-statement(s).

◆ table_count

uint Query_tables_list::table_count

Number of tables which were open by open_tables() and to be locked by lock_tables().

Note that we set this member only in some cases, when this value needs to be passed from open_tables() to lock_tables() which are separated by some amount of code.

◆ using_match

bool Query_tables_list::using_match
private

It will be set true if 'MATCH () AGAINST' is used in the statement.


The documentation for this class was generated from the following files: