23#ifndef SQL_CLASS_INCLUDED
24#define SQL_CLASS_INCLUDED
82#include "mysqld_error.h"
142class Dictionary_client;
145class DD_kill_immunizer;
165 const char *src_function,
const char *src_file,
168 const char *src_function,
const char *src_file,
174 const char *src_function,
const char *src_file,
180#define THD_STAGE_INFO(thd, stage) \
181 (thd)->enter_stage(&stage, NULL, __func__, __FILE__, __LINE__)
337#define THD_SENTRY_MAGIC 0xfeedd1ff
338#define THD_SENTRY_GONE 0xdeadbeef
340#define THD_CHECK_SENTRY(thd) assert(thd->dbug_sentry == THD_SENTRY_MAGIC)
422 template <
typename T>
424 void *m =
alloc(
sizeof(T));
425 return m ==
nullptr ?
nullptr :
new (m) T;
427 template <
typename T>
734#define SUB_STMT_TRIGGER 1
735#define SUB_STMT_FUNCTION 2
754#define RETURN_NAME_AS_STRING(NAME) \
774 sprintf(
buf,
"<UNKNOWN SYSTEM THREAD: %d>", thread);
777#undef RETURN_NAME_AS_STRING
890 assert(
m_thd !=
nullptr);
1321 return pointer_cast<const Protocol_classic *>(
m_protocol);
1326 return pointer_cast<Protocol_classic *>(
m_protocol);
1447 const char *calling_func,
const char *calling_file,
1667 bool binlog_rows_query);
1670 const unsigned char *extra_row_info);
1672 const uchar *old_data,
1673 const unsigned char *extra_row_info);
1676 const uchar *extra_row_info);
1682 template <
class RowsEventT>
1684 TABLE *table,
uint32 serv_id,
size_t needed,
bool is_transactional,
1685 const unsigned char *extra_row_info,
uint32 source_part_id = INT_MAX);
2387#if defined(ENABLED_PROFILING)
2402#ifdef HAVE_PSI_STATEMENT_INTERFACE
2409#ifdef HAVE_PSI_TRANSACTION_INTERFACE
2416#ifdef HAVE_PSI_IDLE_INTERFACE
2567 assert(((
file ==
nullptr) && (pos == 0)) ||
2568 ((
file !=
nullptr) && (pos != 0)));
2584 (
"m_trans_log_file: %s, m_trans_fixed_log_file: %s, "
2585 "m_trans_end_pos: %llu",
2595 (
"file: %s, pos: %llu", file_var ? *file_var :
"<none>",
2596 pos_var ? *pos_var : 0));
2605 (
"file: %s, pos: %llu", file_var ? *file_var :
"<none>",
2606 pos_var ? *pos_var : 0));
2790#if defined(ENABLED_DEBUG_SYNC)
2792 struct st_debug_sync_control *debug_sync_control;
2806 explicit THD(
bool enable_plugins =
true);
2857 enum_thd_life_cycle_stages::ACTIVE};
2943 void disconnect(
bool server_shutdown =
false);
2956 size_t query_len,
bool is_trans,
bool direct,
2957 bool suppress_use,
int errcode);
2963 const char *src_function,
const char *src_file,
2964 int src_line)
override {
2974 enter_stage(stage, old_stage, src_function, src_file, src_line);
2979 const char *src_file,
int src_line)
override {
2991 enter_stage(stage,
nullptr, src_function, src_file, src_line);
3027 bool needs_thr_lock_abort)
override;
3030 bool *victimized)
override;
3159 const char *from,
size_t from_length,
3252 bool copy_conditions =
true) {
3270 template <
typename ProtocolClass>
3291 DBUG_PRINT(
"info", (
"change_item_tree place %p old_value %p new_value %p",
3292 place, *place, new_value));
3321 uint add_state_flags);
3433 return variables.gtid_next_list.is_non_null
3767 auto xid_state = trx->xid_state();
3782 auto xid_state = trx->xid_state();
3786#ifdef HAVE_GTID_NEXT_LIST
3811#ifdef HAVE_GTID_NEXT_LIST
3812 owned_gtid_set.
clear();
3895#ifdef HAVE_PSI_THREAD_INTERFACE
3915 return copy_db_to(
const_cast<char const **
>(p_db), p_db_length);
4035 uint code,
const char *message_text);
4104 size_t query_length_arg [[maybe_unused]]) {
4107 static_cast<uint>(query_length_arg));
4108#ifdef HAVE_PSI_THREAD_INTERFACE
4111 (query_arg,
static_cast<uint>(query_length_arg));
4136 void set_query(
const char *query_arg,
size_t query_length_arg) {
4292 bool some_non_transactional_table,
4293 bool non_transactional_tables_are_tmp);
4376 MY_ATTRIBUTE((format(printf, 2, 3)));
4383 MY_ATTRIBUTE((format(printf, 3, 4)));
4387 va_list args) MY_ATTRIBUTE((format(printf, 3, 0)));
4388 void vsyntax_error_at(const
char *pos_in_lexer_raw_buffer, const
char *format,
4389 va_list args) MY_ATTRIBUTE((format(printf, 3, 0)));
4707 const char *message =
nullptr);
4770 return thd->
variables.xa_detach_on_prepare;
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
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:51
void init()
Initialize the cost model object for a query.
Definition: opt_costmodel.cc:44
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:354
Diagnostics_area * pop_diagnostics_area()
Pop "this" off the Diagnostics Area stack.
Definition: sql_error.cc:631
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:620
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
An instance of the global read lock in a connection.
Definition: sql_class.h:827
bool can_acquire_protection() const
Check if this connection can acquire protection against GRL and emit error if otherwise.
Definition: sql_class.h:853
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:878
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:872
enum_grl_state m_state
Definition: sql_class.h:866
bool is_acquired() const
Definition: sql_class.h:861
Global_read_lock()
Definition: sql_class.h:835
static bool global_read_lock_active()
Used by innodb memcached server to check if any connections have global read lock.
Definition: sql_class.h:847
enum_grl_state
Definition: sql_class.h:829
@ GRL_ACQUIRED_AND_BLOCKS_COMMIT
Definition: sql_class.h:832
@ GRL_ACQUIRED
Definition: sql_class.h:831
@ GRL_NONE
Definition: sql_class.h:830
Represents a set of GTIDs.
Definition: rpl_gtid.h:1454
void clear()
Removes all gtids from this Gtid_set.
Definition: rpl_gtid_set.cc:262
Either statement transaction or normal transaction - related thread-specific storage engine data.
Definition: transaction_info.h:401
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:529
bool m_cancel
Definition: sql_class.h:540
Item * old_value
Definition: sql_class.h:538
Item_change_record(Item **place, Item *new_value)
Definition: sql_class.h:535
Item ** place
Definition: sql_class.h:537
Item * new_value
Definition: sql_class.h:539
Item_change_record()=default
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:850
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:1410
void set_explicit_duration_for_all_locks()
Set explicit duration for all locks in the context.
Definition: mdl.cc:4629
Savepoint for MDL context.
Definition: mdl.h:1315
A granted metadata lock.
Definition: mdl.h:983
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:687
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:696
Class that holds information about tables which were opened and locked by the thread.
Definition: sql_class.h:551
MYSQL_LOCK * lock
Definition: sql_class.h:619
TABLE * open_tables
List of regular tables in use by this thread.
Definition: sql_class.h:598
MYSQL_LOCK * extra_lock
Definition: sql_class.h:626
Open_tables_state()
This constructor initializes Open_tables_state instance which can only be used as backup storage.
Definition: sql_class.h:673
uint state_flags
Definition: sql_class.h:666
void reset_open_tables_state()
Definition: sql_class.cc:613
Reprepare_observer * pop_reprepare_observer()
Definition: sql_class.h:585
void push_reprepare_observer(Reprepare_observer *o)
Definition: sql_class.h:581
enum_flags
Definition: sql_class.h:658
@ BACKUPS_AVAIL
Definition: sql_class.h:659
@ SYSTEM_TABLES
Definition: sql_class.h:660
enum enum_locked_tables_mode locked_tables_mode
Definition: sql_class.h:656
Reprepare_observer * get_reprepare_observer() const
Definition: sql_class.h:576
TABLE * temporary_tables
List of temporary tables used by this thread.
Definition: sql_class.h:604
void reset_reprepare_observers()
Definition: sql_class.h:591
void set_open_tables_state(Open_tables_state *state)
Definition: sql_class.cc:598
Prealloced_array< Reprepare_observer *, 4 > m_reprepare_observers
A stack of Reprepare_observer-instances.
Definition: sql_class.h:573
A per-session context which is always available at any point of execution, because in practice it's a...
Definition: opt_trace_context.h:89
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:477
Prepared_statement_map()
Definition: sql_class.cc:2046
void claim_memory_ownership(bool claim)
Definition: sql_class.cc:2108
Prepared_statement * find_by_name(const LEX_CSTRING &name)
Find prepared statement by name.
Definition: sql_class.cc:2083
int insert(Prepared_statement *statement)
Insert a new statement to the thread-local prepared statement map.
Definition: sql_class.cc:2052
Prepared_statement * m_last_found_statement
Definition: sql_class.h:519
~Prepared_statement_map()
Definition: sql_class.cc:2132
void reset()
Definition: sql_class.cc:2114
void erase(Prepared_statement *statement)
Erase all prepared statements (calls Prepared_statement destructor).
Definition: sql_class.cc:2097
collation_unordered_map< std::string, Prepared_statement * > names_hash
Definition: sql_class.h:518
malloc_unordered_map< ulong, std::unique_ptr< Prepared_statement > > st_hash
Definition: sql_class.h:517
Prepared_statement * find(ulong id)
Find prepared statement by ID.
Definition: sql_class.cc:2088
Prepared_statement: a statement that can contain placeholders.
Definition: sql_prepare.h:345
Definition: protocol_classic.h:239
Definition: protocol_classic.h:51
Class used for the old (MySQL 4.0 protocol).
Definition: protocol_classic.h:217
Definition: protocol.h:32
Definition: sql_class.h:342
enum_state get_state() const
Definition: sql_class.h:405
bool is_stmt_prepare_or_first_stmt_execute() const
Definition: sql_class.h:410
T * memdup_typed(const T *mem)
Definition: sql_class.h:428
enum_state
Definition: sql_class.h:361
@ STMT_INITIALIZED
Definition: sql_class.h:362
@ STMT_ERROR
Definition: sql_class.h:367
@ STMT_REGULAR_EXECUTION
Definition: sql_class.h:365
@ STMT_PREPARED
Definition: sql_class.h:364
@ STMT_INITIALIZED_FOR_SP
Definition: sql_class.h:363
@ STMT_EXECUTED
Definition: sql_class.h:366
bool is_repreparing
To check whether a reprepare operation is active.
Definition: sql_class.h:353
bool is_stmt_prepare() const
Definition: sql_class.h:406
LEX_CSTRING strmake(LEX_CSTRING str)
Definition: sql_class.h:435
void reset_item_list()
Definition: sql_class.h:400
char * mem_strdup(const char *str)
Definition: sql_class.h:431
void free_items()
Definition: sql_class.cc:2010
Item * m_item_list
Definition: sql_class.h:348
void * alloc(size_t size)
Definition: sql_class.h:416
Query_arena(MEM_ROOT *mem_root_arg, enum enum_state state_arg)
Definition: sql_class.h:387
bool is_regular() const
Definition: sql_class.h:414
void set_query_arena(const Query_arena &set)
Copies memory-managing members from set.
Definition: sql_class.cc:2021
char * strmake(const char *str, size_t size) const
Definition: sql_class.h:432
enum_state state
Definition: sql_class.h:384
void set_item_list(Item *item)
Definition: sql_class.h:401
void add_item(Item *item)
Definition: sql_class.cc:2005
void * mem_calloc(size_t size)
Definition: sql_class.h:417
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:2027
void set_state(enum_state state_arg)
Definition: sql_class.h:404
T * alloc_typed()
Definition: sql_class.h:423
Query_arena()
Definition: sql_class.h:394
Item * item_list() const
Definition: sql_class.h:399
bool is_stmt_prepare_or_first_sp_execute() const
Definition: sql_class.h:407
void * memdup(const void *str, size_t size)
Definition: sql_class.h:441
MEM_ROOT * mem_root
Definition: sql_class.h:351
virtual ~Query_arena()=default
Definition: query_result.h:53
Definition: sql_lex.h:2498
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:2606
Definition: rpl_context.h:374
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:53
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:737
ulonglong option_bits
Definition: sql_class.h:739
bool enable_slow_log
Definition: sql_class.h:748
ulong client_capabilities
Definition: sql_class.h:746
ulonglong first_successful_insert_id_in_cur_stmt
Definition: sql_class.h:741
ha_rows examined_row_count
Definition: sql_class.h:745
SAVEPOINT * savepoints
Definition: sql_class.h:749
ulonglong current_found_rows
Definition: sql_class.h:743
ha_rows sent_row_count
Definition: sql_class.h:745
ulonglong previous_found_rows
Definition: sql_class.h:744
enum enum_check_fields check_for_truncated_fields
Definition: sql_class.h:750
Discrete_intervals_list auto_inc_intervals_forced
Definition: sql_class.h:742
ha_rows num_truncated_fields
Definition: sql_class.h:745
uint in_sub_stmt
Definition: sql_class.h:747
ulonglong first_successful_insert_id_in_prev_stmt
Definition: sql_class.h:740
A derived from THD::Attachable_trx class allows updates in the attachable transaction.
Definition: sql_class.h:2026
bool is_read_only() const override
Definition: sql_class.h:2028
Attachable_trx_rw(const Attachable_trx_rw &)
Attachable_trx_rw & operator=(const Attachable_trx_rw &)
Attachable_trx_rw(THD *thd)
Definition: sql_class.cc:529
Class representing read-only attachable transaction, encapsulates knowledge how to backup state of cu...
Definition: sql_class.h:1983
THD * m_thd
THD instance.
Definition: sql_class.h:1994
Transaction_state m_trx_state
Transaction state data.
Definition: sql_class.h:2005
virtual ~Attachable_trx()
Definition: sql_class.cc:485
Attachable_trx * m_prev_attachable_trx
Attachable_trx which was active for the THD before when this transaction was started (NULL in most ca...
Definition: sql_class.h:2002
Attachable_trx(THD *thd, Attachable_trx *prev_trx)
Definition: sql_class.cc:390
virtual bool is_read_only() const
Definition: sql_class.h:1990
enum_reset_lex m_reset_lex
Definition: sql_class.h:1996
Attachable_trx * get_prev_attachable_trx() const
Definition: sql_class.h:1987
Attachable_trx(const Attachable_trx &)
Attachable_trx & operator=(const Attachable_trx &)
Query plan for EXPLAINable commands, should be locked with LOCK_query_plan before using.
Definition: sql_class.h:1348
void set_query_plan(enum_sql_command sql_cmd, LEX *lex_arg, bool ps)
Set query plan.
Definition: sql_class.cc:2670
void assert_plan_is_locked_if_other() const
Asserts that current_thd has locked this plan, if it does not own it.
Definition: sql_class.cc:2665
bool is_single_table_plan() const
Definition: sql_class.cc:3007
THD *const thd
Definition: sql_class.h:1350
Query_plan & operator=(const Query_plan &)
not defined
Query_plan(const Query_plan &)
not defined
bool is_ps_query() const
Definition: sql_class.h:1403
LEX * lex
LEX of topmost statement.
Definition: sql_class.h:1354
bool is_ps
True if query is run in prepared statement.
Definition: sql_class.h:1358
const Modification_plan * modification_plan
Query plan for UPDATE/DELETE/INSERT/REPLACE.
Definition: sql_class.h:1356
Modification_plan const * get_modification_plan() const
Definition: sql_class.h:1399
enum_sql_command get_command() const
Definition: sql_class.h:1391
LEX * get_lex() const
Definition: sql_class.h:1395
Query_plan(THD *thd_arg)
Definition: sql_class.h:1373
enum_sql_command sql_command
Original sql_command;.
Definition: sql_class.h:1352
void set_modification_plan(Modification_plan *plan_arg)
Definition: sql_class.cc:2686
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
bool is_being_disposed() const
Check if THD is being disposed (i.e.
Definition: sql_class.cc:1316
enum_vio_type get_vio_type() const
Definition: sql_class.cc:1923
std::atomic< mysql_cond_t * > current_cond
Pointer to the condition variable the thread owning this THD is currently waiting for.
Definition: sql_class.h:1507
bool has_gtid_consistency_violation
Definition: sql_class.h:3856
friend void my_message_sql(uint, const char *, myf)
All global error messages are sent here where the first one is stored for the client.
Definition: mysqld.cc:3755
Rpl_thd_context rpl_thd_ctx
Definition: sql_class.h:3801
struct THD_timer_info * timer
Holds active timer object.
Definition: sql_class.h:1800
void notify_hton_post_release_exclusive(const MDL_key *mdl_key) override
Notify interested storage engines that we have just released exclusive lock for the key.
Definition: sql_class.cc:3034
uint fill_variables_recursion_level
Definition: sql_class.h:1605
thd_scheduler scheduler
Definition: sql_class.h:3918
ulonglong first_successful_insert_id_in_prev_stmt_for_binlog
Definition: sql_class.h:2127
mysql_mutex_t LOCK_thd_query
Protects THD::m_query_string.
Definition: sql_class.h:1198
PSI_statement_locker * m_statement_psi
Current statement instrumentation.
Definition: sql_class.h:2401