23#ifndef SQL_CLASS_INCLUDED
24#define SQL_CLASS_INCLUDED
50#include <unordered_map>
84#include "mysqld_error.h"
147class Dictionary_client;
150class DD_kill_immunizer;
170 const char *src_function,
const char *src_file,
173 const char *src_function,
const char *src_file,
179 const char *src_function,
const char *src_file,
185#define THD_STAGE_INFO(thd, stage) \
186 (thd)->enter_stage(&stage, NULL, __func__, __FILE__, __LINE__)
342#define THD_SENTRY_MAGIC 0xfeedd1ff
343#define THD_SENTRY_GONE 0xdeadbeef
345#define THD_CHECK_SENTRY(thd) assert(thd->dbug_sentry == THD_SENTRY_MAGIC)
427 template <
typename T>
429 void *m =
alloc(
sizeof(T));
430 return m ==
nullptr ?
nullptr :
new (m) T;
432 template <
typename T>
739#define SUB_STMT_TRIGGER 1
740#define SUB_STMT_FUNCTION 2
759#define RETURN_NAME_AS_STRING(NAME) \
779 sprintf(
buf,
"<UNKNOWN SYSTEM THREAD: %d>", thread);
782#undef RETURN_NAME_AS_STRING
895 assert(
m_thd !=
nullptr);
927 std::pair<Event_tracking_class, Event_tracking_information *>;
1330 return pointer_cast<const Protocol_classic *>(
m_protocol);
1335 return pointer_cast<Protocol_classic *>(
m_protocol);
1456 const char *calling_func,
const char *calling_file,
1676 bool binlog_rows_query);
1679 const unsigned char *extra_row_info);
1681 const uchar *old_data,
1682 const unsigned char *extra_row_info);
1685 const uchar *extra_row_info);
1691 template <
class RowsEventT>
1694 const unsigned char *extra_row_info,
uint32 source_part_id = INT_MAX);
2418#if defined(ENABLED_PROFILING)
2433#ifdef HAVE_PSI_STATEMENT_INTERFACE
2440#ifdef HAVE_PSI_TRANSACTION_INTERFACE
2447#ifdef HAVE_PSI_IDLE_INTERFACE
2598 assert(((
file ==
nullptr) && (pos == 0)) ||
2599 ((
file !=
nullptr) && (pos != 0)));
2615 (
"m_trans_log_file: %s, m_trans_fixed_log_file: %s, "
2616 "m_trans_end_pos: %llu",
2626 (
"file: %s, pos: %llu", file_var ? *file_var :
"<none>",
2627 pos_var ? *pos_var : 0));
2636 (
"file: %s, pos: %llu", file_var ? *file_var :
"<none>",
2637 pos_var ? *pos_var : 0));
2821#if defined(ENABLED_DEBUG_SYNC)
2823 struct st_debug_sync_control *debug_sync_control;
2837 explicit THD(
bool enable_plugins =
true);
2888 enum_thd_life_cycle_stages::ACTIVE};
2974 void disconnect(
bool server_shutdown =
false);
2987 size_t query_len,
bool is_trans,
bool direct,
2988 bool suppress_use,
int errcode);
2994 const char *src_function,
const char *src_file,
2995 int src_line)
override {
3005 enter_stage(stage, old_stage, src_function, src_file, src_line);
3010 const char *src_file,
int src_line)
override {
3022 enter_stage(stage,
nullptr, src_function, src_file, src_line);
3058 bool needs_thr_lock_abort)
override;
3061 bool *victimized)
override;
3190 const char *from,
size_t from_length,
3283 bool copy_conditions =
true) {
3301 template <
typename ProtocolClass>
3322 DBUG_PRINT(
"info", (
"change_item_tree place %p old_value %p new_value %p",
3323 place, *place, new_value));
3352 uint add_state_flags);
3464 return variables.gtid_next_list.is_non_null
3798 auto xid_state = trx->xid_state();
3813 auto xid_state = trx->xid_state();
3817#ifdef HAVE_GTID_NEXT_LIST
3842#ifdef HAVE_GTID_NEXT_LIST
3843 owned_gtid_set.
clear();
3926#ifdef HAVE_PSI_THREAD_INTERFACE
3946 return copy_db_to(
const_cast<char const **
>(p_db), p_db_length);
4066 uint code,
const char *message_text);
4136 size_t query_length_arg [[maybe_unused]]) {
4139 static_cast<uint
>(query_length_arg));
4140#ifdef HAVE_PSI_THREAD_INTERFACE
4143 (query_arg,
static_cast<uint
>(query_length_arg));
4168 void set_query(
const char *query_arg,
size_t query_length_arg) {
4169 const LEX_CSTRING tmp = {query_arg, query_length_arg};
4324 bool some_non_transactional_table,
4325 bool non_transactional_tables_are_tmp);
4409 MY_ATTRIBUTE((format(printf, 2, 3)));
4416 MY_ATTRIBUTE((format(printf, 3, 4)));
4420 MY_ATTRIBUTE((format(printf, 3, 0)));
4421 void vsyntax_error_at(const
char *pos_in_lexer_raw_buffer, const
char *format,
4422 va_list args) MY_ATTRIBUTE((format(printf, 3, 0)));
4748 unsigned long subevent,
bool check_audited);
4779 const char *message =
nullptr);
4842 return thd->
variables.xa_detach_on_prepare;
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:250
int64 query_id_t
Definition: binlog.h:71
API for getting cost estimates for server operations that are not directly related to a table object.
Definition: opt_costmodel.h:53
Stores status of the currently executed statement.
Definition: sql_error.h:268
bool is_error() const
Definition: sql_error.h:365
void reset_diagnostics_area()
Clear this Diagnostics Area.
Definition: sql_error.cc:359
Diagnostics_area * pop_diagnostics_area()
Pop "this" off the Diagnostics Area stack.
Definition: sql_error.cc:636
const Diagnostics_area * stacked_da() const
Returns the Diagnostics Area below the current diagnostics area on the stack.
Definition: sql_error.h:586
void push_diagnostics_area(THD *thd, Diagnostics_area *da, bool copy_conditions)
Push the given Diagnostics Area on top of the stack.
Definition: sql_error.cc:625
List of Discrete_interval objects.
Definition: discrete_interval.h:86
bool append(Discrete_interval *new_interval)
Definition: discrete_interval.h:116
void clear()
Definition: discrete_interval.h:143
Definition: reference_caching_setup.h:108
void refresh_all()
Definition: reference_caching_setup.cc:246
An instance of the global read lock in a connection.
Definition: sql_class.h:832
bool can_acquire_protection() const
Check if this connection can acquire protection against GRL and emit error if otherwise.
Definition: sql_class.h:858
MDL_ticket * m_mdl_blocks_commits_lock
Also in order to acquire the global read lock, the connection must acquire a shared metadata lock in ...
Definition: sql_class.h:883
MDL_ticket * m_mdl_global_shared_lock
In order to acquire the global read lock, the connection must acquire shared metadata lock in GLOBAL ...
Definition: sql_class.h:877
enum_grl_state m_state
Definition: sql_class.h:871
bool is_acquired() const
Definition: sql_class.h:866
Global_read_lock()
Definition: sql_class.h:840
static bool global_read_lock_active()
Used by innodb memcached server to check if any connections have global read lock.
Definition: sql_class.h:852
enum_grl_state
Definition: sql_class.h:834
@ GRL_ACQUIRED_AND_BLOCKS_COMMIT
Definition: sql_class.h:837
@ GRL_ACQUIRED
Definition: sql_class.h:836
@ GRL_NONE
Definition: sql_class.h:835
Represents a set of GTIDs.
Definition: rpl_gtid.h:1466
void clear()
Removes all gtids from this Gtid_set.
Definition: rpl_gtid_set.cc:263
Either statement transaction or normal transaction - related thread-specific storage engine data.
Definition: transaction_info.h:402
This class represents the interface for internal error handlers.
Definition: error_handler.h:46
A registry for item tree transformations performed during query optimization.
Definition: sql_class.h:534
bool m_cancel
Definition: sql_class.h:545
Item * old_value
Definition: sql_class.h:543
Item_change_record(Item **place, Item *new_value)
Definition: sql_class.h:540
Item ** place
Definition: sql_class.h:542
Item * new_value
Definition: sql_class.h:544
Item_change_record()=default
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:932
Definition: sql_list.h:433
Tables that were locked with LOCK TABLES statement.
Definition: locked_tables_list.h:88
An interface to separate the MDL module from the THD, and the rest of the server code.
Definition: mdl.h:84
Context of the owner of metadata locks.
Definition: mdl.h:1411
void set_explicit_duration_for_all_locks()
Set explicit duration for all locks in the context.
Definition: mdl.cc:4631
Savepoint for MDL context.
Definition: mdl.h:1316
A granted metadata lock.
Definition: mdl.h:984
Table modification plan for JOIN-less statements (update/delete)
Definition: opt_explain.h:81
Storage for backup of Open_tables_state.
Definition: sql_class.h:692
MDL_savepoint mdl_system_tables_svp
When we backup the open tables state to open a system table or tables, we want to save state of metad...
Definition: sql_class.h:701
Class that holds information about tables which were opened and locked by the thread.
Definition: sql_class.h:556
MYSQL_LOCK * lock
Definition: sql_class.h:624
TABLE * open_tables
List of regular tables in use by this thread.
Definition: sql_class.h:603
MYSQL_LOCK * extra_lock
Definition: sql_class.h:631
Open_tables_state()
This constructor initializes Open_tables_state instance which can only be used as backup storage.
Definition: sql_class.h:678
uint state_flags
Definition: sql_class.h:671
void reset_open_tables_state()
Definition: sql_class.cc:618
Reprepare_observer * pop_reprepare_observer()
Definition: sql_class.h:590
void push_reprepare_observer(Reprepare_observer *o)
Definition: sql_class.h:586
enum_flags
Definition: sql_class.h:663
@ BACKUPS_AVAIL
Definition: sql_class.h:664
@ SYSTEM_TABLES
Definition: sql_class.h:665
enum enum_locked_tables_mode locked_tables_mode
Definition: sql_class.h:661
Reprepare_observer * get_reprepare_observer() const
Definition: sql_class.h:581
TABLE * temporary_tables
List of temporary tables used by this thread.
Definition: sql_class.h:609
void reset_reprepare_observers()
Definition: sql_class.h:596
void set_open_tables_state(Open_tables_state *state)
Definition: sql_class.cc:603
Prealloced_array< Reprepare_observer *, 4 > m_reprepare_observers
A stack of Reprepare_observer-instances.
Definition: sql_class.h:578
A per-session context which is always available at any point of execution, because in practice it's a...
Definition: opt_trace_context.h:91
Profiling state for a single THD; contains multiple QUERY_PROFILE objects.
Definition: sql_profile.h:225
Internal state of the parser.
Definition: sql_lexer_parser_state.h:43
Plugin array helper class.
Definition: sql_plugin_ref.h:109
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:70
Container for all prepared statements created/used in a connection.
Definition: sql_class.h:482
Prepared_statement_map()
Definition: sql_class.cc:2063
void claim_memory_ownership(bool claim)
Definition: sql_class.cc:2125
Prepared_statement * find_by_name(const LEX_CSTRING &name)
Find prepared statement by name.
Definition: sql_class.cc:2100
int insert(Prepared_statement *statement)
Insert a new statement to the thread-local prepared statement map.
Definition: sql_class.cc:2069
Prepared_statement * m_last_found_statement
Definition: sql_class.h:524
~Prepared_statement_map()
Definition: sql_class.cc:2149
void reset()
Definition: sql_class.cc:2131
void erase(Prepared_statement *statement)
Erase all prepared statements (calls Prepared_statement destructor).
Definition: sql_class.cc:2114
collation_unordered_map< std::string, Prepared_statement * > names_hash
Definition: sql_class.h:523
malloc_unordered_map< ulong, std::unique_ptr< Prepared_statement > > st_hash
Definition: sql_class.h:522
Prepared_statement * find(ulong id)
Find prepared statement by ID.
Definition: sql_class.cc:2105
Prepared_statement: a statement that can contain placeholders.
Definition: sql_prepare.h:345
Definition: protocol_classic.h:241
Definition: protocol_classic.h:53
Class used for the old (MySQL 4.0 protocol).
Definition: protocol_classic.h:219
Definition: protocol.h:32
Definition: sql_class.h:347
enum_state get_state() const
Definition: sql_class.h:410
bool is_stmt_prepare_or_first_stmt_execute() const
Definition: sql_class.h:415
T * memdup_typed(const T *mem)
Definition: sql_class.h:433
enum_state
Definition: sql_class.h:366
@ STMT_INITIALIZED
Definition: sql_class.h:367
@ STMT_ERROR
Definition: sql_class.h:372
@ STMT_REGULAR_EXECUTION
Definition: sql_class.h:370
@ STMT_PREPARED
Definition: sql_class.h:369
@ STMT_INITIALIZED_FOR_SP
Definition: sql_class.h:368
@ STMT_EXECUTED
Definition: sql_class.h:371
bool is_repreparing
To check whether a reprepare operation is active.
Definition: sql_class.h:358
bool is_stmt_prepare() const
Definition: sql_class.h:411
LEX_CSTRING strmake(LEX_CSTRING str)
Definition: sql_class.h:440
void reset_item_list()
Definition: sql_class.h:405
char * mem_strdup(const char *str)
Definition: sql_class.h:436
void free_items()
Definition: sql_class.cc:2027
Item * m_item_list
Definition: sql_class.h:353
void * alloc(size_t size)
Definition: sql_class.h:421
Query_arena(MEM_ROOT *mem_root_arg, enum enum_state state_arg)
Definition: sql_class.h:392
bool is_regular() const
Definition: sql_class.h:419
void set_query_arena(const Query_arena &set)
Copies memory-managing members from set.
Definition: sql_class.cc:2038
char * strmake(const char *str, size_t size) const
Definition: sql_class.h:437
enum_state state
Definition: sql_class.h:389
void set_item_list(Item *item)
Definition: sql_class.h:406
void add_item(Item *item)
Definition: sql_class.cc:2022
void * mem_calloc(size_t size)
Definition: sql_class.h:422
void swap_query_arena(const Query_arena &source, Query_arena *backup)
Copy the current arena to backup and set the current arena to match source
Definition: sql_class.cc:2044
void set_state(enum_state state_arg)
Definition: sql_class.h:409
T * alloc_typed()
Definition: sql_class.h:428
Query_arena()
Definition: sql_class.h:399
Item * item_list() const
Definition: sql_class.h:404
bool is_stmt_prepare_or_first_sp_execute() const
Definition: sql_class.h:412
void * memdup(const void *str, size_t size)
Definition: sql_class.h:446
MEM_ROOT * mem_root
Definition: sql_class.h:356
virtual ~Query_arena()=default
Definition: query_result.h:57
Definition: sql_lex.h:2515
Definition: rpl_rli.h:202
An interface that is used to take an action when the locking module notices that a table version has ...
Definition: sql_prepare.h:80
Common base class for all row-containing log events.
Definition: log_event.h:2716
Definition: rpl_context.h:402
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:52
Definition: sys_vars_resource_mgr.h:69
Definition: session_tracker.h:128
Sql_cmd_common_signal represents the common properties of the SIGNAL and RESIGNAL statements.
Definition: sql_signal.h:87
Sql_cmd_resignal represents a RESIGNAL statement.
Definition: sql_signal.h:167
Sql_cmd_signal represents a SIGNAL statement.
Definition: sql_signal.h:147
Representation of a SQL condition.
Definition: sql_error.h:57
enum_severity_level
Enumeration value describing the severity of the condition.
Definition: sql_error.h:62
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
Used to save context when executing a function or trigger.
Definition: sql_class.h:742
ulonglong option_bits
Definition: sql_class.h:744
bool enable_slow_log
Definition: sql_class.h:753
ulong client_capabilities
Definition: sql_class.h:751
ulonglong first_successful_insert_id_in_cur_stmt
Definition: sql_class.h:746
ha_rows examined_row_count
Definition: sql_class.h:750
SAVEPOINT * savepoints
Definition: sql_class.h:754
ulonglong current_found_rows
Definition: sql_class.h:748
ha_rows sent_row_count
Definition: sql_class.h:750
ulonglong previous_found_rows
Definition: sql_class.h:749
enum enum_check_fields check_for_truncated_fields
Definition: sql_class.h:755
Discrete_intervals_list auto_inc_intervals_forced
Definition: sql_class.h:747
ha_rows num_truncated_fields
Definition: sql_class.h:750
uint in_sub_stmt
Definition: sql_class.h:752
ulonglong first_successful_insert_id_in_prev_stmt
Definition: sql_class.h:745
A derived from THD::Attachable_trx class allows updates in the attachable transaction.
Definition: sql_class.h:2057
bool is_read_only() const override
Definition: sql_class.h:2059
Attachable_trx_rw(const Attachable_trx_rw &)
Attachable_trx_rw & operator=(const Attachable_trx_rw &)
Attachable_trx_rw(THD *thd)
Definition: sql_class.cc:534
Class representing read-only attachable transaction, encapsulates knowledge how to backup state of cu...
Definition: sql_class.h:2014
THD * m_thd
THD instance.
Definition: sql_class.h:2025
Transaction_state m_trx_state
Transaction state data.
Definition: sql_class.h:2036