MySQL 26.10.0
Source Code Documentation
sql_class.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_CLASS_INCLUDED
25#define SQL_CLASS_INCLUDED
26
27/*
28 This file contains the declaration of the THD class and classes which THD
29 depends on. It should contain as little else as possible to increase
30 cohesion and reduce coupling. Since THD is used in many places, many files
31 are dependent on this header and thus require recompilation if it changes.
32 Historically this file contained "Classes in mysql".
33*/
34
35#include "my_config.h"
36
37#include <limits.h>
38#include <stdarg.h>
39#include <stdio.h>
40#include <string.h>
41#ifdef HAVE_SYS_TIME_H
42#include <sys/time.h>
43#endif
44#include <sys/types.h>
45#include <atomic>
46#include <bitset>
47#include <concepts> // invocable
48#include <functional> // function
49#include <list> // list
50#include <memory>
51#include <new>
52#include <stack>
53#include <string>
54#include <unordered_map>
55#include <utility> // move
56#include <vector> // vector
57
58#include "dur_prop.h" // durability_properties
59#include "lex_string.h"
60#include "map_helpers.h"
61#include "my_alloc.h"
62#include "my_base.h"
63#include "my_command.h"
64#include "my_compiler.h"
65#include "my_dbug.h"
66#include "my_inttypes.h"
67#include "my_io.h"
68#include "my_psi_config.h"
69#include "my_sqlcommand.h"
70#include "my_sys.h"
71#include "my_table_map.h"
72#include "my_thread_local.h"
73#include "my_time_t.h"
83#include "mysql/plugin_audit.h"
88#include "mysql/thread_type.h"
89#include "mysql_com_server.h" // NET_SERVER
90#include "mysqld_error.h"
91#include "pfs_thread_provider.h"
92#include "prealloced_array.h"
93#include "scope_guard.h" // Scope_guard
94#include "sql/auth/sql_security_ctx.h" // Security_context
95#include "sql/current_thd.h"
96#include "sql/dd/string_type.h" // dd::string_type
97#include "sql/discrete_interval.h" // Discrete_interval
98#include "sql/locked_tables_list.h" // enum_locked_tables_mode
99#include "sql/mdl.h"
100#include "sql/opt_costmodel.h"
101#include "sql/opt_trace_context.h" // Opt_trace_context
102#include "sql/parse_location.h"
103#include "sql/psi_memory_key.h"
104#include "sql/query_options.h"
107#include "sql/rpl_context.h" // Rpl_thd_context
108#include "sql/rpl_gtid.h"
109#include "sql/session_tracker.h" // Session_tracker
110#include "sql/sql_audit.h"
111#include "sql/sql_connect.h"
112#include "sql/sql_const.h"
113#include "sql/sql_digest_stream.h" // sql_digest_state
114#include "sql/sql_error.h"
115#include "sql/sql_list.h"
116#include "sql/sql_plugin_ref.h"
117#include "sql/sys_vars_resource_mgr.h" // Session_sysvar_resource_manager
118#include "sql/system_variables.h" // system_variables
119#include "sql/transaction_info.h" // Ha_trx_info
120#include "sql/xa.h"
122#include "sql_string.h"
123#include "template_utils.h"
124#include "thr_lock.h"
125#include "violite.h"
126
127enum enum_check_fields : int;
128enum enum_tx_isolation : int;
129enum ha_notification_type : int;
130class Item;
131class Parser_state;
132class PROFILING;
134class Relay_log_info;
135class THD;
136class partition_info;
137class Protocol;
138class Protocol_binary;
139class Protocol_classic;
140class Protocol_text;
141template <class T>
142class mem_root_deque;
143class sp_rcontext;
144class user_var_entry;
145struct LEX;
146struct LEX_USER;
147struct TABLE;
148class Table_ref;
149struct timeval;
150struct User_level_lock;
151
152namespace dd {
153namespace cache {
154class Dictionary_client;
155}
156
157class DD_kill_immunizer;
158} // namespace dd
159
162class Query_result;
164class Rows_log_event;
165class Time_zone;
166class sp_cache;
168struct Log_info;
169
170typedef struct user_conn USER_CONN;
171struct MYSQL_LOCK;
172
173extern "C" void thd_enter_cond(void *opaque_thd, mysql_cond_t *cond,
174 mysql_mutex_t *mutex,
175 const PSI_stage_info *stage,
176 PSI_stage_info *old_stage,
177 const char *src_function, const char *src_file,
178 int src_line);
179extern "C" void thd_exit_cond(void *opaque_thd, const PSI_stage_info *stage,
180 const char *src_function, const char *src_file,
181 int src_line);
182
183extern "C" void thd_enter_stage(void *opaque_thd,
184 const PSI_stage_info *new_stage,
185 PSI_stage_info *old_stage,
186 const char *src_function, const char *src_file,
187 int src_line);
188
189extern "C" void thd_set_waiting_for_disk_space(void *opaque_thd,
190 const bool waiting);
191
192#define THD_STAGE_INFO(thd, stage) \
193 (thd)->enter_stage(&stage, NULL, __func__, __FILE__, __LINE__)
194
195extern char empty_c_string[1];
196
197/*
198 We preallocate data for several storage engine plugins.
199 so: innodb + bdb + ndb + binlog + myisam + myisammrg + archive +
200 example + csv + heap + blackhole + federated + 0
201 (yes, the sum is deliberately inaccurate)
202*/
203constexpr size_t PREALLOC_NUM_HA = 15;
204
205#ifndef NDEBUG
206// Used to sample certain debug flags when a query is read but before the reply
207// is sent.
208enum class TDM { ANY, ON, ZERO, NOT_AVAILABLE };
210#endif /* not defined NDEBUG */
211
212/**
213 To be used for pool-of-threads (implemented differently on various OSs)
214*/
216 public:
217 void *data; /* scheduler-specific data structure */
218
220
221 ~thd_scheduler() = default;
222};
223
225void thd_set_psi(THD *thd, PSI_thread *psi);
226
227/**
228 Return @@session.terminology_use_previous for the current THD.
229
230 @return the integer value of one of the enumeration values in
231 terminology_use_previous::enum_compatibility_version.
232*/
233extern "C" unsigned int thd_get_current_thd_terminology_use_previous();
234
236 /**
237 Memory counter object doesn't update global memory counter and doesn't throw
238 OOM error.
239 */
241 /**
242 if MEM_CNT_UPDATE_GLOBAL_COUNTER is set, memory counter object updates
243 global memory counter.
244 */
246 /**
247 if MEM_CNT_GENERATE_ERROR is set, memory counter object generates OOM error if
248 any.
249*/
251 /**
252 if MEM_CNT_GENERATE_LOG_ERROR is set, memory counter object generates OOM
253 error to error log if any.
254*/
257
259 private:
260 bool m_enabled{false};
261 THD *m_thd{nullptr}; // Pointer to THD object.
262 Diagnostics_area m_da{false}; // Diagnostics area.
263 ulonglong mem_counter{0}; // Amount of memory consumed by thread.
264 ulonglong max_conn_mem{0}; // Max amount memory consumed by thread.
265 ulonglong glob_mem_counter{0}; // Amount of memory added to global
266 // memory counter.
267 uint curr_mode{MEM_CNT_DEFAULT}; // Current memory counter mode.
268 uint orig_mode{MEM_CNT_DEFAULT}; // Original memory counter mode
269 // (sets at init_mode() stage).
270 bool is_connection_stage{true}; // True on connection stage,
271 // resets to false after successful
272 // connection.
273 public:
276 assert(!m_enabled);
277 assert(glob_mem_counter == 0);
278 }
279 void set_thd(THD *thd) { m_thd = thd; }
280 void enable() { m_enabled = true; }
281 void disable();
282
283 void alloc_cnt(size_t size);
284 void free_cnt(size_t size);
285 int reset();
286 void flush();
287 /**
288 Restore original memory counter mode.
289 */
291 /**
292 Set NO ERROR memory counter mode.
293 */
296 }
297 /**
298 Function sets current memory counter mode.
299
300 @param mode_arg current memory counter mode.
301 */
302 void set_curr_mode(uint mode_arg) { curr_mode = mode_arg; }
303 /**
304 Function sets original memory counter mode.
305
306 @param mode_arg original memory counter mode.
307 */
308 void set_orig_mode(uint mode_arg) { orig_mode = mode_arg; }
309 /**
310 Check if memory counter error is issued.
311
312 @retval true if memory counter error is issued, false otherwise.
313 */
314 bool is_error() const { return m_da.is_error(); }
315 void set_thd_error_status() const;
316
317 private:
318 int generate_error(int err_no, ulonglong mem_limit, ulonglong mem_size);
319 /**
320 Check if memory counter is in error mode.
321
322 @retval true if memory counter is in error mode, false otherwise.
323 */
324 bool is_error_mode() const { return (curr_mode & MEM_CNT_GENERATE_ERROR); }
325 /**
326 Check if memory counter is in error log mode.
327
328 @retval true if memory counter is in error log mode, false otherwise.
329 */
330 bool is_error_log_mode() const {
332 }
333};
334
335/**
336 the struct aggregates two parameters that identify an event
337 uniquely in scope of communication of a particular master and slave couple.
338 I.e there can not be 2 events from the same staying connected master which
339 have the same coordinates.
340 @note
341 Such identifier is not yet unique generally as the event originating master
342 is resettable. Also the crashed master can be replaced with some other.
343*/
344typedef struct rpl_event_coordinates {
345 char *file_name; // binlog file name (directories stripped)
346 my_off_t pos; // event's position in the binlog file
348
349#define THD_SENTRY_MAGIC 0xfeedd1ff
350#define THD_SENTRY_GONE 0xdeadbeef
351
352#define THD_CHECK_SENTRY(thd) assert(thd->dbug_sentry == THD_SENTRY_MAGIC)
353
355 private:
356 /*
357 List of items created for this query. Every item adds itself to the list
358 on creation (see Item::Item() for details)
359 */
361
362 public:
363 MEM_ROOT *mem_root; // Pointer to current memroot
364 /// To check whether a reprepare operation is active
365 bool is_repreparing{false};
366 /*
367 The states reflects three different life cycles for three
368 different types of statements:
369 Prepared statement: STMT_INITIALIZED -> STMT_PREPARED -> STMT_EXECUTED.
370 Stored procedure: STMT_INITIALIZED_FOR_SP -> STMT_EXECUTED.
371 Other statements: STMT_REGULAR_EXECUTION never changes.
372 */
379 STMT_ERROR = -1
380 };
381
382 /*
383 State and state changes in SP:
384 1) When state is STMT_INITIALIZED_FOR_SP, objects in the item tree are
385 created on the statement memroot. This is enforced through
386 ps_arena_holder checking the state.
387 2) After the first execute (call p1()), this state should change to
388 STMT_EXECUTED. Objects will be created on the execution memroot and will
389 be destroyed at the end of each execution.
390 3) In case an ER_NEED_REPREPARE error occurs, state should be changed to
391 STMT_INITIALIZED_FOR_SP and objects will again be created on the
392 statement memroot. At the end of this execution, state should change to
393 STMT_EXECUTED.
394 */
395 private:
397
398 public:
399 Query_arena(MEM_ROOT *mem_root_arg, enum enum_state state_arg)
400 : m_item_list(nullptr), mem_root(mem_root_arg), state(state_arg) {}
401
402 /*
403 This constructor is used only when Query_arena is created as
404 backup storage for another instance of Query_arena.
405 */
408
409 virtual ~Query_arena() = default;
410
411 Item *item_list() const { return m_item_list; }
412 void reset_item_list() { m_item_list = nullptr; }
413 void set_item_list(Item *item) { m_item_list = item; }
414 void add_item(Item *item);
415 void free_items();
416 void set_state(enum_state state_arg) { state = state_arg; }
417 enum_state get_state() const { return state; }
418 bool is_stmt_prepare() const { return state == STMT_INITIALIZED; }
420 return (int)state < (int)STMT_PREPARED;
421 }
423 return (int)state <= (int)STMT_PREPARED;
424 }
425 /// @returns true if a regular statement, ie not prepared and not stored proc
426 bool is_regular() const { return state == STMT_REGULAR_EXECUTION; }
427
428 void *alloc(size_t size) { return mem_root->Alloc(size); }
429 void *mem_calloc(size_t size) {
430 void *ptr;
431 if ((ptr = mem_root->Alloc(size))) memset(ptr, 0, size);
432 return ptr;
433 }
434 template <typename T>
436 void *m = alloc(sizeof(T));
437 return m == nullptr ? nullptr : new (m) T;
438 }
439 template <typename T>
440 T *memdup_typed(const T *mem) {
441 return static_cast<T *>(memdup_root(mem_root, mem, sizeof(T)));
442 }
443 char *mem_strdup(const char *str) { return strdup_root(mem_root, str); }
444 char *strmake(const char *str, size_t size) const {
445 return strmake_root(mem_root, str, size);
446 }
448 LEX_CSTRING ret;
449 ret.str = strmake(str.str, str.length);
450 ret.length = ret.str ? str.length : 0;
451 return ret;
452 }
453 void *memdup(const void *str, size_t size) {
454 return memdup_root(mem_root, str, size);
455 }
456
457 /**
458 Copies memory-managing members from `set`. No references are kept to it.
459
460 @param set A Query_arena from which members are copied.
461 */
462 void set_query_arena(const Query_arena &set);
463
464 /**
465 Copy the current arena to `backup` and set the current
466 arena to match `source`
467
468 @param source A Query_arena from which members are copied.
469 @param backup A Query_arena to which members are first saved.
470 */
472};
473
475
476/**
477 Container for all prepared statements created/used in a connection.
478
479 Prepared statements in Prepared_statement_map have unique id
480 (guaranteed by id assignment in Prepared_statement::Prepared_statement).
481
482 Non-empty statement names are unique too: attempt to insert a new statement
483 with duplicate name causes older statement to be deleted.
484
485 Prepared statements are auto-deleted when they are removed from the map
486 and when the map is deleted.
487*/
488
490 public:
492
493 /**
494 Insert a new statement to the thread-local prepared statement map.
495
496 If there was an old statement with the same name, replace it with the
497 new one. Otherwise, check if max_prepared_stmt_count is not reached yet,
498 increase prepared_stmt_count, and insert the new statement. It's okay
499 to delete an old statement and fail to insert the new one.
500
501 All named prepared statements are also present in names_hash.
502 Prepared statement names in names_hash are unique.
503 The statement is added only if prepared_stmt_count < max_prepard_stmt_count
504 m_last_found_statement always points to a valid statement or is 0
505
506 @retval 0 success
507 @retval 1 error: out of resources or max_prepared_stmt_count limit has been
508 reached. An error is sent to the client, the statement
509 is deleted.
510 */
512
513 /** Find prepared statement by name. */
515
516 /** Find prepared statement by ID. */
517 Prepared_statement *find(ulong id);
518
519 /** Erase all prepared statements (calls Prepared_statement destructor). */
521
522 void claim_memory_ownership(bool claim);
523
524 void reset();
525
527
528 private:
532};
533
534/**
535 A registry for item tree transformations performed during
536 query optimization. We register only those changes which require
537 a rollback to re-execute a prepared statement or stored procedure
538 yet another time.
539*/
540
541class Item_change_record : public ilink<Item_change_record> {
542 private:
543 // not used
545
546 public:
552 bool m_cancel{false};
553};
554
556
557/**
558 Class that holds information about tables which were opened and locked
559 by the thread. It is also used to save/restore this information in
560 push_open_tables_state()/pop_open_tables_state().
561*/
562
564 private:
565 /**
566 A stack of Reprepare_observer-instances. The top most instance is the
567 currently active one. This stack is used during execution of prepared
568 statements and stored programs in order to detect metadata changes.
569 The locking subsystem reports a metadata change if the top-most item is not
570 NULL.
571
572 When Open_tables_state part of THD is reset to open a system or
573 INFORMATION_SCHEMA table, NULL is temporarily pushed to avoid spurious
574 ER_NEED_REPREPARE errors -- system and INFORMATION_SCHEMA tables are not
575 subject to metadata version tracking.
576
577 A stack is used here for the convenience -- in some cases we need to
578 temporarily override/disable current Reprepare_observer-instance.
579
580 NOTE: This is not a list of observers, only the top-most element will be
581 notified in case of a metadata change.
582
583 @sa check_and_update_table_version()
584 */
586
587 public:
589 return m_reprepare_observers.size() > 0 ? m_reprepare_observers.back()
590 : nullptr;
591 }
592
594 m_reprepare_observers.push_back(o);
595 }
596
599 m_reprepare_observers.pop_back();
600 return retval;
601 }
602
604
605 public:
606 /**
607 List of regular tables in use by this thread. Contains persistent base
608 tables that were opened with @see open_tables().
609 */
611 /**
612 List of temporary tables used by this thread. Contains user-level
613 temporary tables, created with CREATE TEMPORARY TABLE, and
614 intermediate tables used in ALTER TABLE implementation.
615 */
617 /*
618 During a MySQL session, one can lock tables in two modes: automatic
619 or manual. In automatic mode all necessary tables are locked just before
620 statement execution, and all acquired locks are stored in 'lock'
621 member. Unlocking takes place automatically as well, when the
622 statement ends.
623 Manual mode comes into play when a user issues a 'LOCK TABLES'
624 statement. In this mode the user can only use the locked tables.
625 Trying to use any other tables will give an error.
626 The locked tables are also stored in this member, however,
627 thd->locked_tables_mode is turned on. Manual locking is described in
628 the 'LOCK_TABLES' chapter of the MySQL manual.
629 See also lock_tables() for details.
630 */
632
633 /*
634 CREATE-SELECT keeps an extra lock for the table being
635 created. This field is used to keep the extra lock available for
636 lower level routines, which would otherwise miss that lock.
637 */
639
640 /*
641 Enum enum_locked_tables_mode and locked_tables_mode member are
642 used to indicate whether the so-called "locked tables mode" is on,
643 and what kind of mode is active.
644
645 Locked tables mode is used when it's necessary to open and
646 lock many tables at once, for usage across multiple
647 (sub-)statements.
648 This may be necessary either for queries that use stored functions
649 and triggers, in which case the statements inside functions and
650 triggers may be executed many times, or for implementation of
651 LOCK TABLES, in which case the opened tables are reused by all
652 subsequent statements until a call to UNLOCK TABLES.
653
654 The kind of locked tables mode employed for stored functions and
655 triggers is also called "prelocked mode".
656 In this mode, first open_tables() call to open the tables used
657 in a statement analyses all functions used by the statement
658 and adds all indirectly used tables to the list of tables to
659 open and lock.
660 It also marks the parse tree of the statement as requiring
661 prelocking. After that, lock_tables() locks the entire list
662 of tables and changes THD::locked_tables_modeto LTM_PRELOCKED.
663 All statements executed inside functions or triggers
664 use the prelocked tables, instead of opening their own ones.
665 Prelocked mode is turned off automatically once close_thread_tables()
666 of the main statement is called.
667 */
669
671 BACKUPS_AVAIL = (1U << 0), /* There are backups available. */
672 SYSTEM_TABLES = (1U << 1) /* We are opening system tables. */
673 };
674
675 /*
676 Flags with information about the open tables state.
677 */
679 /**
680 This constructor initializes Open_tables_state instance which can only
681 be used as backup storage. To prepare Open_tables_state instance for
682 operations which open/lock/close tables (e.g. open_table()) one has to
683 call init_open_tables_state().
684 */
687
689
691};
692
693/**
694 Storage for backup of Open_tables_state. Must
695 be used only to open system tables (TABLE_CATEGORY_SYSTEM
696 and TABLE_CATEGORY_LOG).
697*/
698
700 public:
701 /**
702 When we backup the open tables state to open a system
703 table or tables, we want to save state of metadata
704 locks which were acquired before the backup. It is used
705 to release metadata locks on system tables after they are
706 no longer used.
707 */
709};
710
711/**
712 Enum that represents which phase of secondary engine optimization
713 the current statement is in.
714*/
716 /**
717 The current statement should only use tables from primary storage
718 engines. Use of secondary storage engines is disabled.
719 */
721
722 /**
723 The current statement should only use tables from the primary
724 storage engine. However, use of secondary storage engines is not
725 disabled, so the optimizer may choose to trigger a repreparation
726 against the secondary storage engine if it believes that use of a
727 secondary storage engine is beneficial.
728 */
730
731 /**
732 The current statement should use tables from a secondary storage
733 engine if possible. Otherwise, fall back to using tables from
734 primary storage engine only.
735 */
736 SECONDARY,
737};
738
739/**
740 @class Sub_statement_state
741 @brief Used to save context when executing a function or trigger
742*/
743
744/* Defines used for Sub_statement_state::in_sub_stmt */
745
746#define SUB_STMT_TRIGGER 1
747#define SUB_STMT_FUNCTION 2
748#define SUB_STMT_DUALITY_VIEW 3
749
751 public:
764};
765
766inline char const *show_system_thread(enum_thread_type thread) {
767#define RETURN_NAME_AS_STRING(NAME) \
768 case (NAME): \
769 return #NAME
770 switch (thread) {
771 static char buf[64];
786 default:
787 sprintf(buf, "<UNKNOWN SYSTEM THREAD: %d>", thread);
788 return buf;
789 }
790#undef RETURN_NAME_AS_STRING
791}
792
793/**
794 Storage engine specific thread local data.
795*/
796
797struct Ha_data {
798 /**
799 Storage engine specific thread local data.
800 Lifetime: one user connection.
801 */
802 void *ha_ptr;
803 /**
804 A memorizer to engine specific "native" transaction object to provide
805 storage engine detach-re-attach facility.
806 The server level transaction object can dissociate from storage engine
807 transactions. The released "native" transaction reference
808 can be hold in the member until it is reconciled later.
809 Lifetime: Depends on caller of @c hton::replace_native_transaction_in_thd.
810 For instance in the case of slave server applier handling XA transaction
811 it is from XA START to XA PREPARE.
812 */
814 /**
815 0: Life time: one statement within a transaction. If @@autocommit is
816 on, also represents the entire transaction.
817 @sa trans_register_ha()
818
819 1: Life time: one transaction within a connection.
820 If the storage engine does not participate in a transaction,
821 this should not be used.
822 @sa trans_register_ha()
823 */
825
826 /**
827 NULL: engine is not bound to this thread
828 non-NULL: engine is bound to this thread, engine shutdown forbidden
829 */
831
833};
834
835/**
836 An instance of the global read lock in a connection.
837 Implemented in lock.cc.
838*/
839
841 public:
846 };
847
849 : m_state(GRL_NONE),
852
853 bool lock_global_read_lock(THD *thd);
854 void unlock_global_read_lock(THD *thd);
855
856 /**
857 Check if this connection can acquire protection against GRL and
858 emit error if otherwise.
859 */
861 if (m_state) {
862 my_error(ER_CANT_UPDATE_WITH_READLOCK, MYF(0));
863 return true;
864 }
865 return false;
866 }
868 bool is_acquired() const { return m_state != GRL_NONE; }
870
871 private:
873 /**
874 In order to acquire the global read lock, the connection must
875 acquire shared metadata lock in GLOBAL namespace, to prohibit
876 all DDL.
877 */
879 /**
880 Also in order to acquire the global read lock, the connection
881 must acquire a shared metadata lock in COMMIT namespace, to
882 prohibit commits.
883 */
885};
886
887extern "C" void my_message_sql(uint error, const char *str, myf MyFlags);
888
889/**
890 This class keeps the context of transactional DDL statements. Currently only
891 CREATE TABLE with START TRANSACTION uses this context.
892*/
894 public:
895 explicit Transactional_ddl_context(THD *thd) : m_thd(thd) {
896 assert(m_thd != nullptr);
897 }
898
900 assert(!m_hton);
901 post_ddl();
902 }
903
904 void init(dd::String_type db, dd::String_type tablename,
905 const handlerton *hton);
906
907 bool inited() { return m_hton != nullptr; }
908
909 void rollback();
910
911 void post_ddl();
912
913 private:
914 // The current thread.
915 THD *m_thd{nullptr};
916
917 // Handlerton pointer to table's engine begin created.
918 const handlerton *m_hton{nullptr};
919
920 // Schema and table name being created.
923};
924
925struct PS_PARAM;
926
928 std::pair<Event_tracking_class, Event_tracking_information *>;
929using Event_tracking_data_stack = std::stack<Event_tracking_data>;
930
931/**
932 Base class for secondary engine statement context objects. Secondary
933 storage engines may create classes derived from this one which
934 contain state they need to preserve in lifecycle of this query.
935*/
937 public:
938 /**
939 Destructs the secondary engine statement context object. It is
940 called after the query execution has completed. Secondary engines
941 may override the destructor in subclasses and add code that
942 performs cleanup tasks that are needed after query execution.
943 */
945
946 virtual bool is_primary_engine_optimal() const { return true; }
947};
948
949/**
950 @class THD
951 For each client connection we create a separate thread with THD serving as
952 a thread/connection descriptor
953*/
954
955class THD : public MDL_context_owner,
956 public Query_arena,
957 public Open_tables_state {
958 public:
959 /**
960 Controlled memory stats for this session.
961 This member is the first in THD,
962 to initialize Thd_mem_cnt() before allocating more memory.
963 */
965
966 private:
967 bool is_stmt_prepare() const = delete;
970 inline bool is_regular() const = delete;
971
972 public:
974
975 /**
976 MARK_COLUMNS_NONE: Means mark_used_columns is not set and no indicator to
977 handler of fields used is set
978 MARK_COLUMNS_READ: Means a bit in read set is set to inform handler
979 that the field is to be read. Update covering_keys
980 and merge_keys too.
981 MARK_COLUMNS_WRITE: Means a bit is set in write set to inform handler
982 that it needs to update this field in write_row
983 and update_row.
984 MARK_COLUMNS_TEMP: Mark bit in read set, but ignore key sets.
985 Used by filesort().
986 */
988 /**
989 Used by Item::check_column_privileges() to tell which privileges
990 to check for.
991 Set to ~0ULL before starting to resolve a statement.
992 Set to desired privilege mask before calling a resolver function that will
993 call Item::check_column_privileges().
994 After use, restore previous value as current value.
995 */
997
998 private:
999 /**
1000 The lex to hold the parsed tree of conventional (non-prepared) queries.
1001 Whereas for prepared and stored procedure statements we use an own lex
1002 instance for each new query, for conventional statements we reuse
1003 the same lex. (@see dispatch_sql_command for details).
1004 */
1005 std::unique_ptr<LEX> main_lex;
1006
1007 public:
1008 LEX *lex; // parse tree descriptor
1009 dd::cache::Dictionary_client *dd_client() const // Get the dictionary client.
1010 {
1011 return m_dd_client.get();
1012 }
1013
1014 private:
1015 std::unique_ptr<dd::cache::Dictionary_client> m_dd_client;
1016
1017 /**
1018 The query associated with this statement.
1019 */
1022 std::atomic<bool> m_safe_to_display;
1023
1024 /**
1025 Currently selected catalog.
1026 */
1027
1029 /**
1030 Name of the current (default) database.
1031
1032 If there is the current (default) database, "db" contains its name. If
1033 there is no current (default) database, "db" is NULL and "db_length" is
1034 0. In other words, "db", "db_length" must either be NULL, or contain a
1035 valid database name.
1036
1037 @note this attribute is set and allocated by the slave SQL thread (for
1038 the THD of that thread); that thread is (and must remain, for now) the
1039 only responsible for freeing this member.
1040 */
1042
1043 /**
1044 Resource group context indicating the current resource group
1045 and if there are any warnings related to switching resource group.
1046 */
1048
1049 /**
1050 In some cases, we may want to modify the query (i.e. replace
1051 passwords with their hashes before logging the statement etc.).
1052
1053 In case the query was rewritten, the original query will live in
1054 m_query_string, while the rewritten query lives in rewritten_query.
1055 If rewritten_query is empty, m_query_string should be logged.
1056 If rewritten_query is non-empty, the rewritten query it contains
1057 should be used in logs (general log, slow query log, binary log).
1058
1059 Currently, password obfuscation is the only rewriting we do; more
1060 may follow at a later date, both pre- and post parsing of the query.
1061 Rewriting of binloggable statements must preserve all pertinent
1062 information.
1063
1064 Similar restrictions as for m_query_string (see there) hold for locking:
1065 - Value may only be (re)set from owning thread (current_thd)
1066 - Value must be modified using (reset|swap)_rewritten_query().
1067 Doing so will protect the update with LOCK_thd_query.
1068 - The owner (current_thd) may read the value without holding the lock.
1069 - Other threads may read the value, but must hold LOCK_thd_query to do so.
1070 */
1072
1073 /**
1074 Current query's secondary engine statement context.
1075 */
1076 std::unique_ptr<Secondary_engine_statement_context>
1078
1079 /* eligible secondary engine handlerton for this query */
1081
1082 public:
1083 /* Store a thread safe copy of protocol properties. */
1084 enum class cached_properties : int {
1085 NONE = 0, // No properties
1086 IS_ALIVE = 1, // protocol->is_connection_alive()
1087 RW_STATUS = 2, // protocol->get_rw_status()
1088 LAST = 4, // Next unused power of 2.
1089 ALL = (LAST - 1) // Mask selecting all properties.
1090 };
1093
1094 /* Used to execute base64 coded binlog events in MySQL server */
1096 /* Slave applier execution context */
1098
1099 /* Is transaction commit still pending */
1101
1102 /**
1103 The function checks whether the thread is processing queries from binlog,
1104 as automatically generated by mysqlbinlog.
1105
1106 @return true when the thread is a binlog applier
1107 */
1108 bool is_binlog_applier() const {
1109 return rli_fake && variables.pseudo_replica_mode;
1110 }
1111
1112 /**
1113 When the thread is a binlog or slave applier it detaches the engine
1114 ha_data associated with it and memorizes the fact of that.
1115 */
1117
1118 /*
1119 Set secondary_engine_statement_context to new context.
1120 This function assumes existing m_secondary_engine_statement_context is empty,
1121 such that there's only context throughout the query's lifecycle.
1122 */
1124 std::unique_ptr<Secondary_engine_statement_context> context);
1125
1128 }
1129
1131
1134 }
1135
1136 /**
1137 When the thread is a binlog or slave applier it reattaches the engine
1138 ha_data associated with it and memorizes the fact of that.
1139 */
1141
1142 /**
1143 @return true when the current binlog (rli_fake) or slave (rli_slave)
1144 applier thread has detached the engine ha_data,
1145 see @c rpl_detach_engine_ha_data.
1146 @note The detached transaction applier resets a memo
1147 mark at once with this check.
1148 */
1149 bool is_engine_ha_data_detached() const;
1150
1151 /// Iterates over the table and call check_and_registered_engine
1152 /// and emits error for non-composable engines
1153 /// @param[in] table_ref Tables involved in the query
1155
1157 /*
1158 Constant for THD::where initialization in the beginning of every query.
1159
1160 It's needed because we do not save/restore THD::where normally during
1161 primary (non subselect) query execution.
1162 */
1163 static const char *const DEFAULT_WHERE;
1164
1165 /** Additional network instrumentation for the server only. */
1167 /**
1168 Hash for user variables.
1169 User variables are per session,
1170 but can also be monitored outside of the session,
1171 so a lock is needed to prevent race conditions.
1172 Protected by @c LOCK_thd_data.
1173 */
1176 struct rand_struct rand; // used for authentication
1177 struct System_variables variables; // Changeable local variables
1178 struct System_status_var status_var; // Per thread statistic vars
1179 struct System_status_var
1180 *copy_status_var_ptr; // A copy of the statistic vars asof the start of
1181 // the query
1182 struct System_status_var *initial_status_var; /* used by show status */
1183 // has status_var already been added to global_status_var?
1185
1186 /**
1187 Session's connection attributes for the connected client
1188 */
1189 std::vector<char> m_connection_attributes;
1190
1191 /**
1192 Current query cost.
1193 @sa system_status_var::last_query_cost
1194 */
1196
1197 /**
1198 Current query partial plans.
1199 @sa system_status_var::last_query_partial_plans
1200 */
1202
1203 /**
1204 Clear the query costs attributes for the current query.
1205 */
1209 }
1210
1211 /**
1212 Save the current query costs attributes in
1213 the thread session status.
1214 Use this method only after the query execution is completed,
1215 so that
1216 @code SHOW SESSION STATUS like 'last_query_%' @endcode
1217 @code SELECT * from performance_schema.session_status
1218 WHERE VARIABLE_NAME like 'last_query_%' @endcode
1219 actually reports the previous query, not itself.
1220 */
1222 assert(!status_var_aggregated);
1225 }
1226
1227 /**
1228 Clear copy of the status variables.
1229 */
1231
1232 /**
1233 Copy status variables into a structure pointed by the specified pointer and
1234 keep track of the pointer internally.
1235
1236 @param dst_var status variable structure pointer, where internal status
1237 variables are copied into.
1238 */
1240 *dst_var = status_var;
1241 copy_status_var_ptr = dst_var;
1242 }
1243
1244 /**
1245 Copy status variables into a structure pointed by the specified pointer
1246 passed into copy_status_var method call.
1247 */
1249 if (copy_status_var_ptr) {
1250 /* Reset for values at start of next statement */
1252 }
1253 }
1254
1255 THR_LOCK_INFO lock_info; // Locking info of this thread
1256 /**
1257 Protects THD data accessed from other threads.
1258 The attributes protected are:
1259 - thd->is_killable (used by KILL statement and shutdown).
1260 - thd->user_vars (user variables, inspected by monitoring)
1261 Is locked when THD is deleted.
1262 */
1264
1265 /**
1266 Protects THD::m_query_string. No other mutexes should be locked
1267 while having this mutex locked.
1268 */
1270
1271 /**
1272 Protects THD::variables while being updated. This should be taken inside
1273 of LOCK_thd_data and outside of LOCK_global_system_variables.
1274 */
1276
1277#ifndef NDEBUG
1279#endif
1280
1281 /**
1282 Protects THD::m_protocol when it gets removed in x plugin.
1283 */
1285
1286 /**
1287 Protects THD::m_security_ctx from inspection (e.g. by old-style
1288 SHOW PROCESSLIST) while COM_CHANGE_USER changes the context.
1289 */
1291
1292 /**
1293 Protects query plan (SELECT/UPDATE/DELETE's) from being freed/changed
1294 while another thread explains it. Following structures are protected by
1295 this mutex:
1296 THD::Query_plan
1297 Modification_plan
1298 Query_block::join
1299 JOIN::plan_state
1300 Tree of Query_expression after THD::Query_plan was set till
1301 THD::Query_plan cleanup
1302 JOIN_TAB::select->quick
1303 Code that changes objects above should take this mutex.
1304 Explain code takes this mutex to block changes to named structures to
1305 avoid crashes in following functions:
1306 explain_single_table_modification
1307 explain_query
1308 Sql_cmd_explain_other_thread::execute
1309 When doing EXPLAIN CONNECTION:
1310 all explain code assumes that this mutex is already taken.
1311 When doing ordinary EXPLAIN:
1312 the mutex does need to be taken (no need to protect reading my own data,
1313 moreover EXPLAIN CONNECTION can't run on an ordinary EXPLAIN).
1314 */
1315 private:
1317
1318 /**
1319 Keep cached values of "connection alive" and "rw status". Update when
1320 pushing, popping or getting the protocol. Used by
1321 information_schema.processlist to avoid locking mutexes that might
1322 affect performance.
1323 */
1325 std::atomic<uint> m_cached_rw_status;
1326
1327 public:
1328 /// Locks the query plan of this THD
1331
1332 /** All prepared statements of this connection. */
1334
1335 /** Resolve and save the stack base for the current execution context. */
1336 void capture_stack_base(const void *local_marker) {
1337 m_stack_base = resolve_stack_pointer(local_marker);
1338 }
1339
1340 /** Set a base captured earlier, or clear it with nullptr. */
1341 void set_stack_base(const char *captured_base) {
1342 m_stack_base = captured_base;
1343 }
1344
1345 const char *stack_base() const { return m_stack_base; }
1346
1347 private:
1348 const char *m_stack_base{nullptr};
1349
1350 public:
1351 /**
1352 @note
1353 Some members of THD (currently 'Statement::db',
1354 'catalog' and 'query') are set and allocated by the slave SQL thread
1355 (for the THD of that thread); that thread is (and must remain, for now)
1356 the only responsible for freeing these 3 members. If you add members
1357 here, and you add code to set them in replication, don't forget to
1358 free_them_and_set_them_to_0 in replication properly. For details see
1359 the 'err:' label of the handle_slave_sql() in sql/slave.cc.
1360
1361 @see handle_slave_sql
1362 */
1363
1366
1369 if (sctx == m_security_ctx) return;
1370
1371 /*
1372 To prevent race conditions arising from concurrent threads executing
1373 I_S.PROCESSLIST, a mutex LOCK_thd_security_ctx safeguards the security
1374 context switch.
1375 */
1377 m_security_ctx = sctx;
1379 }
1381
1382 /**
1383 @note
1384 The optional password validation plugin doesn't have any API for
1385 temporally disable its functionality for a particular session.
1386 To get around this issue we introduce a boolean variable in the THD
1387 which we check before each call to the password validation plugin.
1388 Password validation is invoked from within the authentication plugin
1389 in the generate_authentication_string() method.
1390
1391 @see generate_authentication_string
1392 */
1394
1395 std::unique_ptr<Protocol_text> protocol_text; // Normal protocol
1396 std::unique_ptr<Protocol_binary> protocol_binary; // Binary protocol
1397
1398 const Protocol *get_protocol() const { return m_protocol; }
1399
1401
1403#ifndef NDEBUG
1404 if (current_thd != this) {
1405 /*
1406 When inspecting this thread from monitoring,
1407 the monitoring thread MUST lock LOCK_thd_data,
1408 to be allowed to safely inspect SSL status variables.
1409 */
1411 }
1412#endif
1413 return m_SSL;
1414 }
1415
1416 /**
1417 Asserts that the protocol is of type text or binary and then
1418 returns the m_protocol casted to Protocol_classic. This method
1419 is needed to prevent misuse of pluggable protocols by legacy code
1420 */
1422 assert(is_classic_protocol());
1423 return pointer_cast<const Protocol_classic *>(m_protocol);
1424 }
1425
1427
1428 private:
1429 Protocol *m_protocol; // Current protocol
1430 /**
1431 SSL data attached to this connection.
1432 This is an opaque pointer,
1433 When building with SSL, this pointer is non NULL
1434 only if the connection is using SSL.
1435 When building without SSL, this pointer is always NULL.
1436 The SSL data can be inspected to read per thread
1437 status variables,
1438 and this can be inspected while the thread is running.
1439 */
1440 SSL_handle m_SSL = {nullptr};
1441
1442 public:
1443 /**
1444 Query plan for EXPLAINable commands, should be locked with
1445 LOCK_query_plan before using.
1446 */
1448 private:
1449 THD *const thd;
1450 /// Original sql_command;
1452 /// LEX of topmost statement
1454 /// Query plan for UPDATE/DELETE/INSERT/REPLACE
1456 /// True if query is run in prepared statement
1457 bool is_ps;
1458
1459 explicit Query_plan(const Query_plan &); ///< not defined
1460 Query_plan &operator=(const Query_plan &); ///< not defined
1461
1462 public:
1463 /// Asserts that current_thd has locked this plan, if it does not own it.
1465#ifdef NDEBUG
1466 {}
1467#else
1468 ;
1469#endif
1470
1471 explicit Query_plan(THD *thd_arg)
1472 : thd(thd_arg),
1474 lex(nullptr),
1476 is_ps(false) {
1477 }
1478
1479 /**
1480 Set query plan.
1481
1482 @note This function takes THD::LOCK_query_plan mutex.
1483 */
1484 void set_query_plan(enum_sql_command sql_cmd, LEX *lex_arg, bool ps);
1485
1486 /*
1487 The 4 getters below expect THD::LOCK_query_plan to be already taken
1488 if called from another thread.
1489 */
1492 return sql_command;
1493 }
1494 LEX *get_lex() const {
1496 return lex;
1497 }
1500 return modification_plan;
1501 }
1502 bool is_ps_query() const {
1504 return is_ps;
1505 }
1506 bool is_single_table_plan() const;
1508
1510
1511 const LEX_CSTRING &catalog() const { return m_catalog; }
1512
1514
1515 private:
1517
1518 /*
1519 Points to info-string that we show in SHOW PROCESSLIST
1520 You are supposed to update thd->proc_info only if you have coded
1521 a time-consuming piece that MySQL can get stuck in for a long time.
1522
1523 Set it using the thd_proc_info(THD *thread, const char *message)
1524 macro/function.
1525
1526 This member is accessed and assigned without any synchronization.
1527 Therefore, it may point only to constant (statically
1528 allocated) strings, which memory won't go away over time.
1529 */
1530 const char *m_proc_info;
1531 /**
1532 Return the m_proc_info, possibly using the string of an older
1533 server release, according to @@terminology_use_previous.
1534
1535 @param sysvars Use the value of
1536 @@terminology_use_previous stored in this
1537 System_variables object.
1538
1539 @return The "proc_info", also known as "stage", of this thread.
1540 */
1541 const char *proc_info(const System_variables &sysvars) const;
1542
1543 public:
1544 // See comment in THD::enter_cond about why SUPPRESS_TSAN is needed.
1545 void enter_stage(const PSI_stage_info *stage, PSI_stage_info *old_stage,
1546 const char *calling_func, const char *calling_file,
1547 const unsigned int calling_line) SUPPRESS_TSAN;
1548 const char *proc_info() const { return m_proc_info; }
1549 /**
1550 Return the m_proc_info, possibly using the string of an older
1551 server release, according to
1552 @@session.terminology_use_previous.
1553
1554 @param invoking_thd Use
1555 @@session.terminology_use_previous of this session.
1556
1557 @return The "proc_info", also known as "stage", of this thread.
1558 */
1559 const char *proc_info_session(THD *invoking_thd) const {
1560 return proc_info(invoking_thd->variables);
1561 }
1564
1565 /*
1566 Used in error messages to tell user in what part of MySQL we found an
1567 error. E. g. when where= "having clause", if fix_fields() fails, user
1568 will know that the error was in having clause.
1569 */
1570 const char *where;
1571
1573
1577 /*
1578 A thread can hold named user-level locks. This variable
1579 contains granted tickets if a lock is present. See item_func.cc and
1580 chapter 'Miscellaneous functions', for functions GET_LOCK, RELEASE_LOCK.
1581 */
1584#ifndef NDEBUG
1585 uint dbug_sentry; // watch out for memory corruption
1586#endif
1588 /**
1589 Mutex protecting access to current_mutex and current_cond.
1590 */
1592 /**
1593 The mutex used with current_cond.
1594 @see current_cond
1595 */
1596 std::atomic<mysql_mutex_t *> current_mutex;
1597 /**
1598 Pointer to the condition variable the thread owning this THD
1599 is currently waiting for. If the thread is not waiting, the
1600 value is NULL. Set by THD::enter_cond().
1601
1602 If this thread is killed (shutdown or KILL stmt), another
1603 thread will broadcast on this condition variable so that the
1604 thread can be unstuck.
1605 */
1606 std::atomic<mysql_cond_t *> current_cond;
1607 /**
1608 Condition variable used for waiting by the THR_LOCK.c subsystem.
1609 */
1611
1612 /// @brief Enables ordering in ha_commit_low. Used in binlog::commit
1613 /// @note Additional requirements need to be met
1614 /// in order to invoke commit ordering in ha_commit_low
1615 /// @see is_ha_commit_low_invoking_commit_order
1617
1618 /// @brief Enables ordering in ha_commit_low. Used in binlog::commit
1619 /// @note Additional requirements need to be met
1620 /// in order to invoke commit ordering in ha_commit_low
1621 /// @see is_ha_commit_low_invoking_commit_order
1623
1624 /// @brief Obtains flag indicating whether additional ordering in the
1625 /// ha_commit_low function is enabled. If not, ordering will take place in
1626 /// binlog::commit
1627 /// @details Accessor for the m_is_low_level_commit_ordering_enabled
1628 /// @return When true, ha_commit_low may order this transaction
1630
1631 private:
1632 /// @brief Flag indicating whether additional ordering in the ha_commit_low
1633 /// function is enabled. If disabled, ordering will take place in
1634 /// binlog::commit. It is set up in binlog::commit
1636
1637 /**
1638 Type of current query: COM_STMT_PREPARE, COM_QUERY, etc.
1639 Set from first byte of the packet in do_command()
1640 */
1642
1643 private:
1645
1646 public:
1647 void set_admin_connection(bool admin) { m_is_admin_conn = admin; }
1648 bool is_admin_connection() const { return m_is_admin_conn; }
1649
1652 uint32 file_id; // for LOAD DATA INFILE
1653 /* remote (peer) port */
1655 struct timeval start_time;
1656 struct timeval user_time;
1657 /**
1658 Query start time, expressed in microseconds.
1659 */
1661
1662 private:
1663 /**
1664 Time spent waiting for TABLE locks and DATA locks.
1665 Expressed in microseconds.
1666 */
1668
1669 public:
1671 void inc_lock_usec(ulonglong usec);
1673 top = m_lock_usec;
1674 m_lock_usec = 0;
1675 }
1677
1678 /**
1679 Type of lock to be used for all DML statements, except INSERT, in cases
1680 when lock is not specified explicitly. Set to TL_WRITE or
1681 TL_WRITE_LOW_PRIORITY depending on whether low_priority_updates option is
1682 off or on.
1683 */
1685 /**
1686 Type of lock to be used for INSERT statement if lock is not specified
1687 explicitly. Set to TL_WRITE_CONCURRENT_INSERT or TL_WRITE_LOW_PRIORITY
1688 depending on whether low_priority_updates option is off or on.
1689 */
1691
1692 /* <> 0 if we are inside of trigger or stored function. */
1694
1695 /**
1696 Used by fill_status() to avoid acquiring LOCK_status mutex twice
1697 when this function is called recursively (e.g. queries
1698 that contains SELECT on I_S.GLOBAL_STATUS with subquery on the
1699 same I_S table).
1700 Incremented each time fill_status() function is entered and
1701 decremented each time before it returns from the function.
1702 */
1705
1706 private:
1707 /* container for handler's private per-connection data */
1709
1710 public:
1711 /**
1712 Retrieve Ha_data for a given slot. Each handler has a fixed slot nr.
1713 */
1714 Ha_data *get_ha_data(int slot) { return &ha_data[slot]; }
1715
1716 /**
1717 Copy ha_data into the provided argument. Used by Attachble_transaction.
1718 */
1720 /*
1721 Protect with LOCK_thd_data avoid accessing ha_data while it
1722 is being modified.
1723 */
1724 mysql_mutex_lock(&this->LOCK_thd_data);
1725 *backup = ha_data;
1726 mysql_mutex_unlock(&this->LOCK_thd_data);
1727 }
1728
1729 /**
1730 Restore ha_data from the provided backup copy.
1731 Used by Attachable_Transaction.
1732 */
1735 /*
1736 Protect with LOCK_thd_data to avoid e.g. KILL CONNECTION
1737 reading ha_data while it is being modified.
1738 */
1739 mysql_mutex_lock(&this->LOCK_thd_data);
1740 ha_data = backup;
1741 mysql_mutex_unlock(&this->LOCK_thd_data);
1742 }
1743
1744 /*
1745 Position of first event in Binlog
1746 *after* last event written by this
1747 thread.
1748 */
1750 void set_next_event_pos(const char *_filename, ulonglong _pos);
1751 void clear_next_event_pos();
1752
1753 /*
1754 Ptr to row event extra data to be written to Binlog /
1755 received from Binlog.
1756
1757 */
1759
1761
1762 /**
1763 * @brief Configure size of binlog transaction cache. Used to configure the
1764 * size of an individual cache, normally to a value that differs from the
1765 * default `binlog_cache_size` which controls the size otherwise.
1766 *
1767 * @note Assumes that the binlog cache manager already exist (i.e created
1768 * by call to binlog_setup_trx_data()) and is empty.
1769 *
1770 * @param new_size The new size of cache. Value exceeding
1771 * `max_binlog_cache_size` will be clamped and warning logged. Value must be
1772 * a multiple of IO_SIZE which is the block size for all binlog cache size
1773 * related variables.
1774 *
1775 * @return true if new cache size can't be configured, in that case the cache
1776 * is not usable.
1777 */
1778 bool binlog_configure_trx_cache_size(ulong new_size);
1779
1780 /*
1781 Public interface to write RBR events to the binlog
1782 */
1783 int binlog_write_table_map(TABLE *table, bool is_transactional,
1784 bool binlog_rows_query);
1785 int binlog_write_row(TABLE *table, bool is_transactional,
1786 const uchar *new_data,
1787 const unsigned char *extra_row_info);
1788 int binlog_delete_row(TABLE *table, bool is_transactional,
1789 const uchar *old_data,
1790 const unsigned char *extra_row_info);
1791 int binlog_update_row(TABLE *table, bool is_transactional,
1792 const uchar *old_data, const uchar *new_data,
1793 const uchar *extra_row_info);
1794 void set_server_id(uint32 sid) { server_id = sid; }
1795
1796 /*
1797 Member functions to handle pending event for row-level logging.
1798 */
1799 template <class RowsEventT>
1801 TABLE *table, uint32 serv_id, size_t needed, bool is_transactional,
1802 const unsigned char *extra_row_info, uint32 source_part_id = INT_MAX);
1803 Rows_log_event *binlog_get_pending_rows_event(bool is_transactional) const;
1804 inline int binlog_flush_pending_rows_event(bool stmt_end) {
1805 return (binlog_flush_pending_rows_event(stmt_end, false) ||
1806 binlog_flush_pending_rows_event(stmt_end, true));
1807 }
1808 int binlog_flush_pending_rows_event(bool stmt_end, bool is_transactional);
1809
1810 /**
1811 Determine the binlog format of the current statement.
1812
1813 @retval 0 if the current statement will be logged in statement
1814 format.
1815 @retval nonzero if the current statement will be logged in row
1816 format.
1817 */
1822 }
1823
1824 /**
1825 Determine if binlogging is currently disabled for this session.
1826
1827 There are two ways that binlogging can be disabled:
1828
1829 1. The binary log file is closed (globally). This can happen for
1830 two reasons: either --skip-log-bin was used on the command line,
1831 or a binlog write error happened when binlog_error_action=IGNORE_ERROR.
1832
1833 2. The binary log is disabled on session level. This can happen for
1834 two reasons: either the user has set @@session.sql_log_bin = 0,
1835 or the server code has internally disabled the binary log (by
1836 either setting thd->variables.option_bits &= ~OPTION_BIN_LOG or
1837 creating a Disable_binlog_guard object).
1838
1839 Even if this function returns true and the binary log is disabled,
1840 it is possible that the statement will be written to the binary log,
1841 in the cases where the server has merely temporarily disabled binary
1842 logging.
1843
1844 And even if this function returns false and the binary log is
1845 enabled, it is possible that the statement will not be written to
1846 the binary log, e.g. in case it is a no-op, it fails, it gets rolled
1847 back, or some other session closes the binary log due to a write
1848 error when using binlog_error_action=IGNORE_ERROR.
1849
1850 @retval true The binary log is currently disabled for the statement.
1851
1852 @retval false The binary log is currently enabled for the statement.
1853 */
1855
1856 /**
1857 Determine if binlogging is currently disabled for this session.
1858 If the binary log is disabled for this thread (either by log_bin=0 or
1859 sql_log_bin=0 or by log_replica_updates=0 for a slave thread), then the
1860 statement will not be written to the binary log.
1861
1862 @retval true The binary log is currently disabled for the statement.
1863
1864 @retval false The binary log is currently enabled for the statement.
1865 */
1867
1868 /**
1869 Checks whether binlog caches are disabled (binlog does not cache data) or
1870 empty in case binloggging is enabled in the current call to this function.
1871 This function may be safely called in case binlogging is disabled.
1872 @retval true binlog local caches are empty or disabled and binlogging is
1873 enabled
1874 @retval false binlog local caches are enabled and contain data or binlogging
1875 is disabled
1876 */
1878
1879 /**
1880 Determine if binloging is enabled in row format and write set extraction is
1881 enabled for this session
1882 @retval true if is enable
1883 @retval false otherwise
1884 */
1886
1887 /** Tells whether the given optimizer_switch flag is on */
1889 return (variables.optimizer_switch & flag);
1890 }
1891
1897
1900 }
1901
1905 }
1906
1910 }
1911
1913 return m_binlog_filter_state;
1914 }
1915
1916 /** Holds active timer object */
1918 /**
1919 After resetting(cancelling) timer, current timer object is cached
1920 with timer_cache timer to reuse.
1921 */
1923
1924 private:
1925 /*
1926 Indicates that the command which is under execution should ignore the
1927 'read_only' and 'super_read_only' options.
1928 */
1930
1931 /*
1932 Indicates that the command which is under execution should ignore the
1933 read only transaction mode.
1934 */
1936 /**
1937 Indicate if the current statement should be discarded
1938 instead of written to the binlog.
1939 This is used to discard special statements, such as
1940 DML or DDL that affects only 'local' (non replicated)
1941 tables, such as performance_schema.*
1942 */
1944
1945 /**
1946 Indicates the format in which the current statement will be
1947 logged. This can only be set from @c decide_logging_format().
1948 */
1950
1951 /**
1952 Bit field for the state of binlog warnings.
1953
1954 The first Lex::BINLOG_STMT_UNSAFE_COUNT bits list all types of
1955 unsafeness that the current statement has.
1956
1957 This must be a member of THD and not of LEX, because warnings are
1958 detected and issued in different places (@c
1959 decide_logging_format() and @c binlog_query(), respectively).
1960 Between these calls, the THD->lex object may change; e.g., if a
1961 stored routine is invoked. Only THD persists between the calls.
1962 */
1964
1965 /*
1966 Number of outstanding table maps, i.e., table maps in the
1967 transaction cache.
1968 */
1970 /*
1971 MTS: db names listing to be updated by the query databases
1972 */
1974
1975 /**
1976 The binary log position of the transaction.
1977
1978 The file and position are zero if the current transaction has not
1979 been written to the binary log.
1980
1981 @see set_trans_pos
1982 @see get_trans_pos
1983
1984 @todo Similar information is kept in the patch for BUG#11762277
1985 and by the master/slave heartbeat implementation. We should merge
1986 these positions instead of maintaining three different ones.
1987 */
1988 /**@{*/
1989 const char *m_trans_log_file;
1992 /**@}*/
1993 // NOTE: Ideally those two should be in Protocol,
1994 // but currently its design doesn't allow that.
1995 NET net; // client connection descriptor
1996 String packet; // dynamic buffer for network I/O
1997 public:
1998 const NET *get_net() const { return &net; }
1999
2001 skip_readonly_check = true;
2002 // Make a transaction skip the read only check set via the command
2003 // SET SESSION TRANSACTION READ ONLY
2005 }
2008 }
2010
2013 }
2017 }
2018
2022 }
2023
2024 void issue_unsafe_warnings();
2025
2028
2029 /*
2030 MTS: accessor to binlog_accessed_db_names list
2031 */
2034 }
2035
2036 /* MTS: method inserts a new unique name into binlog_updated_dbs */
2037 void add_to_binlog_accessed_dbs(const char *db);
2038
2039 bool is_applier_thread() const {
2042 }
2043
2044 private:
2045 std::unique_ptr<Transaction_ctx> m_transaction;
2046
2047 /** An utility struct for @c Attachable_trx */
2051 void backup(THD *thd);
2052 void restore(THD *thd);
2053
2054 /// SQL-command.
2056
2058
2059 /// Open-tables state.
2061
2062 /// SQL_MODE.
2064
2065 /// Transaction isolation level.
2067
2068 /// Ha_data array.
2070
2071 /// Transaction_ctx instance.
2073
2074 /// Transaction read-only state.
2076
2077 /// THD options.
2079
2080 /// Current transaction instrumentation.
2082
2083 /// Server status flags.
2085
2086 /// THD::in_lock_tables value.
2088
2089 /**
2090 Current time zone (i.e. @@session.time_zone) usage indicator.
2091
2092 Saving it allows data-dictionary code to read timestamp values
2093 as datetimes from system tables without disturbing user's statement.
2094
2095 TODO: We need to change DD code not to use @@session.time_zone at all and
2096 stick to UTC for internal storage of timestamps in DD objects.
2097 */
2099
2100 /**
2101 Transaction rollback request flag.
2102
2103 InnoDB can try to access table definition while rolling back regular
2104 transaction. So we need to be able to start attachable transaction
2105 without being affected by, and affecting, the rollback state of regular
2106 transaction.
2107 */
2109 };
2110
2111 public:
2113
2114 private:
2115 /**
2116 Class representing read-only attachable transaction, encapsulates
2117 knowledge how to backup state of current transaction, start
2118 read-only attachable transaction in SE, finalize it and then restore
2119 state of original transaction back. Also serves as a base class for
2120 read-write attachable transaction implementation.
2121 */
2123 public:
2124 Attachable_trx(THD *thd, Attachable_trx *prev_trx);
2125 virtual ~Attachable_trx();
2127 return m_prev_attachable_trx;
2128 }
2129 virtual bool is_read_only() const { return true; }
2130
2131 protected:
2132 /// THD instance.
2134
2136
2137 /**
2138 Attachable_trx which was active for the THD before when this
2139 transaction was started (NULL in most cases).
2140 */
2142
2143 /// Transaction state data.
2145
2146 private:
2149 };
2150
2151 /**
2152 A derived from THD::Attachable_trx class allows updates in
2153 the attachable transaction. Callers of the class methods must
2154 make sure the attachable_rw won't cause deadlock with the main transaction.
2155 The destructor does not invoke ha_commit_{stmt,trans} nor ha_rollback_trans
2156 on purpose.
2157 Burden to terminate the read-write instance also lies on the caller!
2158 In order to use this interface it *MUST* prove that no side effect to
2159 the global transaction state can be inflicted by a chosen method.
2160
2161 This class is being used only by class Gtid_table_access_context by
2162 replication and by dd::info_schema::Table_statistics.
2163 */
2164
2166 public:
2167 bool is_read_only() const override { return false; }
2168 explicit Attachable_trx_rw(THD *thd);
2169
2170 private:
2173 };
2174
2176
2177 public:
2179
2180 const Transaction_ctx *get_transaction() const { return m_transaction.get(); }
2181
2182 /**
2183 Changes the Transaction_ctx instance within THD-object. The previous
2184 Transaction_ctx instance is destroyed.
2185
2186 @note this is a THD-internal operation which MUST NOT be used outside.
2187
2188 @param transaction_ctx new Transaction_ctx instance to be associated with
2189 the THD-object.
2190 */
2191 void set_transaction(Transaction_ctx *transaction_ctx);
2192
2194
2195 Vio *active_vio = {nullptr};
2196
2197 /* Active network vio for clone remote connection. */
2198 Vio *clone_vio = {nullptr};
2199
2200 /**
2201 This is used to track transient changes to items during optimization of a
2202 prepared statement/stored procedure. Change objects are created by
2203 change_item_tree() in memory root of THD, and freed by
2204 rollback_item_tree_changes(). Changes recorded here are rolled back at
2205 the end of execution.
2206
2207 Transient changes require the following conditions:
2208 - The statement is not regular (ie. it is prepared or part of SP).
2209 - The change is performed outside preparation code (ie. it is
2210 performed during the optimization phase).
2211 - The change is applied to non-transient items (ie. items that have
2212 been created before or during preparation, not items that have been
2213 created in the optimization phase. Notice that the tree of AND/OR
2214 conditions is always as transient objects during optimization.
2215 Doing this should be quite harmless, though.)
2216 change_item_tree() only records changes to non-regular statements.
2217 It is also ensured that no changes are applied in preparation phase by
2218 asserting that the list of items is empty (see Sql_cmd_dml::prepare()).
2219 Other constraints are not enforced, in particular care must be taken
2220 so that all changes made during optimization to non-transient Items in
2221 non-regular statements must be recorded.
2222 */
2224
2225 /*
2226 A permanent memory area of the statement. For conventional
2227 execution, the parsed tree and execution runtime reside in the same
2228 memory root. In this case stmt_arena points to THD. In case of
2229 a prepared statement or a stored procedure statement, thd->mem_root
2230 conventionally points to runtime memory, and thd->stmt_arena
2231 points to the memory of the PS/SP, where the parsed tree of the
2232 statement resides. Whenever you need to perform a permanent
2233 transformation of a parsed tree, you should allocate new memory in
2234 stmt_arena, to allow correct re-execution of PS/SP.
2235 Note: in the parser, stmt_arena == thd, even for PS/SP.
2236 */
2238
2239 /*
2240 map for tables that will be updated for a multi-table update query
2241 statement, for other query statements, this will be zero.
2242 */
2244
2245 /* Tells if LAST_INSERT_ID(#) was called for the current statement */
2247 /*
2248 ALL OVER THIS FILE, "insert_id" means "*automatically generated* value for
2249 insertion into an auto_increment column".
2250 */
2251 /*
2252 This is the first autogenerated insert id which was *successfully*
2253 inserted by the previous statement (exactly, if the previous statement
2254 didn't successfully insert an autogenerated insert id, then it's the one
2255 of the statement before, etc).
2256 It can also be set by SET LAST_INSERT_ID=# or SELECT LAST_INSERT_ID(#).
2257 It is returned by LAST_INSERT_ID().
2258 */
2260 /*
2261 Variant of the above, used for storing in statement-based binlog. The
2262 difference is that the one above can change as the execution of a stored
2263 function progresses, while the one below is set once and then does not
2264 change (which is the value which statement-based binlog needs).
2265 */
2267 /*
2268 This is the first autogenerated insert id which was *successfully*
2269 inserted by the current statement. It is maintained only to set
2270 first_successful_insert_id_in_prev_stmt when statement ends.
2271 */
2273 /*
2274 We follow this logic:
2275 - when stmt starts, first_successful_insert_id_in_prev_stmt contains the
2276 first insert id successfully inserted by the previous stmt.
2277 - as stmt makes progress, handler::insert_id_for_cur_row changes;
2278 every time get_auto_increment() is called,
2279 auto_inc_intervals_in_cur_stmt_for_binlog is augmented with the
2280 reserved interval (if statement-based binlogging).
2281 - at first successful insertion of an autogenerated value,
2282 first_successful_insert_id_in_cur_stmt is set to
2283 handler::insert_id_for_cur_row.
2284 - when stmt goes to binlog,
2285 auto_inc_intervals_in_cur_stmt_for_binlog is binlogged if
2286 non-empty.
2287 - when stmt ends, first_successful_insert_id_in_prev_stmt is set to
2288 first_successful_insert_id_in_cur_stmt.
2289 */
2290 /*
2291 stmt_depends_on_first_successful_insert_id_in_prev_stmt is set when
2292 LAST_INSERT_ID() is used by a statement.
2293 If it is set, first_successful_insert_id_in_prev_stmt_for_binlog will be
2294 stored in the statement-based binlog.
2295 This variable is CUMULATIVE along the execution of a stored function or
2296 trigger: if one substatement sets it to 1 it will stay 1 until the
2297 function/trigger ends, thus making sure that
2298 first_successful_insert_id_in_prev_stmt_for_binlog does not change anymore
2299 and is propagated to the caller for binlogging.
2300 */
2302 /*
2303 List of auto_increment intervals reserved by the thread so far, for
2304 storage in the statement-based binlog.
2305 Note that its minimum is not first_successful_insert_id_in_cur_stmt:
2306 assuming a table with an autoinc column, and this happens:
2307 INSERT INTO ... VALUES(3);
2308 SET INSERT_ID=3; INSERT IGNORE ... VALUES (NULL);
2309 then the latter INSERT will insert no rows
2310 (first_successful_insert_id_in_cur_stmt == 0), but storing "INSERT_ID=3"
2311 in the binlog is still needed; the list's minimum will contain 3.
2312 This variable is cumulative: if several statements are written to binlog
2313 as one (stored functions or triggers are used) this list is the
2314 concatenation of all intervals reserved by all statements.
2315 */
2317 /* Used by replication and SET INSERT_ID */
2319 /*
2320 There is BUG#19630 where statement-based replication of stored
2321 functions/triggers with two auto_increment columns breaks.
2322 We however ensure that it works when there is 0 or 1 auto_increment
2323 column; our rules are
2324 a) on master, while executing a top statement involving substatements,
2325 first top- or sub- statement to generate auto_increment values wins the
2326 exclusive right to see its values be written to binlog (the write
2327 will be done by the statement or its caller), and the losers won't see
2328 their values be written to binlog.
2329 b) on slave, while replicating a top statement involving substatements,
2330 first top- or sub- statement to need to read auto_increment values from
2331 the master's binlog wins the exclusive right to read them (so the losers
2332 won't read their values from binlog but instead generate on their own).
2333 a) implies that we mustn't backup/restore
2334 auto_inc_intervals_in_cur_stmt_for_binlog.
2335 b) implies that we mustn't backup/restore auto_inc_intervals_forced.
2336
2337 If there are more than 1 auto_increment columns, then intervals for
2338 different columns may mix into the
2339 auto_inc_intervals_in_cur_stmt_for_binlog list, which is logically wrong,
2340 but there is no point in preventing this mixing by preventing intervals
2341 from the secondly inserted column to come into the list, as such
2342 prevention would be wrong too.
2343 What will happen in the case of
2344 INSERT INTO t1 (auto_inc) VALUES(NULL);
2345 where t1 has a trigger which inserts into an auto_inc column of t2, is
2346 that in binlog we'll store the interval of t1 and the interval of t2 (when
2347 we store intervals, soon), then in slave, t1 will use both intervals, t2
2348 will use none; if t1 inserts the same number of rows as on master,
2349 normally the 2nd interval will not be used by t1, which is fine. t2's
2350 values will be wrong if t2's internal auto_increment counter is different
2351 from what it was on master (which is likely). In 5.1, in mixed binlogging
2352 mode, row-based binlogging is used for such cases where two
2353 auto_increment columns are inserted.
2354 */
2358 }
2361 /* It's the first time we read it */
2365 }
2367 }
2374 }
2375
2376 /*
2377 Used by Intvar_log_event::do_apply_event() and by "SET INSERT_ID=#"
2378 (mysqlbinlog). We'll soon add a variant which can take many intervals in
2379 argument.
2380 */
2382 auto_inc_intervals_forced.clear(); // in case of multiple SET INSERT_ID
2384 }
2385
2386 /**
2387 Stores the result of the FOUND_ROWS() function. Set at query end, stable
2388 throughout the query.
2389 */
2391 /**
2392 Dynamic, collected and set also in subqueries. Not stable throughout query.
2393 previous_found_rows is a snapshot of this take at query end making it
2394 stable throughout the next query, see update_previous_found_rows.
2395 */
2397
2398 /*
2399 Indicate if the gtid_executed table is being operated implicitly
2400 within current transaction. This happens because we are inserting
2401 a GTID specified through SET GTID_NEXT by user client or
2402 slave SQL thread/workers.
2403 */
2405 /*
2406 Indicate that a sub-statement is being operated implicitly
2407 within current transaction.
2408 As we don't want that this implicit sub-statement to consume the
2409 GTID of the actual transaction, we set it true at the beginning of
2410 the sub-statement and set it false again after "committing" the
2411 sub-statement.
2412 When it is true, the applier will not save the transaction owned
2413 gtid into mysql.gtid_executed table before transaction prepare, as
2414 it does when binlog is disabled, or binlog is enabled and
2415 log_replica_updates is disabled.
2416 Also the flag is made to defer updates to the slave info table from
2417 intermediate commits by non-atomic DDL.
2418 Rpl_info_table::do_flush_info(), rpl_rli.h::is_atomic_ddl_commit_on_slave()
2419 uses this flag.
2420 */
2422
2423 private:
2424 /**
2425 Stores the result of ROW_COUNT() function.
2426
2427 ROW_COUNT() function is a MySQL extension, but we try to keep it
2428 similar to ROW_COUNT member of the GET DIAGNOSTICS stack of the SQL
2429 standard (see SQL99, part 2, search for ROW_COUNT). Its value is
2430 implementation defined for anything except INSERT, DELETE, UPDATE.
2431
2432 ROW_COUNT is assigned according to the following rules:
2433
2434 - In my_ok():
2435 - for DML statements: to the number of affected rows;
2436 - for DDL statements: to 0.
2437
2438 - In my_eof(): to -1 to indicate that there was a result set.
2439
2440 We derive this semantics from the JDBC specification, where int
2441 java.sql.Statement.getUpdateCount() is defined to (sic) "return the
2442 current result as an update count; if the result is a ResultSet
2443 object or there are no more results, -1 is returned".
2444
2445 - In my_error(): to -1 to be compatible with the MySQL C API and
2446 MySQL ODBC driver.
2447
2448 - For SIGNAL statements: to 0 per WL#2110 specification (see also
2449 sql_signal.cc comment). Zero is used since that's the "default"
2450 value of ROW_COUNT in the Diagnostics Area.
2451 */
2452
2453 longlong m_row_count_func; /* For the ROW_COUNT() function */
2454
2455 public:
2457
2458 inline void set_row_count_func(longlong row_count_func) {
2459 m_row_count_func = row_count_func;
2460 }
2461
2463
2464 private:
2465 /**
2466 Number of rows we actually sent to the client, including "synthetic"
2467 rows in ROLLUP etc.
2468 */
2470
2471 /**
2472 Number of rows read and/or evaluated for a statement. Used for
2473 slow log reporting.
2474
2475 An examined row is defined as a row that is read and/or evaluated
2476 according to a statement condition, including in
2477 create_sort_index(). Rows may be counted more than once, e.g., a
2478 statement including ORDER BY could possibly evaluate the row in
2479 filesort() before reading it for e.g. update.
2480 */
2482
2483 private:
2485
2486 public:
2487 void set_user_connect(USER_CONN *uc);
2488 const USER_CONN *get_user_connect() const { return m_user_connect; }
2489
2492
2494
2496
2498
2500
2501 public:
2503
2505
2507
2510
2520 void inc_status_sort_range();
2522 void inc_status_sort_scan();
2525
2527#if defined(ENABLED_PROFILING)
2528 std::unique_ptr<PROFILING> profiling;
2529#endif
2530
2531 /** Current stage progress instrumentation. */
2533 /** Current statement digest. */
2535 /** Current statement digest token array. */
2536 unsigned char *m_token_array;
2537 /** Top level statement digest. */
2539
2540 /** Current statement instrumentation. */
2542#ifdef HAVE_PSI_STATEMENT_INTERFACE
2543 /** Current statement instrumentation state. */
2545#endif /* HAVE_PSI_STATEMENT_INTERFACE */
2546
2547 /** Current transaction instrumentation. */
2549#ifdef HAVE_PSI_TRANSACTION_INTERFACE
2550 /** Current transaction instrumentation state. */
2552#endif /* HAVE_PSI_TRANSACTION_INTERFACE */
2553
2554 /** Idle instrumentation. */
2556#ifdef HAVE_PSI_IDLE_INTERFACE
2557 /** Idle instrumentation state. */
2559#endif /* HAVE_PSI_IDLE_INTERFACE */
2560 /** True if the server code is IDLE for this connection. */
2562
2563 /*
2564 Id of current query. Statement can be reused to execute several queries
2565 query_id is global in context of the whole MySQL server.
2566 ID is automatically generated from mutex-protected counter.
2567 It's used in handler code for various purposes: to check which columns
2568 from table are necessary for this select, to check if it's necessary to
2569 update auto-updatable fields (like auto_increment and timestamp).
2570 */
2572
2573 /* Statement id is thread-wide. This counter is used to generate ids */
2577 /**
2578 This counter is 32 bit because of the client protocol.
2579
2580 @note It is not meant to be used for my_thread_self(), see @c real_id for
2581 this.
2582
2583 @note Set to reserved_thread_id on initialization. This is a magic
2584 value that is only to be used for temporary THDs not present in
2585 the global THD list.
2586 */
2587 private:
2589
2590 public:
2591 /**
2592 Assign a value to m_thread_id by calling
2593 Global_THD_manager::get_new_thread_id().
2594 */
2595 void set_new_thread_id();
2597
2601
2602 // Check if this THD belongs to a system thread.
2604
2605 // Check if this THD belongs to a dd bootstrap system thread.
2606 bool is_dd_system_thread() const {
2609 }
2610
2611 // Check if this THD belongs to the initialize system thread. The
2612 // initialize thread executes statements that are compiled into the
2613 // server.
2616 }
2617
2618 // Check if this THD is executing statements passed through a init file.
2621 }
2622
2623 // Check if this THD belongs to a bootstrap system thread. Note that
2624 // this thread type may execute statements submitted by the user.
2628 }
2629
2630 // Check if this THD belongs to a server upgrade thread. Server upgrade
2631 // threads execute statements that are compiled into the server.
2634 }
2635
2636 /*
2637 Current or next transaction isolation level.
2638 When a connection is established, the value is taken from
2639 @@session.tx_isolation (default transaction isolation for
2640 the session), which is in turn taken from @@global.tx_isolation
2641 (the global value).
2642 If there is no transaction started, this variable
2643 holds the value of the next transaction's isolation level.
2644 When a transaction starts, the value stored in this variable
2645 becomes "actual".
2646 At transaction commit or rollback, we assign this variable
2647 again from @@session.tx_isolation.
2648 The only statement that can otherwise change the value
2649 of this variable is SET TRANSACTION ISOLATION LEVEL.
2650 Its purpose is to effect the isolation level of the next
2651 transaction in this session. When this statement is executed,
2652 the value in this variable is changed. However, since
2653 this statement is only allowed when there is no active
2654 transaction, this assignment (naturally) only affects the
2655 upcoming transaction.
2656 At the end of the current active transaction the value is
2657 be reset again from @@session.tx_isolation, as described
2658 above.
2659 */
2661 /*
2662 Current or next transaction access mode.
2663 See comment above regarding tx_isolation.
2664 */
2666 /*
2667 Transaction cannot be rolled back must be given priority.
2668 When two transactions conflict inside InnoDB, the one with
2669 greater priority wins.
2670 */
2672 /*
2673 All transactions executed by this thread will have high
2674 priority mode, independent of tx_priority value.
2675 */
2677
2679
2680 // For user variables replication
2682 MEM_ROOT *user_var_events_alloc; /* Allocate above array elements here */
2683
2684 /**
2685 Used by MYSQL_BIN_LOG to maintain the commit queue for binary log
2686 group commit.
2687 */
2689
2690 /**
2691 The member is served for marking a query that CREATEs or ALTERs
2692 a table declared with a TIMESTAMP column as dependent on
2693 @@session.explicit_defaults_for_timestamp.
2694 Is set to true by parser, unset at the end of the query.
2695 Possible marking in checked by binary logger.
2696 */
2698
2699 /**
2700 Functions to set and get transaction position.
2701
2702 These functions are used to set the transaction position for the
2703 transaction written when committing this transaction.
2704 */
2705 /**@{*/
2706 void set_trans_pos(const char *file, my_off_t pos) {
2707 DBUG_TRACE;
2708 assert(((file == nullptr) && (pos == 0)) ||
2709 ((file != nullptr) && (pos != 0)));
2710 if (file) {
2711 DBUG_PRINT("enter", ("file: %s, pos: %llu", file, pos));
2712 // Only the file name should be used, not the full path
2716 assert(strlen(m_trans_log_file) <= FN_REFLEN);
2718 } else {
2719 m_trans_log_file = nullptr;
2720 m_trans_fixed_log_file = nullptr;
2721 }
2722
2723 m_trans_end_pos = pos;
2724 DBUG_PRINT("return",
2725 ("m_trans_log_file: %s, m_trans_fixed_log_file: %s, "
2726 "m_trans_end_pos: %llu",
2728 return;
2729 }
2730
2731 void get_trans_pos(const char **file_var, my_off_t *pos_var) const {
2732 DBUG_TRACE;
2733 if (file_var) *file_var = m_trans_log_file;
2734 if (pos_var) *pos_var = m_trans_end_pos;
2735 DBUG_PRINT("return",
2736 ("file: %s, pos: %llu", file_var ? *file_var : "<none>",
2737 pos_var ? *pos_var : 0));
2738 return;
2739 }
2740
2741 void get_trans_fixed_pos(const char **file_var, my_off_t *pos_var) const {
2742 DBUG_TRACE;
2743 if (file_var) *file_var = m_trans_fixed_log_file;
2744 if (pos_var) *pos_var = m_trans_end_pos;
2745 DBUG_PRINT("return",
2746 ("file: %s, pos: %llu", file_var ? *file_var : "<none>",
2747 pos_var ? *pos_var : 0));
2748 return;
2749 }
2750
2751 /**@}*/
2752
2753 /*
2754 Error code from committing or rolling back the transaction.
2755 */
2764
2765 /*
2766 Define durability properties that engines may check to
2767 improve performance.
2768 */
2770
2771 /*
2772 If checking this in conjunction with a wait condition, please
2773 include a check after enter_cond() if you want to avoid a race
2774 condition. For details see the implementation of awake(),
2775 especially the "broadcast" part.
2776 */
2779 KILL_CONNECTION = ER_SERVER_SHUTDOWN,
2780 KILL_QUERY = ER_QUERY_INTERRUPTED,
2781 KILL_TIMEOUT = ER_QUERY_TIMEOUT,
2782 KILLED_NO_VALUE /* means neither of the states */
2784 std::atomic<killed_state> killed;
2785
2786 /**
2787 Whether we are currently in the execution phase of an EXPLAIN ANALYZE query.
2788 If so, send_kill_message() won't actually set an error; we will add a
2789 warning near the end of the execution instead.
2790 */
2792
2793 /**
2794 When operation on DD tables is in progress then THD is set to kill immune
2795 mode.
2796 This member holds DD_kill_immunizer object created to make DD operations
2797 immune from the kill operations. Member also indicated whether THD is in
2798 kill immune mode or not.
2799 */
2801
2802 /* scramble - random string sent to client on handshake */
2804
2805 /// @todo: slave_thread is completely redundant, we should use 'system_thread'
2806 /// instead /sven
2808
2810
2811 private:
2812 /**
2813 Set to true if execution of the current compound statement
2814 can not continue. In particular, disables activation of
2815 CONTINUE or EXIT handlers of stored routines.
2816 Reset in the end of processing of the current user request, in
2817 @see mysql_reset_thd_for_next_command().
2818 */
2820
2821 public:
2822 /**
2823 Set by a storage engine to request the entire
2824 transaction (that possibly spans multiple engines) to
2825 rollback. Reset in ha_rollback.
2826 */
2828 /**
2829 true if we are in a sub-statement and the current error can
2830 not be safely recovered until we left the sub-statement mode.
2831 In particular, disables activation of CONTINUE and EXIT
2832 handlers inside sub-statements. E.g. if it is a deadlock
2833 error and requires a transaction-wide rollback, this flag is
2834 raised (traditionally, MySQL first has to close all the reads
2835 via @see handler::ha_index_or_rnd_end() and only then perform
2836 the rollback).
2837 Reset to false when we leave the sub-statement mode.
2838 */
2843 /**
2844 True if a slave error. Causes the slave to stop. Not the same
2845 as the statement execution error (is_error()), since
2846 a statement may be expected to return an error, e.g. because
2847 it returned an error on master, and this is OK on the slave.
2848 */
2850
2851 /** is set if some thread specific value(s) used in a statement. */
2853 /**
2854 is set if a statement accesses a temporary table created through
2855 CREATE TEMPORARY TABLE.
2856 */
2859 bool enable_slow_log; /* enable slow log for current statement */
2860 /* set during loop of derived table processing */
2862 // Set while parsing INFORMATION_SCHEMA system views.
2864 // Set while parsing JSON duality view.
2866
2867 /** Current SP-runtime context. */
2871
2872 /** number of name_const() substitutions, see sp_head.cc:subst_spvars() */
2874
2875 /* Used by the sys_var class to store temporary values */
2876 union {
2883
2884 struct {
2885 /*
2886 If true, mysql_bin_log::write(Log_event) call will not write events to
2887 binlog, and maintain 2 below variables instead (use
2888 mysql_bin_log.start_union_events to turn this on)
2889 */
2891 /*
2892 If true, at least one mysql_bin_log::write(Log_event) call has been
2893 made after last mysql_bin_log.start_union_events() call.
2894 */
2896 /*
2897 If true, at least one mysql_bin_log::write(Log_event e), where
2898 e.cache_stmt == true call has been made after last
2899 mysql_bin_log.start_union_events() call.
2900 */
2902
2903 /*
2904 'queries' (actually SP statements) that run under inside this binlog
2905 union have thd->query_id >= first_query_id.
2906 */
2909
2910 /**
2911 Internal parser state.
2912 Note that since the parser is not re-entrant, we keep only one parser
2913 state here. This member is valid only when executing code during parsing.
2914 */
2916
2918
2920
2921 /**
2922 Array of active audit plugins which have been used by this THD.
2923 This list is later iterated to invoke release_thd() on those
2924 plugins.
2925 */
2927 /**
2928 Array of bits indicating which audit classes have already been
2929 added to the list of audit plugins which are currently in use.
2930 */
2932
2933#if defined(ENABLED_DEBUG_SYNC)
2934 /* Debug Sync facility. See debug_sync.cc. */
2935 struct st_debug_sync_control *debug_sync_control;
2936#endif /* defined(ENABLED_DEBUG_SYNC) */
2937
2938 // We don't want to load/unload plugins for unit tests.
2940
2941 /*
2942 Audit API events are generated, when this flag is true. The flag
2943 is initially true, but it can be set false in some cases, e.g.
2944 Session Service's THDs are created with auditing disabled. Auditing
2945 is enabled on EVENT_TRACKING_CONNECTION_CONNECT event.
2946 */
2948
2949 explicit THD(bool enable_plugins = true);
2950
2951 /*
2952 The THD dtor is effectively split in two:
2953 THD::release_resources() and ~THD().
2954
2955 We want to minimize the time we hold LOCK_thd_list,
2956 so when destroying a global thread, do:
2957
2958 thd->release_resources()
2959 Global_THD_manager::get_instance()->remove_thd();
2960 delete thd;
2961 */
2962 ~THD() override;
2963
2964 void release_resources();
2965 /**
2966 @returns true if THD resources are released.
2967 */
2968 bool release_resources_done() const;
2969 /**
2970 Check if THD is being disposed (i.e. m_thd_life_cycle_stage >=
2971 SCHEDULED_FOR_DISPOSAL)
2972
2973 Non-owner thread should acquire LOCK_thd_data to check THD state without
2974 getting into races.
2975
2976 @returns true of THD is being disposed.
2977 */
2978 bool is_being_disposed() const;
2979
2980 private:
2981 /**
2982 Represents life cycle stages of THD instance.
2983 Stage transition in THD clean up:
2984 1. ACTIVE -> ACTIVE_AND_CLEAN
2985
2986 Stage transition in THD disposal:
2987 1. ACTIVE -> SCHEDULED_FOR_DISPOSAL -> CLEANED_UP -> RESOURCES_RELEASED
2988 -> DISPOSED.
2989 2. ACTIVE_AND_CLEAN -> CLEANED_UP -> RESOURCES_RELEASED -> DISPOSED.
2990 */
2997 DISPOSED
3000 enum_thd_life_cycle_stages::ACTIVE};
3001
3002 /**
3003 Set THD in ACTIVE life stage to disposal stage.
3004
3005 To avoid race conditions with non-owner thread checking THD disposal state,
3006 LOCK_thd_data should be acquired before changing THD stage to disposal
3007 stage.
3008 */
3009 void start_disposal();
3010
3011 /**
3012 @returns true if THD is cleaned up.
3013 */
3014 bool is_cleanup_done();
3015 void cleanup(void);
3016
3017 void init(void);
3018
3019 public:
3020 /**
3021 Initialize memory roots necessary for query processing and (!)
3022 pre-allocate memory for it. We can't do that in THD constructor because
3023 there are use cases (acl_init, watcher threads,
3024 killing mysqld) where it's vital to not allocate excessive and not used
3025 memory. Note, that we still don't return error from init_query_mem_roots()
3026 if preallocation fails, we should notice that at the first call to
3027 alloc_root.
3028 */
3029 void init_query_mem_roots();
3030 void cleanup_connection(void);
3031 /**
3032 Sets the THD::variables values that depend on the protocol
3033
3034 Some THD::variable values take different default based on properties of the
3035 protocol, e.g. capabilities etc. This function sets these values.
3036
3037 Called when:
3038 1. A new connection is established
3039 2. A reset connection or change_user is done
3040 */
3042 void cleanup_after_query();
3043 void store_globals();
3044 void restore_globals();
3045
3046 inline void set_active_vio(Vio *vio) {
3048 active_vio = vio;
3050 }
3051
3052 void set_ssl(Vio *vio);
3053
3054 inline void clear_active_vio() {
3056 active_vio = nullptr;
3057 m_SSL = nullptr;
3059 }
3060
3061 /** Set active clone network Vio for remote clone.
3062 @param[in] vio network vio */
3063 inline void set_clone_vio(Vio *vio) {
3065 clone_vio = vio;
3067 }
3068
3069 /** Clear clone network Vio for remote clone. */
3070 inline void clear_clone_vio() {
3072 clone_vio = nullptr;
3074 }
3075
3076 /** Check if clone network Vio is active. */
3077 inline bool check_clone_vio() {
3079 const bool is_active = (clone_vio != nullptr);
3081 return (is_active);
3082 }
3083
3084 /** Shutdown clone vio, if active. */
3085 void shutdown_clone_vio();
3086
3088
3089 void shutdown_active_vio();
3090 void awake(THD::killed_state state_to_set);
3091
3092 /** Disconnect the associated communication endpoint. */
3093 void disconnect(bool server_shutdown = false);
3094
3096 /* The query can be logged in row format or in statement format. */
3098
3099 /* The query has to be logged in statement format. */
3101
3104
3105 int binlog_query(enum_binlog_query_type qtype, const char *query,
3106 size_t query_len, bool is_trans, bool direct,
3107 bool suppress_use, int errcode);
3108
3109 // Begin implementation of MDL_context_owner interface.
3110
3112 const PSI_stage_info *stage, PSI_stage_info *old_stage,
3113 const char *src_function, const char *src_file,
3114 int src_line) override {
3115 DBUG_TRACE;
3117 /*
3118 Sic: We don't lock LOCK_current_cond here.
3119 If we did, we could end up in deadlock with THD::awake()
3120 which locks current_mutex while LOCK_current_cond is locked.
3121 */
3122 current_mutex = mutex;
3123 current_cond = cond;
3124 enter_stage(stage, old_stage, src_function, src_file, src_line);
3125 return;
3126 }
3127
3128 void exit_cond(const PSI_stage_info *stage, const char *src_function,
3129 const char *src_file, int src_line) override {
3130 DBUG_TRACE;
3131 /*
3132 current_mutex must be unlocked _before_ LOCK_current_cond is
3133 locked (if that would not be the case, you'll get a deadlock if someone
3134 does a THD::awake() on you).
3135 */
3138 current_mutex = nullptr;
3139 current_cond = nullptr;
3141 enter_stage(stage, nullptr, src_function, src_file, src_line);
3142 return;
3143 }
3144
3145 int is_killed() const final { return killed; }
3147 /*
3148 We need to return if this thread can have any commit order waiters
3149 which are still accounted by MDL deadlock detector (even in absence
3150 of any MDL locks). We approximate this check by testing whether
3151 this thread is replication applier. Doing more precise check is going
3152 to be more expensive and possibly racy.
3153 */
3154 return slave_thread;
3155 }
3156
3157 THD *get_thd() override { return this; }
3158
3159 /**
3160 A callback to the server internals that is used to address
3161 special cases of the locking protocol.
3162 Invoked when acquiring an exclusive lock, for each thread that
3163 has a conflicting shared metadata lock.
3164
3165 This function aborts waiting of the thread on a data lock, to make
3166 it notice the pending exclusive lock and back off.
3167
3168 @note This function does not wait for the thread to give away its
3169 locks. Waiting is done outside for all threads at once.
3170
3171 @param ctx_in_use The MDL context owner (thread) to wake up.
3172 @param needs_thr_lock_abort Indicates that to wake up thread
3173 this call needs to abort its waiting
3174 on table-level lock.
3175 */
3176 void notify_shared_lock(MDL_context_owner *ctx_in_use,
3177 bool needs_thr_lock_abort) override;
3178
3179 bool notify_hton_pre_acquire_exclusive(const MDL_key *mdl_key,
3180 bool *victimized) override;
3181
3182 void notify_hton_post_release_exclusive(const MDL_key *mdl_key) override;
3183
3184 /**
3185 Provide thread specific random seed for MDL_context's PRNG.
3186
3187 Note that even if two connections will request seed during handling of
3188 statements which were started at exactly the same time, and thus will
3189 get the same values in PRNG at the start, they will naturally diverge
3190 soon, since calls to PRNG in MDL subsystem are affected by many factors
3191 making process quite random. OTOH the fact that we use time as a seed
3192 gives more randomness and thus better coverage in tests as opposed to
3193 using thread_id for the same purpose.
3194 */
3195 uint get_rand_seed() const override { return (uint)start_utime; }
3196
3197 // End implementation of MDL_context_owner interface.
3198
3199 inline bool is_strict_mode() const {
3200 return (variables.sql_mode &
3202 }
3203 inline const CHARSET_INFO *collation() {
3204 return variables.collation_server ? variables.collation_server
3206 }
3208 time_zone_used = true;
3209 return variables.time_zone;
3210 }
3211 time_t query_start_in_secs() const { return start_time.tv_sec; }
3213 void set_time();
3214 void set_time(const struct timeval *t) {
3215 user_time = *t;
3216 set_time();
3217 }
3218 inline bool is_fsp_truncate_mode() const {
3220 }
3221
3224 }
3225
3226 /**
3227 Evaluate the current time, and if it exceeds the long-query-time
3228 setting, mark the query as slow.
3229 */
3231
3233
3234 /*
3235 Call when it is clear that the query is ended and we have collected the
3236 right value for current_found_rows. Calling this method makes a snapshot of
3237 that value and makes it ready and stable for subsequent FOUND_ROWS() call
3238 in the next statement.
3239 */
3242 }
3243
3244 /**
3245 Returns true if session is in a multi-statement transaction mode.
3246
3247 OPTION_NOT_AUTOCOMMIT: When autocommit is off, a multi-statement
3248 transaction is implicitly started on the first statement after a
3249 previous transaction has been ended.
3250
3251 OPTION_BEGIN: Regardless of the autocommit status, a multi-statement
3252 transaction can be explicitly started with the statements "START
3253 TRANSACTION", "BEGIN [WORK]", "[COMMIT | ROLLBACK] AND CHAIN", etc.
3254
3255 Note: this doesn't tell you whether a transaction is active.
3256 A session can be in multi-statement transaction mode, and yet
3257 have no active transaction, e.g., in case of:
3258 set \@\@autocommit=0;
3259 set \@a= 3; <-- these statements don't
3260 set transaction isolation level serializable; <-- start an active
3261 flush tables; <-- transaction
3262
3263 I.e. for the above scenario this function returns true, even
3264 though no active transaction has begun.
3265 @sa in_active_multi_stmt_transaction()
3266 */
3268 return variables.option_bits & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN);
3269 }
3270 /**
3271 true if the session is in a multi-statement transaction mode
3272 (@sa in_multi_stmt_transaction_mode()) *and* there is an
3273 active transaction, i.e. there is an explicit start of a
3274 transaction with BEGIN statement, or implicit with a
3275 statement that uses a transactional engine.
3276
3277 For example, these scenarios don't start an active transaction
3278 (even though the server is in multi-statement transaction mode):
3279
3280 @verbatim
3281 set @@autocommit=0;
3282 select * from nontrans_table;
3283 set @var = true;
3284 flush tables;
3285 @endverbatim
3286
3287 Note, that even for a statement that starts a multi-statement
3288 transaction (i.e. select * from trans_table), this
3289 flag won't be set until we open the statement's tables
3290 and the engines register themselves for the transaction
3291 (see trans_register_ha()),
3292 hence this method is reliable to use only after
3293 open_tables() has completed.
3294
3295 Why do we need a flag?
3296 ----------------------
3297 We need to maintain a (at first glance redundant)
3298 session flag, rather than looking at thd->transaction.all.ha_list
3299 because of explicit start of a transaction with BEGIN.
3300
3301 I.e. in case of
3302 BEGIN;
3303 select * from nontrans_t1; <-- in_active_multi_stmt_transaction() is true
3304 */
3307 }
3309 return !stmt_arena->is_stmt_prepare();
3310 }
3311
3313 const char *from, size_t from_length,
3314 const CHARSET_INFO *from_cs, bool report_error = false);
3315
3317
3318 /**
3319 Clear the current error, if any.
3320 We do not clear is_fatal_error or is_fatal_sub_stmt_error since we
3321 assume this is never called if the fatal error is set.
3322 @todo: To silence an error, one should use Internal_error_handler
3323 mechanism. In future this function will be removed.
3324 */
3325 inline void clear_error() {
3326 DBUG_TRACE;
3328 is_slave_error = false;
3329 return;
3330 }
3331
3332 bool is_classic_protocol() const;
3333
3334 /** Return false if connection to client is broken. */
3335 bool is_connected(bool use_cached_connection_alive = false) final;
3336
3337 /** Return the cached protocol rw status. */
3339
3340 /**
3341 Mark the current error as fatal. Warning: this does not
3342 set any error, it sets a property of the error, so must be
3343 followed or prefixed with my_error().
3344 */
3346 bool is_fatal_error() const { return m_is_fatal_error; }
3347 /**
3348 true if there is an error in the error stack.
3349
3350 Please use this method instead of direct access to
3351 net.report_error.
3352
3353 If true, the current (sub)-statement should be aborted.
3354 The main difference between this member and is_fatal_error
3355 is that a fatal error can not be handled by a stored
3356 procedure continue handler, whereas a normal error can.
3357
3358 To raise this flag, use my_error().
3359 */
3360 inline bool is_error() const { return get_stmt_da()->is_error(); }
3361
3362 /// Returns first Diagnostics Area for the current statement.
3364
3365 /// Returns first Diagnostics Area for the current statement.
3366 const Diagnostics_area *get_stmt_da() const { return m_stmt_da; }
3367
3368 /// Returns the second Diagnostics Area for the current statement.
3370 return get_stmt_da()->stacked_da();
3371 }
3372
3373 /**
3374 Returns thread-local Diagnostics Area for parsing.
3375 We need to have a clean DA in case errors or warnings are thrown
3376 during parsing, but we can't just reset the main DA in case we
3377 have a diagnostic statement on our hand that needs the old DA
3378 to answer questions about the previous execution.
3379 Keeping a static per-thread DA for parsing is less costly than
3380 allocating a temporary one for each statement we parse.
3381 */
3383
3384 /**
3385 Returns thread-local Diagnostics Area to be used by query rewrite plugins.
3386 Query rewrite plugins use their own diagnostics area. The reason is that
3387 they are invoked right before and right after parsing, and we don't want
3388 conditions raised by plugins in either statement nor parser DA until we
3389 know which type of statement we have parsed.
3390
3391 @note The diagnostics area is instantiated the first time it is asked for.
3392 */
3395 }
3396
3397 /**
3398 Push the given Diagnostics Area on top of the stack, making
3399 it the new first Diagnostics Area. Conditions in the new second
3400 Diagnostics Area will be copied to the new first Diagnostics Area.
3401
3402 @param da Diagnostics Area to be come the top of
3403 the Diagnostics Area stack.
3404 @param copy_conditions
3405 Copy the conditions from the new second Diagnostics Area
3406 to the new first Diagnostics Area, as per SQL standard.
3407 */
3409 bool copy_conditions = true) {
3410 get_stmt_da()->push_diagnostics_area(this, da, copy_conditions);
3411 m_stmt_da = da;
3412 }
3413
3414 /// Pop the top DA off the Diagnostics Area stack.
3417 }
3418
3419 /**
3420 Inserts the new protocol at the top of the protocol stack, and make it
3421 the current protocol for this thd.
3422
3423 @param protocol Protocol to be inserted.
3424 */
3425 void push_protocol(Protocol *protocol);
3426
3427 template <typename ProtocolClass>
3428 void push_protocol(const std::unique_ptr<ProtocolClass> &protocol) {
3429 push_protocol(protocol.get());
3430 }
3431
3432 /**
3433 Pops the top protocol of the Protocol stack and sets the previous one
3434 as the current protocol.
3435 */
3436 void pop_protocol();
3437
3438 public:
3440 void update_charset();
3441
3442 /**
3443 Record a transient change to a pointer to an Item within another Item.
3444 */
3445 void change_item_tree(Item **place, Item *new_value) {
3446 /* TODO: check for OOM condition here */
3447 if (!stmt_arena->is_regular()) {
3448 DBUG_PRINT("info", ("change_item_tree place %p old_value %p new_value %p",
3449 place, *place, new_value));
3450 nocheck_register_item_tree_change(place, new_value);
3451 }
3452 *place = new_value;
3453 }
3454
3455 /**
3456 Remember that place was updated with new_value so it can be restored
3457 by rollback_item_tree_changes().
3458
3459 @param[in] place the location that will change, and whose old value
3460 we need to remember for restoration
3461 @param[in] new_value new value about to be inserted into *place
3462 */
3463 void nocheck_register_item_tree_change(Item **place, Item *new_value);
3464
3465 /**
3466 Restore locations set by calls to nocheck_register_item_tree_change().
3467 Note that this needs to happen before Item::cleanup is called.
3468 */
3470
3471 /*
3472 Cleanup statement parse state (parse tree, lex) and execution
3473 state after execution of a non-prepared SQL statement.
3474 */
3475 void end_statement();
3476 void send_kill_message() const;
3477
3479 uint add_state_flags);
3483
3484 public:
3485 /**
3486 Start a read-only attachable transaction.
3487 There must be no active attachable transactions (in other words, there can
3488 be only one active attachable transaction at a time).
3489 */
3491
3492 /**
3493 Start a read-write attachable transaction.
3494 All the read-only class' requirements apply.
3495 Additional requirements are documented along the class
3496 declaration.
3497 */
3499
3500 /**
3501 End an active attachable transaction. Applies to both the read-only
3502 and the read-write versions.
3503 Note, that the read-write attachable transaction won't be terminated
3504 inside this method.
3505 To invoke the function there must be active attachable transaction.
3506 */
3508
3509 /**
3510 @return true if there is an active attachable transaction.
3511 */
3513 return m_attachable_trx != nullptr && m_attachable_trx->is_read_only();
3514 }
3515
3516 /**
3517 @return true if there is an active attachable transaction.
3518 */
3520 return m_attachable_trx != nullptr;
3521 }
3522
3523 /**
3524 @return true if there is an active rw attachable transaction.
3525 */
3527 return m_attachable_trx != nullptr && !m_attachable_trx->is_read_only();
3528 }
3529
3530 public:
3531 /*
3532 @todo Make these methods private or remove them completely. Only
3533 decide_logging_format should call them. /Sven
3534 */
3536 DBUG_TRACE;
3537 /*
3538 This should only be called from decide_logging_format.
3539
3540 @todo Once we have ensured this, uncomment the following
3541 statement, remove the big comment below that, and remove the
3542 in_sub_stmt==0 condition from the following 'if'.
3543 */
3544 /* assert(in_sub_stmt == 0); */
3545 /*
3546 If in a stored/function trigger, the caller should already have done the
3547 change. We test in_sub_stmt to prevent introducing bugs where people
3548 wouldn't ensure that, and would switch to row-based mode in the middle
3549 of executing a stored function/trigger (which is too late, see also
3550 reset_current_stmt_binlog_format_row()); this condition will make their
3551 tests fail and so force them to propagate the
3552 lex->binlog_row_based_if_mixed upwards to the caller.
3553 */
3554 if ((variables.binlog_format == BINLOG_FORMAT_MIXED) && (in_sub_stmt == 0))
3556
3557 return;
3558 }
3560 DBUG_TRACE;
3562 return;
3563 }
3565 DBUG_TRACE;
3567 return;
3568 }
3570 DBUG_TRACE;
3571 DBUG_PRINT("debug", ("in_sub_stmt: %d, system_thread: %s", in_sub_stmt != 0,
3573 if (in_sub_stmt == 0) {
3574 if (variables.binlog_format == BINLOG_FORMAT_ROW)
3576 else
3578 }
3579 return;
3580 }
3581
3582 /**
3583 Copies variables.original_commit_timestamp to
3584 ((Slave_worker *)rli_slave)->original_commit_timestamp,
3585 if this is a slave thread.
3586 */
3588
3589 /// Return the value of @@gtid_next_list: either a Gtid_set or NULL.
3591 return variables.gtid_next_list.is_non_null
3592 ? variables.gtid_next_list.gtid_set
3593 : nullptr;
3594 }
3595
3596 /// Return the value of @@gtid_next_list: either a Gtid_set or NULL.
3598 return const_cast<THD *>(this)->get_gtid_next_list();
3599 }
3600
3601 /**
3602 Return true if the statement/transaction cache is currently empty,
3603 false otherwise.
3604
3605 @param is_transactional if true, check the transaction cache.
3606 If false, check the statement cache.
3607 */
3608 bool is_binlog_cache_empty(bool is_transactional) const;
3609
3610 /**
3611 The GTID of the currently owned transaction.
3612
3613 ==== Modes of ownership ====
3614
3615 The following modes of ownership are possible:
3616
3617 - owned_gtid.sidno==0: the thread does not own any transaction.
3618
3619 - owned_gtid.sidno==THD::OWNED_SIDNO_ANONYMOUS(==-2): the thread
3620 owns an anonymous transaction
3621
3622 - owned_gtid.sidno>0 and owned_gtid.gno>0: the thread owns a GTID
3623 transaction.
3624
3625 - (owned_gtid.sidno==THD::OWNED_SIDNO_GTID_SET(==-1): this is
3626 currently not used. It was reserved for the case where multiple
3627 GTIDs are owned (using gtid_next_list). This was one idea to
3628 make GTIDs work with NDB: due to the epoch concept, multiple
3629 transactions can be combined into one in NDB, and therefore a
3630 single transaction on a slave can have multiple GTIDs.)
3631
3632 ==== Life cycle of ownership ====
3633
3634 Generally, transaction ownership starts when the transaction is
3635 assigned its GTID and ends when the transaction commits or rolls
3636 back. On a master (GTID_NEXT=AUTOMATIC), the GTID is assigned
3637 just before binlog flush; on a slave (GTID_NEXT=UUID:NUMBER or
3638 GTID_NEXT=ANONYMOUS) it is assigned before starting the
3639 transaction.
3640
3641 A new client always starts with owned_gtid.sidno=0.
3642
3643 Ownership can be acquired in the following ways:
3644
3645 A1. If GTID_NEXT = 'AUTOMATIC' and GTID_MODE = OFF/OFF_PERMISSIVE:
3646 The thread acquires anonymous ownership in
3647 gtid_state->generate_automatic_gtid called from
3648 MYSQL_BIN_LOG::write_transaction.
3649
3650 A2. If GTID_NEXT = 'AUTOMATIC' and GTID_MODE = ON/ON_PERMISSIVE:
3651 The thread generates the GTID and acquires ownership in
3652 gtid_state->generate_automatic_gtid called from
3653 MYSQL_BIN_LOG::write_transaction.
3654
3655 A3. If GTID_NEXT = 'UUID:NUMBER': The thread acquires ownership in
3656 the following ways:
3657
3658 - In a client, the SET GTID_NEXT statement acquires ownership.
3659
3660 - The slave's analogy to a clients SET GTID_NEXT statement is
3661 Gtid_log_event::do_apply_event. So the slave acquires
3662 ownership in this function.
3663
3664 Note: if the GTID UUID:NUMBER is already included in
3665 GTID_EXECUTED, then the transaction must be skipped (the GTID
3666 auto-skip feature). Thus, ownership is *not* acquired in this
3667 case and owned_gtid.sidno==0.
3668
3669 A4. If GTID_NEXT = 'ANONYMOUS':
3670
3671 - In a client, the SET GTID_NEXT statement acquires ownership.
3672
3673 - In a slave thread, Gtid_log_event::do_apply_event acquires
3674 ownership.
3675
3676 - Contrary to the case of GTID_NEXT='UUID:NUMBER', it is
3677 allowed to execute two transactions in sequence without
3678 changing GTID_NEXT (cf. R1 and R2 below). Both transactions
3679 should be executed as anonymous transactions. But ownership
3680 is released when the first transaction commits. Therefore,
3681 when GTID_NEXT='ANONYMOUS', we also acquire anonymous
3682 ownership when starting to execute a statement, in
3683 gtid_reacquire_ownership_if_anonymous called from
3684 gtid_pre_statement_checks (usually called from
3685 mysql_execute_command).
3686
3687 A5. Slave applier threads start in a special mode, having
3688 GTID_NEXT='NOT_YET_DETERMINED'. This mode cannot be set in a
3689 regular client. When GTID_NEXT=NOT_YET_DETERMINED, the slave
3690 thread is postponing the decision of the value of GTID_NEXT
3691 until it has more information. There are three cases:
3692
3693 - If the first transaction of the relay log has a
3694 Gtid_log_event, then it will set GTID_NEXT=GTID:NUMBER and
3695 acquire GTID ownership in Gtid_log_event::do_apply_event.
3696
3697 - If the first transaction of the relay log has a
3698 Anonymous_gtid_log_event, then it will set
3699 GTID_NEXT=ANONYMOUS and acquire anonymous ownership in
3700 Gtid_log_event::do_apply_event.
3701
3702 - If the relay log was received from a pre-5.7.6 master with
3703 GTID_MODE=OFF (or a pre-5.6 master), then there are neither
3704 Gtid_log_events nor Anonymous_log_events in the relay log.
3705 In this case, the slave sets GTID_NEXT=ANONYMOUS and
3706 acquires anonymous ownership when executing a
3707 Query_log_event (Query_log_event::do_apply_event calls
3708 dispatch_sql_command which calls gtid_pre_statement_checks which
3709 calls gtid_reacquire_ownership_if_anonymous).
3710
3711 Ownership is released in the following ways:
3712
3713 R1. A thread that holds GTID ownership releases ownership at
3714 transaction commit or rollback. If GTID_NEXT=AUTOMATIC, all
3715 is fine. If GTID_NEXT=UUID:NUMBER, the UUID:NUMBER cannot be
3716 used for another transaction, since only one transaction can
3717 have any given GTID. To avoid the user mistake of forgetting
3718 to set back GTID_NEXT, on commit we set
3719 thd->variables.gtid_next.type=UNDEFINED_GTID. Then, any
3720 statement that user tries to execute other than SET GTID_NEXT
3721 will generate an error.
3722
3723 R2. A thread that holds anonymous ownership releases ownership at
3724 transaction commit or rollback. In this case there is no harm
3725 in leaving GTID_NEXT='ANONYMOUS', so
3726 thd->variables.gtid_next.type will remain ANONYMOUS_GTID and
3727 not UNDEFINED_GTID.
3728
3729 There are statements that generate multiple transactions in the
3730 binary log. This includes the following:
3731
3732 M1. DROP TABLE that is used with multiple tables, and the tables
3733 belong to more than one of the following groups: non-temporary
3734 table, temporary transactional table, temporary
3735 non-transactional table. DROP TABLE is split into one
3736 transaction for each of these groups of tables.
3737
3738 M2. DROP DATABASE that fails e.g. because rmdir fails. Then a
3739 single DROP TABLE is generated, which lists all tables that
3740 were dropped before the failure happened. But if the list of
3741 tables is big, and grows over a limit, the statement will be
3742 split into multiple statements.
3743
3744 M3. CREATE TABLE ... SELECT that is logged in row format. Then
3745 the server generates a single CREATE statement, followed by a
3746 BEGIN ... row events ... COMMIT transaction.
3747
3748 M4. A statement that updates both transactional and
3749 non-transactional tables in the same statement, and is logged
3750 in row format. Then it generates one transaction for the
3751 non-transactional row updates, followed by one transaction for
3752 the transactional row updates.
3753
3754 M5. CALL is executed as multiple transactions and logged as
3755 multiple transactions.
3756
3757 The general rules for multi-transaction statements are:
3758
3759 - If GTID_NEXT=AUTOMATIC and GTID_MODE=ON or ON_PERMISSIVE, one
3760 GTID should be generated for each transaction within the
3761 statement. Therefore, ownership must be released after each
3762 commit so that a new GTID can be generated by the next
3763 transaction. Typically mysql_bin_log.commit() is called to
3764 achieve this. (Note that some of these statements are currently
3765 disallowed when GTID_MODE=ON.)
3766
3767 - If GTID_NEXT=AUTOMATIC and GTID_MODE=OFF or OFF_PERMISSIVE, one
3768 Anonymous_gtid_log_event should be generated for each
3769 transaction within the statement. Similar to the case above, we
3770 call mysql_bin_log.commit() and release ownership between
3771 transactions within the statement.
3772
3773 This works for all the special cases M1-M5 except M4. When a
3774 statement writes both non-transactional and transactional
3775 updates to the binary log, both the transaction cache and the
3776 statement cache are flushed within the same call to
3777 flush_thread_caches(THD) from within the binary log group commit
3778 code. At that point we cannot use mysql_bin_log.commit().
3779 Instead we release ownership using direct calls to
3780 gtid_state->release_anonymous_ownership() and
3781 thd->clear_owned_gtids() from binlog_cache_mngr::flush.
3782
3783 - If GTID_NEXT=ANONYMOUS, anonymous ownership must be *preserved*
3784 between transactions within the statement, to prevent that a
3785 concurrent SET GTID_MODE=ON makes it impossible to log the
3786 statement. To avoid that ownership is released if
3787 mysql_bin_log.commit() is called, we set
3788 thd->is_commit_in_middle_of_statement before calling
3789 mysql_bin_log.commit. Note that we must set this flag only if
3790 GTID_NEXT=ANONYMOUS, not if the transaction is anonymous when
3791 GTID_NEXT=AUTOMATIC and GTID_MODE=OFF.
3792
3793 This works for all the special cases M1-M5 except M4. When a
3794 statement writes non-transactional updates in the middle of a
3795 transaction, but keeps some transactional updates in the
3796 transaction cache, then it is not easy to know at the time of
3797 calling mysql_bin_log.commit() whether anonymous ownership needs
3798 to be preserved or not. Instead, we directly check if the
3799 transaction cache is nonempty before releasing anonymous
3800 ownership inside Gtid_state::update_gtids_impl.
3801
3802 - If GTID_NEXT='UUID:NUMBER', it is impossible to log a
3803 multi-transaction statement, since each GTID can only be used by
3804 one transaction. Therefore, an error must be generated in this
3805 case. Errors are generated in different ways for the different
3806 statement types:
3807
3808 - DROP TABLE: we can detect the situation before it happens,
3809 since the table type is known once the tables are opened. So
3810 we generate an error before even executing the statement.
3811
3812 - DROP DATABASE: we can't detect the situation until it is too
3813 late; the tables have already been dropped and we cannot log
3814 anything meaningful. So we don't log at all.
3815
3816 - CREATE TABLE ... SELECT: this is not allowed when
3817 enforce_gtid_consistency is ON; the statement will be
3818 forbidden in is_ddl_gtid_compatible.
3819
3820 - Statements that update both transactional and
3821 non-transactional tables are disallowed when GTID_MODE=ON, so
3822 this normally does not happen. However, it can happen if the
3823 slave uses a different engine type than the master, so that a
3824 statement that updates InnoDB+InnoDB on master updates
3825 InnoDB+MyISAM on slave. In this case the statement will be
3826 forbidden in is_dml_gtid_compatible and will not be allowed to
3827 execute.
3828
3829 - CALL: the second statement will generate an error because
3830 GTID_NEXT is 'undefined'. Note that this situation can only
3831 happen if user does it on purpose: A CALL on master is logged
3832 as multiple statements, so a slave never executes CALL with
3833 GTID_NEXT='UUID:NUMBER'.
3834
3835 Finally, ownership release is suppressed in one more corner case:
3836
3837 C1. Administration statements including OPTIMIZE TABLE, REPAIR
3838 TABLE, or ANALYZE TABLE are written to the binary log even if
3839 they fail. This means that the thread first calls
3840 trans_rollack, and then writes the statement to the binlog.
3841 Rollback normally releases ownership. But ownership must be
3842 kept until writing the binlog. The solution is that these
3843 statements set thd->skip_gtid_rollback=true before calling
3844 trans_rollback, and Gtid_state::update_on_rollback does not
3845 release ownership if the flag is set.
3846
3847 @todo It would probably be better to encapsulate this more, maybe
3848 use Gtid_specification instead of Gtid.
3849 */
3851 static const int OWNED_SIDNO_GTID_SET = -1;
3852 static const int OWNED_SIDNO_ANONYMOUS = -2;
3853
3854 /**
3855 For convenience, this contains the TSID component of the GTID
3856 stored in owned_gtid.
3857 */
3859
3860 /** SE GTID persistence flag types. */
3861 enum Se_GTID_flag : size_t {
3862 /** Pin owned GTID */
3864 /** Cleanup GTID during unpin. */
3866 /** SE would persist GTID for current transaction. */
3868 /** If RESET log in progress. */
3870 /** Explicit request for SE to persist GTID for current transaction. */
3872 /** GTID table persistence was requested for current ownership. */
3874 /** Max element holding the biset size. */
3877
3878 using Se_GTID_flagset = std::bitset<SE_GTID_MAX>;
3879
3880 /** Flags for SE GTID persistence. */
3882
3883 /** Defer freeing owned GTID and TSID till unpinned. */
3885
3886 /** Unpin and free GTID and TSID. */
3887 void unpin_gtid() {
3889 /* Do any deferred cleanup */
3893 }
3894 }
3895
3896 /** @return true, if single phase XA commit operation. */
3897 bool is_one_phase_commit();
3898
3899 /** Set when binlog reset operation is started. */
3901
3902 /** Cleared after flushing SE logs during binlog reset. */
3904
3905 /** @return true, if binlog reset operation. */
3907
3908 /** Set by SE when it guarantees GTID persistence. */
3910
3911 /** Request SE to persist GTID explicitly. */
3915 }
3916
3917 /** Reset by SE at transaction end after persisting GTID. */
3921 }
3922
3923 /** @return true, if SE persists GTID for current transaction. */
3924 bool se_persists_gtid() const {
3925 DBUG_EXECUTE_IF("disable_se_persists_gtid", return (false););
3926 auto trx = get_transaction();
3927 auto xid_state = trx->xid_state();
3928 /* XA transactions are always persisted by Innodb. */
3929 return (!xid_state->has_state(XID_STATE::XA_NOTR) ||
3931 }
3932
3933 /** @return true, if SE is explicitly set to persists GTID. */
3935 DBUG_EXECUTE_IF("disable_se_persists_gtid", return (false););
3937 }
3938
3939 /** @return true, if external XA transaction is in progress. */
3940 bool is_extrenal_xa() const {
3941 auto trx = get_transaction();
3942 auto xid_state = trx->xid_state();
3943 return !xid_state->has_state(XID_STATE::XA_NOTR);
3944 }
3945
3946 /// Mark GTID table persistence as requested for the currently owned GTID.
3947 ///
3948 /// This follows GTID ownership lifetime, not the shorter internal
3949 /// storage-engine transaction used while accessing mysql.gtid_executed.
3952 }
3953
3954 /// @return true if GTID table persistence was already requested for the
3955 /// currently owned GTID.
3958 }
3959
3960#ifdef HAVE_GTID_NEXT_LIST
3961 /**
3962 If this thread owns a set of GTIDs (i.e., GTID_NEXT_LIST != NULL),
3963 then this member variable contains the subset of those GTIDs that
3964 are owned by this thread.
3965 */
3966 Gtid_set owned_gtid_set;
3967#endif
3968
3969 /*
3970 Replication related context.
3971
3972 @todo: move more parts of replication related fields in THD to inside this
3973 class.
3974 */
3976
3978 /* Defer GTID cleanup if pinned. Used for XA transactions where
3979 SE(Innodb) needs to read GTID. */
3982 return;
3983 }
3985#ifdef HAVE_GTID_NEXT_LIST
3986 owned_gtid_set.clear();
3987#else
3988 assert(0);
3989#endif
3990 }
3991 owned_gtid.clear();
3992 owned_tsid.clear();
3994 owned_gtid.dbug_print(nullptr, "set owned_gtid in clear_owned_gtids");
3995 }
3996
3997 /** @return true, if owned GTID is empty or waiting for deferred cleanup. */
4000 return (true);
4001 }
4002 return (owned_gtid.is_empty());
4003 }
4004
4005 /*
4006 There are some statements (like OPTIMIZE TABLE, ANALYZE TABLE and
4007 REPAIR TABLE) that might call trans_rollback_stmt() and also will be
4008 successfully executed and will have to go to the binary log.
4009 For these statements, the skip_gtid_rollback flag must be set to avoid
4010 problems when the statement is executed with a GTID_NEXT set to
4011 ASSIGNED_GTID (like the SQL thread do when applying events from other
4012 server). When this flag is set, a call to gtid_rollback() will do nothing.
4013 */
4015
4016 private:
4017 /// Callback functions that determine if GTID rollback shall be skipped.
4018 std::list<std::function<bool(const THD &)>> m_skip_gtid_rollback_checkers;
4019
4020 /// Actions to execute before owned GTID state is externalized.
4022
4023 public:
4024 /// Invoke the callback functions that determine if GTID rollback shall be
4025 /// skipped, and return true as soon as one of them returns true; otherwise
4026 /// return false.
4028 for (const auto &func : m_skip_gtid_rollback_checkers)
4029 if (func(*this)) return true;
4030 return false;
4031 }
4032
4033 /// Register a callback function that will determine if a subsequent GTID
4034 /// rollback shall be skipped. Returns a (moveable, but not copyable) object
4035 /// whose destructor will will unregister the callback.
4037 const std::invocable<const THD &> auto &shall_skip) {
4038 m_skip_gtid_rollback_checkers.emplace_back(shall_skip);
4039 auto it = std::prev(m_skip_gtid_rollback_checkers.end());
4040 return Scope_guard{
4041 [this, it] { this->m_skip_gtid_rollback_checkers.erase(it); }};
4042 }
4043
4044 /// Register an action that will run before this THD externalizes its owned
4045 /// GTID state.
4046 ///
4047 /// @param f Action to execute. The action argument is true when GTID state
4048 /// is committed and false when GTID state is rolled back.
4049 void register_action_before_gtid_state_update(std::function<void(bool)> f) {
4050 m_actions_before_gtid_state_update.push_back(std::move(f));
4051 }
4052
4053 /// Execute and remove registered before-GTID-state-update actions.
4054 ///
4055 /// @param is_commit Whether GTID state is committed.
4057 for (auto &action : m_actions_before_gtid_state_update) action(is_commit);
4059 }
4060
4061 /*
4062 There are some statements (like DROP DATABASE that fails on rmdir
4063 and gets rewritten to multiple DROP TABLE statements) that may
4064 call trans_commit_stmt() before it has written all statements to
4065 the binlog. When using GTID_NEXT = ANONYMOUS, such statements
4066 should not release ownership of the anonymous transaction until
4067 all statements have been written to the binlog. To prevent that
4068 update_gtid_impl releases ownership, such statements must set this
4069 flag.
4070 */
4072
4073 /*
4074 True while the transaction is executing, if one of
4075 is_ddl_gtid_consistent or is_dml_gtid_consistent returned false.
4076 */
4078
4079 const LEX_CSTRING &db() const { return m_db; }
4080
4081 /**
4082 Set the current database; use deep copy of C-string.
4083
4084 @param new_db the new database name.
4085
4086 Initialize the current database from a NULL-terminated string with
4087 length. If we run out of memory, we free the current database and
4088 return true. This way the user will notice the error as there will be
4089 no current database selected (in addition to the error message set by
4090 malloc).
4091
4092 @note This operation just sets {db, db_length}. Switching the current
4093 database usually involves other actions, like switching other database
4094 attributes including security context. In the future, this operation
4095 will be made private and more convenient interface will be provided.
4096
4097 @return Operation status
4098 @retval false Success
4099 @retval true Out-of-memory error
4100 */
4101 bool set_db(const LEX_CSTRING &new_db);
4102
4103 /**
4104 Set the current database; use shallow copy of C-string.
4105
4106 @param new_db the new database name.
4107
4108 @note This operation just sets {db, db_length}. Switching the current
4109 database usually involves other actions, like switching other database
4110 attributes including security context. In the future, this operation
4111 will be made private and more convenient interface will be provided.
4112 */
4113 void reset_db(const LEX_CSTRING &new_db) {
4114 m_db.str = new_db.str;
4115 m_db.length = new_db.length;
4116#ifdef HAVE_PSI_THREAD_INTERFACE
4117 PSI_THREAD_CALL(set_thread_db)(new_db.str, static_cast<int>(new_db.length));
4118#endif
4119 }
4120 /*
4121 Copy the current database to the argument. Use the current arena to
4122 allocate memory for a deep copy: current database may be freed after
4123 a statement is parsed but before it's executed.
4124 */
4125 bool copy_db_to(char const **p_db, size_t *p_db_length) const {
4126 if (m_db.str == nullptr) {
4127 my_error(ER_NO_DB_ERROR, MYF(0));
4128 return true;
4129 }
4130 *p_db = strmake(m_db.str, m_db.length);
4131 *p_db_length = m_db.length;
4132 return false;
4133 }
4134
4135 bool copy_db_to(char **p_db, size_t *p_db_length) const {
4136 return copy_db_to(const_cast<char const **>(p_db), p_db_length);
4137 }
4138
4140
4141 /**
4142 Get resource group context.
4143
4144 @returns pointer to resource group context.
4145 */
4146
4148 return &m_resource_group_ctx;
4149 }
4150
4151 public:
4152 /**
4153 Save the performance schema thread instrumentation
4154 associated with this user session.
4155 @param psi Performance schema thread instrumentation
4156 */
4157 void set_psi(PSI_thread *psi) { m_psi = psi; }
4158
4159 /**
4160 Read the performance schema thread instrumentation
4161 associated with this user session.
4162 This method is safe to use from a different thread.
4163 */
4164 PSI_thread *get_psi() const { return m_psi; }
4165
4166 private:
4167 /**
4168 Performance schema thread instrumentation for this session.
4169 This member is maintained using atomic operations,
4170 do not access it directly.
4171 @sa set_psi
4172 @sa get_psi
4173 */
4174 std::atomic<PSI_thread *> m_psi;
4175
4176 public:
4178 return m_internal_handler;
4179 }
4180
4181 /**
4182 Add an internal error handler to the thread execution context.
4183 @param handler the exception handler to add
4184 */
4186
4187 private:
4188 /**
4189 Handle a sql condition.
4190 @param sql_errno the condition error number
4191 @param sqlstate the condition sqlstate
4192 @param level the condition level
4193 @param msg the condition message text
4194 @return true if the condition is handled
4195 */
4196 bool handle_condition(uint sql_errno, const char *sqlstate,
4198 const char *msg);
4199
4200 public:
4201 /**
4202 Remove the error handler last pushed.
4203 */
4205
4206 Opt_trace_context opt_trace; ///< optimizer trace of current statement
4207 /**
4208 Raise an exception condition.
4209 @param code the MYSQL_ERRNO error code of the error
4210 */
4211 void raise_error(uint code);
4212
4213 /**
4214 Raise an exception condition, with a formatted message.
4215 @param code the MYSQL_ERRNO error code of the error
4216 */
4217 void raise_error_printf(uint code, ...);
4218
4219 /**
4220 Raise a completion condition (warning).
4221 @param code the MYSQL_ERRNO error code of the warning
4222 */
4223 void raise_warning(uint code);
4224
4225 /**
4226 Raise a completion condition (warning), with a formatted message.
4227 @param code the MYSQL_ERRNO error code of the warning
4228 */
4229 void raise_warning_printf(uint code, ...);
4230
4231 /**
4232 Raise a completion condition (note), with a fixed message.
4233 @param code the MYSQL_ERRNO error code of the note
4234 */
4235 void raise_note(uint code);
4236
4237 /**
4238 Raise an completion condition (note), with a formatted message.
4239 @param code the MYSQL_ERRNO error code of the note
4240 */
4241 void raise_note_printf(uint code, ...);
4242
4243 private:
4244 /*
4245 Only the implementation of the SIGNAL and RESIGNAL statements
4246 is permitted to raise SQL conditions in a generic way,
4247 or to raise them by bypassing handlers (RESIGNAL).
4248 To raise a SQL condition, the code should use the public
4249 raise_error() or raise_warning() methods provided by class THD.
4250 */
4252 friend class Sql_cmd_signal;
4253 friend class Sql_cmd_resignal;
4254 friend void push_warning(THD *thd,
4256 uint code, const char *message_text);
4257 friend void my_message_sql(uint, const char *, myf);
4258
4259 /**
4260 Raise a generic SQL condition. Also calls
4261 mysql_event_tracking_general_notify() unless the condition is handled by a
4262 SQL condition handler.
4263
4264 @param sql_errno the condition error number
4265 @param sqlstate the condition SQLSTATE
4266 @param level the condition level
4267 @param msg the condition message text
4268 @param fatal_error should the fatal_error flag be set?
4269 @return The condition raised, or NULL
4270 */
4271 Sql_condition *raise_condition(uint sql_errno, const char *sqlstate,
4273 const char *msg, bool fatal_error = false);
4274
4275 public:
4276 void set_command(enum enum_server_command command);
4277
4278 inline enum enum_server_command get_command() const { return m_command; }
4279
4280 /**
4281 For safe and protected access to the query string, the following
4282 rules should be followed:
4283 1: Only the owner (current_thd) can set the query string.
4284 This will be protected by LOCK_thd_query.
4285 2: The owner (current_thd) can read the query string without
4286 locking LOCK_thd_query.
4287 3: Other threads must lock LOCK_thd_query before reading
4288 the query string.
4289
4290 This means that write-write conflicts are avoided by LOCK_thd_query.
4291 Read(by owner or other thread)-write(other thread) are disallowed.
4292 Read(other thread)-write(by owner) conflicts are avoided by LOCK_thd_query.
4293 Read(by owner)-write(by owner) won't happen as THD=thread.
4294
4295 We want to keep current_thd out of header files, so the debug assert,
4296 is moved to the .cc file. In optimized mode, we want this getter to
4297 be fast, so we inline it.
4298 */
4299 void debug_assert_query_locked() const;
4300 const LEX_CSTRING &query() const {
4301#ifndef NDEBUG
4303#endif
4304 return m_query_string;
4305 }
4306
4307 /**
4308 The current query in normalized form. The format is intended to be
4309 identical to the digest text of performance_schema, but not limited in
4310 size. In this case the parse tree is traversed as opposed to a (limited)
4311 token buffer. The string is allocated by this Statement and will be
4312 available until the next call to this function or this object is deleted.
4313
4314 @note We have no protection against out-of-memory errors as this function
4315 relies on the Item::print() interface which does not propagate errors.
4316
4317 @return The current query in normalized form.
4318 */
4319 const String normalized_query();
4320
4321 /**
4322 Set query to be displayed in performance schema (threads table etc.). Also
4323 mark the query safe to display for information_schema.process_list.
4324 */
4325 void set_query_for_display(const char *query_arg [[maybe_unused]],
4326 size_t query_length_arg [[maybe_unused]]) {
4327 // Set in pfs events statements table
4329 static_cast<uint>(query_length_arg));
4330#ifdef HAVE_PSI_THREAD_INTERFACE
4331 // Set in pfs threads table
4332 PSI_THREAD_CALL(set_thread_info)
4333 (query_arg, static_cast<uint>(query_length_arg));
4334#endif
4335 set_safe_display(true);
4336 }
4337
4338 /**
4339 Reset query string to be displayed in PFS. Also reset the safety flag
4340 for information_schema.process_list for next query.
4341 */
4343 set_query_for_display(nullptr, 0);
4344 m_safe_to_display.store(false);
4345 }
4346
4347 /** @return true, if safe to display the query string. */
4348 bool safe_to_display() const { return m_safe_to_display.load(); }
4349
4350 /** Set if the query string to be safe to display.
4351 @param[in] safe if it is safe to display query string */
4352 void set_safe_display(bool safe) { m_safe_to_display.store(safe); }
4353
4354 /**
4355 Assign a new value to thd->m_query_string.
4356 Protected with the LOCK_thd_query mutex.
4357 */
4358 void set_query(const char *query_arg, size_t query_length_arg) {
4359 const LEX_CSTRING tmp = {query_arg, query_length_arg};
4360 set_query(tmp);
4361 }
4362 void set_query(LEX_CSTRING query_arg);
4364
4365 /**
4366 Set the rewritten query (with passwords obfuscated etc.) on the THD.
4367 Wraps this in the LOCK_thd_query mutex to protect against race conditions
4368 with SHOW PROCESSLIST inspecting that string.
4369
4370 This uses swap() and therefore "steals" the argument from the caller;
4371 the caller MUST take care not to try to use its own string after calling
4372 this function! This is an optimization for mysql_rewrite_query() so we
4373 don't copy its temporary string (which may get very long, up to
4374 @@max_allowed_packet).
4375
4376 Using this outside of mysql_rewrite_query() is almost certainly wrong;
4377 please check with the runtime team!
4378
4379 @param query_arg The rewritten query to use for slow/bin/general logging.
4380 The value will be released in the caller and MUST NOT
4381 be used there after calling this function.
4382 */
4383 void swap_rewritten_query(String &query_arg);
4384
4385 /**
4386 Get the rewritten query (with passwords obfuscated etc.) from the THD.
4387 If done from a different thread (from the one that the rewritten_query
4388 is set on), the caller must hold LOCK_thd_query while calling this!
4389 */
4390 const String &rewritten_query() const {
4391#ifndef NDEBUG
4393#endif
4394 return m_rewritten_query;
4395 }
4396
4397 /**
4398 Reset thd->m_rewritten_query. Protected with the LOCK_thd_query mutex.
4399 */
4401 if (rewritten_query().length()) {
4402 String empty;
4404 }
4405 }
4406
4407 /**
4408 Assign a new value to thd->query_id.
4409 Protected with the LOCK_thd_data mutex.
4410 */
4411 void set_query_id(query_id_t new_query_id) {
4413 query_id = new_query_id;
4416 }
4417
4418 /**
4419 Assign a new value to open_tables.
4420 Protected with the LOCK_thd_data mutex.
4421 */
4422 void set_open_tables(TABLE *open_tables_arg) {
4424 open_tables = open_tables_arg;
4426 }
4427
4428 /**
4429 Assign a new value to is_killable
4430 Protected with the LOCK_thd_data mutex.
4431 */
4432 void set_is_killable(bool is_killable_arg) {
4434 is_killable = is_killable_arg;
4436 }
4437
4439 assert(locked_tables_mode == LTM_NONE);
4440
4441 if (mode_arg == LTM_LOCK_TABLES) {
4442 /*
4443 When entering LOCK TABLES mode we should set explicit duration
4444 for all metadata locks acquired so far in order to avoid releasing
4445 them till UNLOCK TABLES statement.
4446 We don't do this when entering prelocked mode since sub-statements
4447 don't release metadata locks and restoring status-quo after leaving
4448 prelocking mode gets complicated.
4449 */
4451 }
4452
4453 locked_tables_mode = mode_arg;
4454 }
4456 int decide_logging_format(Table_ref *tables);
4457 /**
4458 is_dml_gtid_compatible() and is_ddl_gtid_compatible() check if the
4459 statement that is about to be processed will safely get a
4460 GTID. Currently, the following cases may lead to errors
4461 (e.g. duplicated GTIDs) and as such are forbidden:
4462
4463 1. DML statements that mix non-transactional updates with
4464 transactional updates.
4465
4466 2. Transactions that use non-transactional tables after
4467 having used transactional tables.
4468
4469 3. CREATE...SELECT statement;
4470
4471 4. CREATE TEMPORARY TABLE or DROP TEMPORARY TABLE within a
4472 transaction
4473
4474 The first two conditions have to be checked in
4475 decide_logging_format, because that's where we know if the table
4476 is transactional or not. These are implemented in
4477 is_dml_gtid_compatible().
4478
4479 The third and fourth conditions have to be checked in
4480 mysql_execute_command because (1) that prevents implicit commit
4481 from being executed if the statement fails; (2) DROP TEMPORARY
4482 TABLE does not invoke decide_logging_format. These are
4483 implemented in is_ddl_gtid_compatible().
4484
4485 In the cases where GTID violations generate errors,
4486 is_ddl_gtid_compatible() needs to be called before the implicit
4487 pre-commit, so that there is no implicit commit if the statement
4488 fails.
4489
4490 In the cases where GTID violations do not generate errors,
4491 is_ddl_gtid_compatible() needs to be called after the implicit
4492 pre-commit, because in these cases the function will increase the
4493 global counter automatic_gtid_violating_transaction_count or
4494 anonymous_gtid_violating_transaction_count. If there is an
4495 ongoing transaction, the implicit commit will commit the
4496 transaction, which will call update_gtids_impl, which should
4497 decrease the counters depending on whether the *old* was violating
4498 GTID-consistency or not. Thus, we should increase the counters
4499 only after the old transaction is committed.
4500
4501 @param some_transactional_table true if the statement updates some
4502 transactional table; false otherwise.
4503
4504 @param some_non_transactional_table true if the statement updates
4505 some non-transactional table; false otherwise.
4506
4507 @param non_transactional_tables_are_tmp true if all updated
4508 non-transactional tables are temporary.
4509
4510 @retval true if the statement is compatible;
4511 @retval false if the statement is not compatible.
4512 */
4513 bool is_dml_gtid_compatible(bool some_transactional_table,
4514 bool some_non_transactional_table,
4515 bool non_transactional_tables_are_tmp);
4518 bool need_binlog_invoker() const { return m_binlog_invoker; }
4519 void get_definer(LEX_USER *definer);
4521 m_invoker_user.str = user->str;
4522 m_invoker_user.length = user->length;
4523 m_invoker_host.str = host->str;
4524 m_invoker_host.length = host->length;
4525 }
4528 bool has_invoker() const { return m_invoker_user.str != nullptr; }
4529
4531
4532 private:
4533 /** The current internal error handler for this thread, or NULL. */
4535
4536 /**
4537 This memory root is used for two purposes:
4538 - for conventional queries, to allocate structures stored in main_lex
4539 during parsing, and allocate runtime data (execution plan, etc.)
4540 during execution.
4541 - for prepared queries, only to allocate runtime data. The parsed
4542 tree itself is reused between executions and thus is stored elsewhere.
4543 */
4546 Diagnostics_area m_parser_da; /**< cf. get_parser_da() */
4549
4551
4552 /**
4553 It will be set TRUE if CURRENT_USER() is called in account management
4554 statements or default definer is set in CREATE/ALTER SP, SF, Event,
4555 TRIGGER or VIEW statements.
4556
4557 Current user will be binlogged into Query_log_event if current_user_used
4558 is true; It will be stored into m_invoker_host and m_invoker_user by SQL
4559 thread.
4560 */
4562
4563 /**
4564 It points to the invoker in the Query_log_event.
4565 SQL thread use it as the default definer in CREATE/ALTER SP, SF, Event,
4566 TRIGGER or VIEW statements or current user in account management
4567 statements if it is not NULL.
4568 */
4571
4572 friend class Protocol_classic;
4573
4574 private:
4575 /**
4576 Optimizer cost model for server operations.
4577 */
4580
4581 public:
4582 /**
4583 Initialize the optimizer cost model.
4584
4585 This function should be called each time a new query is started.
4586 */
4587 void init_cost_model();
4588
4589 /**
4590 Retrieve the optimizer cost model for this connection.
4591 */
4592 const Cost_model_server *cost_model() const;
4593
4596
4597 void syntax_error() { syntax_error(ER_SYNTAX_ERROR); }
4598 void syntax_error(const char *format, ...)
4599 MY_ATTRIBUTE((format(printf, 2, 3)));
4600 void syntax_error(int mysql_errno, ...);
4601
4602 void syntax_error_at(const POS &location) {
4603 syntax_error_at(location, ER_SYNTAX_ERROR);
4604 }
4605 void syntax_error_at(const POS &location, const char *format, ...)
4606 MY_ATTRIBUTE((format(printf, 3, 4)));
4607 void syntax_error_at(const POS &location, int mysql_errno, ...);
4608
4609 void vsyntax_error_at(const POS &location, const char *format, va_list args)
4610 MY_ATTRIBUTE((format(printf, 3, 0)));
4611 void vsyntax_error_at(const char *pos_in_lexer_raw_buffer, const char *format,
4612 va_list args) MY_ATTRIBUTE((format(printf, 3, 0)));
4613
4614 /**
4615 Send name and type of result to client.
4616
4617 Sum fields has table name empty and field_name.
4618
4619 @param list List of items to send to client
4620 @param flags Bit mask with the following functions:
4621 - 1 send number of rows
4622 - 2 send default values
4623 - 4 don't write eof packet
4624
4625 @retval
4626 false ok
4627 @retval
4628 true Error (Note that in this case the error is not sent to the client)
4629 */
4630
4631 bool send_result_metadata(const mem_root_deque<Item *> &list, uint flags);
4632
4633 /**
4634 Send one result set row.
4635
4636 @param row_items a collection of column values for that row
4637
4638 @return Error status.
4639 @retval true Error.
4640 @retval false Success.
4641 */
4642
4643 bool send_result_set_row(const mem_root_deque<Item *> &row_items);
4644
4645 /*
4646 Send the status of the current statement execution over network.
4647
4648 In MySQL, there are two types of SQL statements: those that return
4649 a result set and those that return status information only.
4650
4651 If a statement returns a result set, it consists of 3 parts:
4652 - result set meta-data
4653 - variable number of result set rows (can be 0)
4654 - followed and terminated by EOF or ERROR packet
4655
4656 Once the client has seen the meta-data information, it always
4657 expects an EOF or ERROR to terminate the result set. If ERROR is
4658 received, the result set rows are normally discarded (this is up
4659 to the client implementation, libmysql at least does discard them).
4660 EOF, on the contrary, means "successfully evaluated the entire
4661 result set". Since we don't know how many rows belong to a result
4662 set until it's evaluated, EOF/ERROR is the indicator of the end
4663 of the row stream. Note, that we can not buffer result set rows
4664 on the server -- there may be an arbitrary number of rows. But
4665 we do buffer the last packet (EOF/ERROR) in the Diagnostics_area and
4666 delay sending it till the very end of execution (here), to be able to
4667 change EOF to an ERROR if commit failed or some other error occurred
4668 during the last cleanup steps taken after execution.
4669
4670 A statement that does not return a result set doesn't send result
4671 set meta-data either. Instead it returns one of:
4672 - OK packet
4673 - ERROR packet.
4674 Similarly to the EOF/ERROR of the previous statement type, OK/ERROR
4675 packet is "buffered" in the Diagnostics Area and sent to the client
4676 in the end of statement.
4677
4678 @note This method defines a template, but delegates actual
4679 sending of data to virtual Protocol::send_{ok,eof,error}. This
4680 allows for implementation of protocols that "intercept" ok/eof/error
4681 messages, and store them in memory, etc, instead of sending to
4682 the client.
4683
4684 @pre The Diagnostics Area is assigned or disabled. It can not be empty
4685 -- we assume that every SQL statement or COM_* command
4686 generates OK, ERROR, or EOF status.
4687
4688 @post The status information is encoded to protocol format and sent to the
4689 client.
4690
4691 @return We conventionally return void, since the only type of error
4692 that can happen here is a NET (transport) error, and that one
4693 will become visible when we attempt to read from the NET the
4694 next command.
4695 Diagnostics_area::is_sent is set for debugging purposes only.
4696 */
4697
4698 void send_statement_status();
4699
4700 /**
4701 This is only used by master dump threads.
4702 When the master receives a new connection from a slave with a
4703 UUID (for slave versions >= 5.6)/server_id(for slave versions < 5.6)
4704 that is already connected, it will set this flag true
4705 before killing the old slave connection.
4706 */
4708
4709 /**
4710 Claim all the memory used by the THD object.
4711 This method is to keep memory instrumentation statistics
4712 updated, when an object is transferred across threads.
4713 */
4714 void claim_memory_ownership(bool claim);
4715
4718
4719 /**
4720 Returns the plugin, the thd belongs to.
4721 @return pointer to the plugin id
4722 */
4723 const st_plugin_int *get_plugin() const { return m_plugin; }
4724 /**
4725 Sets the plugin id to the value provided as parameter
4726 @param plugin the id of the plugin the thd belongs to
4727 */
4728 void set_plugin(const st_plugin_int *plugin) { m_plugin = plugin; }
4729#ifndef NDEBUG
4731 void set_tmp_table_seq_id(uint arg) { tmp_table_seq_id = arg; }
4732#endif
4733
4736
4737 private:
4738 /**
4739 Variable to mark if the object is part of a Srv_session object, which
4740 aggregates THD.
4741 */
4743
4744 /// Stores the plugin id it is attached to (if any).
4745 const st_plugin_int *m_plugin{nullptr};
4746
4747 /**
4748 Creating or dropping plugin native table through a plugin service.
4749 This variable enables the DDL command execution from
4750 dd::create_native_table() to be executed without committing the
4751 transaction.
4752 */
4754
4755#ifndef NDEBUG
4756 /**
4757 Sequential number of internal tmp table created in the statement. Useful for
4758 tracking tmp tables when number of them is involved in a query.
4759 */
4761
4762 public:
4763 /*
4764 The member serves to guard against duplicate use of the same xid
4765 at binary logging.
4766 */
4768#endif
4769 private:
4770 /*
4771 Flag set by my_write before waiting for disk space.
4772
4773 This is used by replication to decide if the I/O thread should be
4774 killed or not when stopping the replication threads.
4775
4776 In ordinary STOP REPLICA case, the I/O thread will wait for disk space
4777 or to be killed regardless of this flag value.
4778
4779 In server shutdown case, if this flag is true, the I/O thread will be
4780 signaled with KILL_CONNECTION to abort the waiting, letting the server
4781 to shutdown promptly.
4782 */
4784
4785 public:
4786 /**
4787 Set the waiting_for_disk_space flag.
4788
4789 @param waiting The value to set in the flag.
4790 */
4791 void set_waiting_for_disk_space(bool waiting) {
4792 waiting_for_disk_space = waiting;
4793 }
4794 /**
4795 Returns the current waiting_for_disk_space flag value.
4796 */
4798
4799 bool sql_parser();
4800
4801 /// Enables or disables use of secondary storage engines in this session.
4804 }
4805 /// cleanup all secondary engine relevant members after statement execution.
4807
4808 /**
4809 Can secondary storage engines be used for query execution in
4810 this session?
4811 */
4814 }
4815
4816 /**
4817 Checks if queries in this session can use a secondary storage engine for
4818 execution.
4819
4820 @return true if secondary storage engines can be used in this
4821 session, or false otherwise
4822 */
4824
4825 /// Indicate whether secondary storage engine is forced for this execution
4828 }
4829
4831
4832 private:
4833 /**
4834 This flag tells if a secondary storage engine can be used to
4835 execute a query in this session.
4836 */
4839
4840 /**
4841 Flag that tells whether secondary storage engine is forced for execution.
4842 Notice that use_secondary_engine is not reliable because it may be restored
4843 early.
4844 */
4846
4848
4849 /**
4850 Flag that indicates if the user of current session has SYSTEM_USER privilege
4851 */
4852 std::atomic<bool> m_is_system_user;
4853 /**
4854 Flag that indicates if the user of current session has CONNECTION_ADMIN
4855 privilege
4856 */
4857 std::atomic<bool> m_is_connection_admin;
4858
4859 public:
4860 bool is_system_user();
4861 void set_system_user(bool system_user_flag);
4862
4863 bool is_connection_admin();
4864 void set_connection_admin(bool connection_admin_flag);
4865
4866 public:
4868
4869 /**
4870 Flag to indicate this thread is executing
4871 @ref sys_var::update for a @ref OPT_GLOBAL variable.
4872
4873 This flag imply the thread already holds @ref LOCK_global_system_variables.
4874 Knowing this is required to resolve reentrancy issues
4875 in the system variable code, when callers
4876 read system variable Y while inside an update function
4877 for system variable X.
4878 Executing table io while inside a system variable update function
4879 will indirectly cause this.
4880 @todo Clean up callers and remove m_inside_system_variable_global_update.
4881 */
4883
4884 public:
4885 /** The parameter value bindings for the current query. Allocated on the THD
4886 * memroot. Can be empty */
4888 /** the number of elements in parameters */
4890
4891 public:
4892 /**
4893 Copy session properties that affect table access
4894 from the parent session to the current session.
4895
4896 The following properties:
4897 - the OPTION_BIN_LOG flag,
4898 - the skip_readonly_check flag,
4899 - the transaction isolation (tx_isolation)
4900 are copied from the parent to the current THD.
4901
4902 This is useful to execute an isolated, internal THD session
4903 to access tables, while leaving tables in the parent session
4904 unchanged.
4905
4906 @param thd parent session
4907 */
4911
4914
4915#ifndef NDEBUG
4916 const char *current_key_name;
4920 return (is_error() &&
4921 (get_stmt_da()->mysql_errno() == ER_DA_GLOBAL_CONN_LIMIT ||
4922 get_stmt_da()->mysql_errno() == ER_DA_CONN_LIMIT));
4923 }
4924#endif
4925
4926 public:
4927 bool add_external(unsigned int slot, void *data);
4928 void *fetch_external(unsigned int slot);
4930
4931 private:
4932 std::unordered_map<unsigned int, void *> external_store_;
4933
4934 public:
4935 /* Indicates if we are inside loadable function */
4937
4938 public:
4940 if (!event_tracking_data_.empty()) return event_tracking_data_.top();
4941 return std::make_pair(Event_tracking_class::LAST, nullptr);
4942 }
4943
4945 unsigned long subevent, bool check_audited);
4946 bool event_notify(struct st_mysql_event_generic *event_data);
4949 }
4950
4951 private:
4955
4957
4961
4962 public:
4963 /// Flag indicating whether this session incremented the number of sessions
4964 /// with GTID_NEXT set to AUTOMATIC:tag
4966
4967 /// Count of Regular Statement Handles in use.
4969
4970 /// Increment the owned temptable counter. This is used to find leaked
4971 /// temptable handles during close_connection calls
4973 /// Decrement the owned temptable counter.
4975 /// Return currently owned temptable count.
4977
4978 private:
4979 /** Each THD can open multiple temptables, we create these temptable objects
4980 in the temptable engine. These objects have their lifetime controlled with
4981 create and delete_table calls in the temptable handler. The sql layer is
4982 responsible for calling the create and delete_table functions. We increment
4983 this counter in create, and decrement it in delete_table. This allows us to
4984 detect any situation where we call close_connection which releases the
4985 underlying memory in the temptable engine, before all temptable objects
4986 have been deleted. This way we can react and clean up any temptable objects
4987 before we free the underlying memory. So we can think of the THD as owning
4988 multiple temptable objects in the temptable engine, and we tie the lifetime
4989 of these objects to the lifetime of the THD. In normal operation they
4990 should be deleted before the close_connection call but this enforces
4991 defined behaviour when they aren't.
4992 */
4994
4995 private:
4997 /// Member to store count of tables in foreign key cascade chains.
4999
5000 public:
5003
5008};
5009
5010/**
5011 Return lock_tables_mode for secondary engine.
5012 @param cthd thread context
5013 @retval true if lock_tables_mode is on
5014 @retval false, otherwise
5015 */
5016inline bool secondary_engine_lock_tables_mode(const THD &cthd) {
5017 return (cthd.locked_tables_mode == LTM_LOCK_TABLES ||
5019}
5020
5021/** A short cut for thd->get_stmt_da()->set_ok_status(). */
5022void my_ok(THD *thd, ulonglong affected_rows = 0, ulonglong id = 0,
5023 const char *message = nullptr);
5024
5025/** A short cut for thd->get_stmt_da()->set_eof_status(). */
5026void my_eof(THD *thd);
5027
5028bool add_item_to_list(THD *thd, Item *item);
5029
5030/*************************************************************************/
5031
5032/**
5033 Check if engine substitution is allowed in the current thread context.
5034
5035 @param thd thread context
5036 @retval true if engine substitution is allowed
5037 @retval false otherwise
5038*/
5039
5040inline bool is_engine_substitution_allowed(const THD *thd) {
5042}
5043
5044/**
5045 Returns if the user of the session has the SYSTEM_USER privilege or not.
5046
5047 @retval true User has SYSTEM_USER privilege
5048 @retval false Otherwise
5049*/
5050inline bool THD::is_system_user() {
5051 return m_is_system_user.load(std::memory_order_seq_cst);
5052}
5053
5054/**
5055 Sets the system_user flag atomically for the current session.
5056
5057 @param [in] system_user_flag boolean flag that indicates value to set.
5058*/
5059inline void THD::set_system_user(bool system_user_flag) {
5060 m_is_system_user.store(system_user_flag, std::memory_order_seq_cst);
5061}
5062
5063/**
5064 Returns if the user of the session has the CONNECTION_ADMIN privilege or not.
5065
5066 @retval true User has CONNECTION_ADMIN privilege
5067 @retval false Otherwise
5068*/
5070 return m_is_connection_admin.load(std::memory_order_seq_cst);
5071}
5072
5073/**
5074 Sets the connection_admin flag atomically for the current session.
5075
5076 @param [in] connection_admin_flag boolean flag that indicates value to set.
5077*/
5078inline void THD::set_connection_admin(bool connection_admin_flag) {
5079 m_is_connection_admin.store(connection_admin_flag, std::memory_order_seq_cst);
5080}
5081
5082/**
5083 Returns true if xa transactions are detached as part of executing XA PREPARE.
5084*/
5085inline bool is_xa_tran_detached_on_prepare(const THD *thd) {
5086 return thd->variables.xa_detach_on_prepare;
5087}
5088
5089/**
5090 Return if source replication node is older than the given version.
5091 @param thd thread context
5092 @param version version number to compare
5093
5094 @retval true if source version is older
5095 @retval false otherwise
5096 */
5097inline bool is_rpl_source_older(const THD *thd, uint version) {
5098 return thd->is_applier_thread() &&
5099 (thd->variables.original_server_version == UNDEFINED_SERVER_VERSION ||
5100 thd->variables.original_server_version < version);
5101}
5102
5103/**
5104 * @brief Check if foreign handling at SQL is enabled.
5105 *
5106 * @param thd Thread Handle.
5107 *
5108 * @return true If enabled.
5109 * @return false Otherwise.
5110 */
5112 DBUG_EXECUTE_IF("force_innodb_fk", return false;);
5113 DBUG_EXECUTE_IF("force_sql_fk", return true;);
5114 assert(thd != nullptr);
5115 return thd->variables.option_bits & OPTION_USE_SQL_FOREIGN_KEY_HANDLING;
5116}
5117
5118/**
5119 * @brief Check if SQL foreign key handling can be used for a table.
5120 *
5121 * @param thd Thread Handle.
5122 * @param table TABLE instance of a table.
5123 *
5124 * @return true if SQL FK checks supported for SE.
5125 * @return false Otherwise.
5126 */
5128
5129/**
5130 * @brief Check if SQL FK cascade should fire triggers.
5131 *
5132 * @param thd Thread Handle.
5133 *
5134 * @return true If enabled.
5135 * @return false Otherwise.
5136 */
5138 assert(thd != nullptr);
5139 if (is_rpl_source_older(thd, 90700)) return false;
5140 return thd->variables.enable_cascade_triggers;
5141}
5142#endif /* SQL_CLASS_INCLUDED */
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
uint32_t Access_bitmask
Definition: auth_acls.h:34
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
int64 query_id_t
Definition: binlog.h:73
API for getting cost estimates for server operations that are not directly related to a table object.
Definition: opt_costmodel.h:54
Stores status of the currently executed statement.
Definition: sql_error.h:274
bool is_error() const
Definition: sql_error.h:371
void reset_diagnostics_area()
Clear this Diagnostics Area.
Definition: sql_error.cc:362
Diagnostics_area * pop_diagnostics_area()
Pop "this" off the Diagnostics Area stack.
Definition: sql_error.cc:688
const Diagnostics_area * stacked_da() const
Returns the Diagnostics Area below the current diagnostics area on the stack.
Definition: sql_error.h:614
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:677
List of Discrete_interval objects.
Definition: discrete_interval.h:87
bool append(Discrete_interval *new_interval)
Definition: discrete_interval.h:117
void clear()
Definition: discrete_interval.h:144
Definition: reference_caching_setup.h:109
void refresh_all()
Definition: reference_caching_setup.cc:260
Definition: sql_audit.h:375
An instance of the global read lock in a connection.
Definition: sql_class.h:840
bool can_acquire_protection() const
Check if this connection can acquire protection against GRL and emit error if otherwise.
Definition: sql_class.h:860
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:884
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:878
enum_grl_state m_state
Definition: sql_class.h:872
bool is_acquired() const
Definition: sql_class.h:868
Global_read_lock()
Definition: sql_class.h:848
enum_grl_state
Definition: sql_class.h:842
@ GRL_ACQUIRED_AND_BLOCKS_COMMIT
Definition: sql_class.h:845
@ GRL_ACQUIRED
Definition: sql_class.h:844
@ GRL_NONE
Definition: sql_class.h:843
Represents a set of GTIDs.
Definition: rpl_gtid.h:1558
void clear()
Removes all gtids from this Gtid_set.
Definition: rpl_gtid_set.cc:276
Either statement transaction or normal transaction - related thread-specific storage engine data.
Definition: transaction_info.h:430
This class represents the interface for internal error handlers.
Definition: error_handler.h:47
A registry for item tree transformations performed during query optimization.
Definition: sql_class.h:541
bool m_cancel
Definition: sql_class.h:552
Item * old_value
Definition: sql_class.h:550
Item_change_record(Item **place, Item *new_value)
Definition: sql_class.h:547
Item ** place
Definition: sql_class.h:549
Item * new_value
Definition: sql_class.h:551
Item_change_record()=default
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:935
Definition: sql_list.h:494
Tables that were locked with LOCK TABLES statement.
Definition: locked_tables_list.h:89
An interface to separate the MDL module from the THD, and the rest of the server code.
Definition: mdl.h:86
Context of the owner of metadata locks.
Definition: mdl.h:1415
void set_explicit_duration_for_all_locks()
Set explicit duration for all locks in the context.
Definition: mdl.cc:4640
Savepoint for MDL context.
Definition: mdl.h:1320
A granted metadata lock.
Definition: mdl.h:988
Table modification plan for JOIN-less statements (update/delete)
Definition: opt_explain.h:82
Storage for backup of Open_tables_state.
Definition: sql_class.h:699
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:708
Class that holds information about tables which were opened and locked by the thread.
Definition: sql_class.h:563
MYSQL_LOCK * lock
Definition: sql_class.h:631
TABLE * open_tables
List of regular tables in use by this thread.
Definition: sql_class.h:610
MYSQL_LOCK * extra_lock
Definition: sql_class.h:638
Open_tables_state()
This constructor initializes Open_tables_state instance which can only be used as backup storage.
Definition: sql_class.h:685
uint state_flags
Definition: sql_class.h:678
void reset_open_tables_state()
Definition: sql_class.cc:665
Reprepare_observer * pop_reprepare_observer()
Definition: sql_class.h:597
void push_reprepare_observer(Reprepare_observer *o)
Definition: sql_class.h:593
enum_flags
Definition: sql_class.h:670
@ BACKUPS_AVAIL
Definition: sql_class.h:671
@ SYSTEM_TABLES
Definition: sql_class.h:672
enum enum_locked_tables_mode locked_tables_mode
Definition: sql_class.h:668
Reprepare_observer * get_reprepare_observer() const
Definition: sql_class.h:588
TABLE * temporary_tables
List of temporary tables used by this thread.
Definition: sql_class.h:616
void reset_reprepare_observers()
Definition: sql_class.h:603
void set_open_tables_state(Open_tables_state *state)
Definition: sql_class.cc:650
Prealloced_array< Reprepare_observer *, 4 > m_reprepare_observers
A stack of Reprepare_observer-instances.
Definition: sql_class.h:585
A per-session context which is always available at any point of execution, because in practice it's a...
Definition: opt_trace_context.h:94
Profiling state for a single THD; contains multiple QUERY_PROFILE objects.
Definition: sql_profile.h:226
Internal state of the parser.
Definition: sql_lexer_parser_state.h:44
Plugin array helper class.
Definition: sql_plugin_ref.h:110
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:71
Container for all prepared statements created/used in a connection.
Definition: sql_class.h:489
Prepared_statement_map()
Definition: sql_class.cc:2176
void claim_memory_ownership(bool claim)
Definition: sql_class.cc:2238
Prepared_statement * find_by_name(const LEX_CSTRING &name)
Find prepared statement by name.
Definition: sql_class.cc:2213
int insert(Prepared_statement *statement)
Insert a new statement to the thread-local prepared statement map.
Definition: sql_class.cc:2182
Prepared_statement * m_last_found_statement
Definition: sql_class.h:531
~Prepared_statement_map()
Definition: sql_class.cc:2262
void reset()
Definition: sql_class.cc:2244
void erase(Prepared_statement *statement)
Erase all prepared statements (calls Prepared_statement destructor).
Definition: sql_class.cc:2227
collation_unordered_map< std::string, Prepared_statement * > names_hash
Definition: sql_class.h:530
malloc_unordered_map< ulong, std::unique_ptr< Prepared_statement > > st_hash
Definition: sql_class.h:529
Prepared_statement * find(ulong id)
Find prepared statement by ID.
Definition: sql_class.cc:2218
Prepared_statement: a statement that can contain placeholders.
Definition: sql_prepare.h:150
Definition: protocol_classic.h:242
Definition: protocol_classic.h:54
Class used for the old (MySQL 4.0 protocol).
Definition: protocol_classic.h:220
Definition: protocol.h:33
Definition: sql_class.h:354
enum_state get_state() const
Definition: sql_class.h:417
bool is_stmt_prepare_or_first_stmt_execute() const
Definition: sql_class.h:422
T * memdup_typed(const T *mem)
Definition: sql_class.h:440
enum_state
Definition: sql_class.h:373
@ STMT_INITIALIZED
Definition: sql_class.h:374
@ STMT_ERROR
Definition: sql_class.h:379
@ STMT_REGULAR_EXECUTION
Definition: sql_class.h:377
@ STMT_PREPARED
Definition: sql_class.h:376
@ STMT_INITIALIZED_FOR_SP
Definition: sql_class.h:375
@ STMT_EXECUTED
Definition: sql_class.h:378
bool is_repreparing
To check whether a reprepare operation is active.
Definition: sql_class.h:365
bool is_stmt_prepare() const
Definition: sql_class.h:418
LEX_CSTRING strmake(LEX_CSTRING str)
Definition: sql_class.h:447
void reset_item_list()
Definition: sql_class.h:412
char * mem_strdup(const char *str)
Definition: sql_class.h:443
void free_items()
Definition: sql_class.cc:2140
Item * m_item_list
Definition: sql_class.h:360
void * alloc(size_t size)
Definition: sql_class.h:428
Query_arena(MEM_ROOT *mem_root_arg, enum enum_state state_arg)
Definition: sql_class.h:399
bool is_regular() const
Definition: sql_class.h:426
void set_query_arena(const Query_arena &set)
Copies memory-managing members from set.
Definition: sql_class.cc:2151
char * strmake(const char *str, size_t size) const
Definition: sql_class.h:444
enum_state state
Definition: sql_class.h:396
void set_item_list(Item *item)
Definition: sql_class.h:413
void add_item(Item *item)
Definition: sql_class.cc:2134
void * mem_calloc(size_t size)
Definition: sql_class.h:429
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:2157
void set_state(enum_state state_arg)
Definition: sql_class.h:416
T * alloc_typed()
Definition: sql_class.h:435
Query_arena()
Definition: sql_class.h:406
Item * item_list() const
Definition: sql_class.h:411
bool is_stmt_prepare_or_first_sp_execute() const
Definition: sql_class.h:419
void * memdup(const void *str, size_t size)
Definition: sql_class.h:453
MEM_ROOT * mem_root
Definition: sql_class.h:363
virtual ~Query_arena()=default
Definition: query_result.h:60
Definition: sql_lex.h:2777
Definition: rpl_rli.h:208
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:2807
Definition: rpl_context.h:411
A Lambda to be called at scope exit.
Definition: scope_guard.h:55
Base class for secondary engine statement context objects.
Definition: sql_class.h:936
virtual bool is_primary_engine_optimal() const
Definition: sql_class.h:946
virtual ~Secondary_engine_statement_context()=default
Destructs the secondary engine statement context object.
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:54
Definition: sys_vars_resource_mgr.h:70
Definition: session_tracker.h:129
Sql_cmd_common_signal represents the common properties of the SIGNAL and RESIGNAL statements.
Definition: sql_signal.h:88
Sql_cmd_resignal represents a RESIGNAL statement.
Definition: sql_signal.h:168
Sql_cmd_signal represents a SIGNAL statement.
Definition: sql_signal.h:148
Representation of a SQL condition.
Definition: sql_error.h:61
enum_severity_level
Enumeration value describing the severity of the condition.
Definition: sql_error.h:66
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:169
Used to save context when executing a function or trigger.
Definition: sql_class.h:750
ulonglong option_bits
Definition: sql_class.h:752
bool enable_slow_log
Definition: sql_class.h:761
ulong client_capabilities
Definition: sql_class.h:759
ulonglong first_successful_insert_id_in_cur_stmt
Definition: sql_class.h:754
ha_rows examined_row_count
Definition: sql_class.h:758
SAVEPOINT * savepoints
Definition: sql_class.h:762
ulonglong current_found_rows
Definition: sql_class.h:756
ha_rows sent_row_count
Definition: sql_class.h:758
ulonglong previous_found_rows
Definition: sql_class.h:757
enum enum_check_fields check_for_truncated_fields
Definition: sql_class.h:763
Discrete_intervals_list auto_inc_intervals_forced
Definition: sql_class.h:755
ha_rows num_truncated_fields
Definition: sql_class.h:758
uint in_sub_stmt
Definition: sql_class.h:760
ulonglong first_successful_insert_id_in_prev_stmt
Definition: sql_class.h:753
A derived from THD::Attachable_trx class allows updates in the attachable transaction.
Definition: sql_class.h:2165
bool is_read_only() const override
Definition: sql_class.h:2167
Attachable_trx_rw(const Attachable_trx_rw &)
Attachable_trx_rw & operator=(const Attachable_trx_rw &)
Attachable_trx_rw(THD *thd)
Definition: sql_class.cc:580
Class representing read-only attachable transaction, encapsulates knowledge how to backup state of cu...
Definition: sql_class.h:2122
THD * m_thd
THD instance.
Definition: sql_class.h:2133
Transaction_state m_trx_state
Transaction state data.
Definition: sql_class.h:2144
virtual ~Attachable_trx()
Definition: sql_class.cc:536
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:2141
Attachable_trx(THD *thd, Attachable_trx *prev_trx)
Definition: sql_class.cc:441
virtual bool is_read_only() const
Definition: sql_class.h:2129
enum_reset_lex m_reset_lex
Definition: sql_class.h:2135
Attachable_trx * get_prev_attachable_trx() const
Definition: sql_class.h:2126
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:1447
void set_query_plan(enum_sql_command sql_cmd, LEX *lex_arg, bool ps)
Set query plan.
Definition: sql_class.cc:2807
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:2802
bool is_single_table_plan() const
Definition: sql_class.cc:3149
THD *const thd
Definition: sql_class.h:1449
Query_plan & operator=(const Query_plan &)
not defined
Query_plan(const Query_plan &)
not defined
bool is_ps_query() const
Definition: sql_class.h:1502
LEX * lex
LEX of topmost statement.
Definition: sql_class.h:1453
bool is_ps
True if query is run in prepared statement.
Definition: sql_class.h:1457
const Modification_plan * modification_plan
Query plan for UPDATE/DELETE/INSERT/REPLACE.
Definition: sql_class.h:1455
Modification_plan const * get_modification_plan() const
Definition: sql_class.h:1498
enum_sql_command get_command() const
Definition: sql_class.h:1490
LEX * get_lex() const
Definition: sql_class.h:1494
Query_plan(THD *thd_arg)
Definition: sql_class.h:1471
enum_sql_command sql_command
Original sql_command;.
Definition: sql_class.h:1451
void set_modification_plan(Modification_plan *plan_arg)
Definition: sql_class.cc:2823
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
bool is_being_disposed() const
Check if THD is being disposed (i.e.
Definition: sql_class.cc:1431
enum_vio_type get_vio_type() const
Definition: sql_class.cc:2052
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:1606
bool has_gtid_consistency_violation
Definition: sql_class.h:4077
std::unique_ptr< Secondary_engine_statement_context > m_secondary_engine_statement_context
Current query's secondary engine statement context.
Definition: sql_class.h:1077
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:3983
Rpl_thd_context rpl_thd_ctx
Definition: sql_class.h:3975
struct THD_timer_info * timer
Holds active timer object.
Definition: sql_class.h:1917
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:3176
uint fill_variables_recursion_level
Definition: sql_class.h:1704
thd_scheduler scheduler
Definition: sql_class.h:4139
ulonglong first_successful_insert_id_in_prev_stmt_for_binlog
Definition: sql_class.h:2266
void set_stack_base(const char *captured_base)
Set a base captured earlier, or clear it with nullptr.
Definition: sql_class.h:1341
mysql_mutex_t LOCK_thd_query
Protects THD::m_query_string.
Definition: sql_class.h:1269
bool get_sql_foreign_keys() const
PSI_statement_locker * m_statement_psi
Current statement instrumentation.
Definition: sql_class.h:2541
std::unique_ptr< dd::cache::Dictionary_client > m_dd_client
Definition: sql_class.h:1015
void disconnect(bool server_shutdown=false)
Disconnect the associated communication endpoint.
Definition: sql_class.cc:1736
bool m_is_admin_conn
Definition: sql_class.h:1644
PSI_transaction_locker_state m_transaction_state
Current transaction instrumentation state.
Definition: sql_class.h:2551
PSI_stage_progress * m_stage_progress_psi
Current stage progress instrumentation.
Definition: sql_class.h:2532
std::atomic< bool > m_is_system_user
Flag that indicates if the user of current session has SYSTEM_USER privilege.
Definition: sql_class.h:4852
void cleanup_connection(void)
Definition: sql_class.cc:1266
Gtid owned_gtid
The GTID of the currently owned transaction.
Definition: sql_class.h:3850
sql_digest_state * m_digest
Current statement digest.
Definition: sql_class.h:2534
Diagnostics_area m_query_rewrite_plugin_da
Definition: sql_class.h:4547
void clear_binlog_local_stmt_filter()
Definition: sql_class.h:1902
struct System_status_var * initial_status_var
Definition: sql_class.h:1182
struct THD::@182 binlog_evt_union
ulonglong first_successful_insert_id_in_cur_stmt
Definition: sql_class.h:2272
void store_globals()
Definition: sql_class.cc:1807
Secondary_engine_optimization m_secondary_engine_optimization
This flag tells if a secondary storage engine can be used to execute a query in this session.
Definition: sql_class.h:4837
void push_lock_usec(ulonglong &top)
Definition: sql_class.h:1672
rpl_event_coordinates binlog_next_event_pos
Definition: sql_class.h:1749
void reset_n_backup_open_tables_state(Open_tables_backup *backup, uint add_state_flags)
Definition: sql_class.cc:2306
void claim_memory_ownership(bool claim)
Claim all the memory used by the THD object.
Definition: sql_class.cc:3055
std::atomic< uint > m_cached_rw_status
Definition: sql_class.h:1325
void inc_status_select_range()
Definition: sql_class.cc:2544
void set_row_count_func(longlong row_count_func)
Definition: sql_class.h:2458
std::unordered_map< unsigned int, void * > external_store_
Definition: sql_class.h:4932
bool is_a_srv_session() const
Definition: sql_class.h:4716
void set_catalog(const LEX_CSTRING &catalog)
Definition: sql_class.h:1513
void clear_binlog_table_maps()
Definition: sql_class.h:2027
void enable_low_level_commit_ordering()
Enables ordering in ha_commit_low.
Definition: sql_class.cc:3134
void unlock_query_plan()
Definition: sql_class.h:1330
void get_trans_pos(const char **file_var, my_off_t *pos_var) const
Definition: sql_class.h:2731
void rpl_detach_engine_ha_data()
When the thread is a binlog or slave applier it detaches the engine ha_data associated with it and me...
Definition: sql_class.cc:3089
uint fill_status_recursion_level
Used by fill_status() to avoid acquiring LOCK_status mutex twice when this function is called recursi...
Definition: sql_class.h:1703
bool interpret_utf8_as_utf8mb4() const
Definition: sql_class.h:3222
longlong m_row_count_func
Stores the result of ROW_COUNT() function.
Definition: sql_class.h:2453
unsigned long bind_parameter_values_count
the number of elements in parameters
Definition: sql_class.h:4889
bool is_current_stmt_binlog_disabled() const
Determine if binlogging is currently disabled for this session.
Definition: sql_class.cc:3115
void dec_fk_cascade_chain_tables()
Definition: sql_class.h:5006
PS_PARAM * bind_parameter_values
The parameter value bindings for the current query.
Definition: sql_class.h:4887
static const int OWNED_SIDNO_GTID_SET
Definition: sql_class.h:3851
Discrete_intervals_list auto_inc_intervals_forced
Definition: sql_class.h:2318
void set_psi(PSI_thread *psi)
Save the performance schema thread instrumentation associated with this user session.
Definition: sql_class.h:4157
bool add_external(unsigned int slot, void *data)
Definition: sql_class.cc:3385
void request_persist_gtid_by_se()
Request SE to persist GTID explicitly.
Definition: sql_class.h:3912
void set_query(const char *query_arg, size_t query_length_arg)
Assign a new value to thd->m_query_string.
Definition: sql_class.h:4358
const String normalized_query()
The current query in normalized form.
Definition: sql_class.cc:3154
void reset_query_for_display()
Reset query string to be displayed in PFS.
Definition: sql_class.h:4342
PSI_thread * get_psi() const
Read the performance schema thread instrumentation associated with this user session.
Definition: sql_class.h:4164
void init_cost_model()
Initialize the optimizer cost model.
Definition: sql_class.cc:3866
std::bitset< SE_GTID_MAX > Se_GTID_flagset
Definition: sql_class.h:3878
ulong statement_id_counter
Definition: sql_class.h:2574
void enter_cond(mysql_cond_t *cond, mysql_mutex_t *mutex, const PSI_stage_info *stage, PSI_stage_info *old_stage, const char *src_function, const char *src_file, int src_line) override
Enter a condition wait.
Definition: sql_class.h:3111
bool is_log_reset() const
Definition: sql_class.h:3906
bool slave_thread
Definition: sql_class.h:2807
bool m_is_fatal_error
Set to true if execution of the current compound statement can not continue.
Definition: sql_class.h:2819
void shutdown_active_vio()
Definition: sql_class.cc:2057
std::unique_ptr< Protocol_binary > protocol_binary
Definition: sql_class.h:1396
bool is_waiting_for_disk_space() const
Returns the current waiting_for_disk_space flag value.
Definition: sql_class.h:4797
uint dbug_sentry
Definition: sql_class.h:1585
ulonglong first_successful_insert_id_in_prev_stmt
Definition: sql_class.h:2259
Diagnostics_area main_da
Definition: sql_class.h:4545
dd::cache::Dictionary_client * dd_client() const
Definition: sql_class.h:1009
enum_binlog_query_type
Definition: sql_class.h:3095
@ ROW_QUERY_TYPE
Definition: sql_class.h:3097
@ QUERY_TYPE_COUNT
Definition: sql_class.h:3102
@ STMT_QUERY_TYPE
Definition: sql_class.h:3100
SSL_handle m_SSL
SSL data attached to this connection.
Definition: sql_class.h:1440
dd::DD_kill_immunizer * kill_immunizer
When operation on DD tables is in progress then THD is set to kill immune mode.
Definition: sql_class.h:2800
LEX_CSTRING m_invoker_host
Definition: sql_class.h:4570
Prealloced_array< unsigned long, 11 > audit_class_mask
Array of bits indicating which audit classes have already been added to the list of audit plugins whi...
Definition: sql_class.h:2931
bool is_applier_thread() const
Definition: sql_class.h:2039
void set_invoker(const LEX_STRING *user, const LEX_STRING *host)
Definition: sql_class.h:4520
void set_new_thread_id()
Assign a value to m_thread_id by calling Global_THD_manager::get_new_thread_id().
Definition: sql_class.cc:1235
XID debug_binlog_xid_last
Definition: sql_class.h:4767
PSI_statement_locker_state m_statement_state
Current statement instrumentation state.
Definition: sql_class.h:2544
bool notify_hton_pre_acquire_exclusive(const MDL_key *mdl_key, bool *victimized) override
Notify/get permission from interested storage engines before acquiring exclusive lock for the key.
Definition: sql_class.cc:3170
void reset_fk_cascade_chain_tables()
Definition: sql_class.h:5007
const st_plugin_int * m_plugin
Stores the plugin id it is attached to (if any).
Definition: sql_class.h:4745
void pop_diagnostics_area()
Pop the top DA off the Diagnostics Area stack.
Definition: sql_class.h:3415
bool m_binlog_invoker
It will be set TRUE if CURRENT_USER() is called in account management statements or default definer i...
Definition: sql_class.h:4561
MDL_context mdl_context
Definition: sql_class.h:973
void unpin_gtid()
Unpin and free GTID and TSID.
Definition: sql_class.h:3887
mysql_cond_t COND_thr_lock
Condition variable used for waiting by the THR_LOCK.c subsystem.
Definition: sql_class.h:1610
thr_lock_type insert_lock_default
Type of lock to be used for INSERT statement if lock is not specified explicitly.
Definition: sql_class.h:1690
bool running_explain_analyze
Whether we are currently in the execution phase of an EXPLAIN ANALYZE query.
Definition: sql_class.h:2791
void clear_current_query_costs()
Clear the query costs attributes for the current query.
Definition: sql_class.h:1206
bool has_invoker() const
Definition: sql_class.h:4528
std::unique_ptr< Protocol_text > protocol_text
Definition: sql_class.h:1395
void increment_updates_counter()
Definition: sql_class.cc:2764
const char * proc_info_session(THD *invoking_thd) const
Return the m_proc_info, possibly using the string of an older server release, according to @session....
Definition: sql_class.h:1559
collation_unordered_map< std::string, unique_ptr_my_free< Table_ref > > handler_tables_hash
Definition: sql_class.h:1575
enum_tx_isolation tx_isolation
Definition: sql_class.h:2660
bool is_error() const
true if there is an error in the error stack.
Definition: sql_class.h:3360
unsigned char * m_token_array
Current statement digest token array.
Definition: sql_class.h:2536
void set_ssl(Vio *vio)
Definition: sql_class.cc:1241
void save_current_query_costs()
Save the current query costs attributes in the thread session status.
Definition: sql_class.h:1221
bool is_cleanup_done()
Definition: sql_class.cc:1319
my_off_t m_trans_end_pos
Definition: sql_class.h:1991
void restore_sub_statement_state(Sub_statement_state *backup)
Definition: sql_class.cc:2421
THD * get_thd() override
Within MDL subsystem this one is only used for DEBUG_SYNC.
Definition: sql_class.h:3157
void register_action_before_gtid_state_update(std::function< void(bool)> f)
Register an action that will run before this THD externalizes its owned GTID state.
Definition: sql_class.h:4049
void leave_locked_tables_mode()
Leave explicit LOCK TABLES or prelocked mode and restore value of transaction sentinel in MDL subsyst...
Definition: sql_class.cc:2638
bool skip_transaction_read_only_check
Definition: sql_class.h:1935
my_thread_id thread_id() const
Definition: sql_class.h:2596
resourcegroups::Resource_group_ctx * resource_group_ctx()
Get resource group context.
Definition: sql_class.h:4147
void set_trans_pos(const char *file, my_off_t pos)
Functions to set and get transaction position.
Definition: sql_class.h:2706
my_thread_t real_id
Definition: sql_class.h:2576
void push_protocol(const std::unique_ptr< ProtocolClass > &protocol)
Definition: sql_class.h:3428
void begin_attachable_rw_transaction()
Start a read-write attachable transaction.
Definition: sql_class.cc:2341
void lock_query_plan()
Locks the query plan of this THD.
Definition: sql_class.h:1329
void nocheck_register_item_tree_change(Item **place, Item *new_value)
Remember that place was updated with new_value so it can be restored by rollback_item_tree_changes().
Definition: sql_class.cc:2097
ha_rows get_examined_row_count() const
Definition: sql_class.h:2504
void get_trans_fixed_pos(const char **file_var, my_off_t *pos_var) const
Definition: sql_class.h:2741
bool copy_db_to(char **p_db, size_t *p_db_length) const
Definition: sql_class.h:4135
void set_security_context(Security_context *sctx)
Definition: sql_class.h:1368
void send_kill_message() const
Definition: sql_class.cc:2270
void inc_fk_cascade_chain_tables()
Definition: sql_class.h:5005
void inc_status_select_scan()
Definition: sql_class.cc:2560
Event_tracking_data_stack event_tracking_data_
Definition: sql_class.h:4959
void reset_gtid_persisted_by_se()
Reset by SE at transaction end after persisting GTID.
Definition: sql_class.h:3918
bool tx_commit_pending
Definition: sql_class.h:1100
void decrement_temptable_count()
Decrement the owned temptable counter.
Definition: sql_class.h:4974
USER_CONN * m_user_connect
Definition: sql_class.h:2484
void swap_rewritten_query(String &query_arg)
Set the rewritten query (with passwords obfuscated etc.) on the THD.
Definition: sql_class.cc:3249
Cost_model_server m_cost_model
Optimizer cost model for server operations.
Definition: sql_class.h:4578
char scramble[SCRAMBLE_LENGTH+1]
Definition: sql_class.h:2803
my_timeval query_start_timeval_trunc(uint decimals)
Definition: sql_class.cc:1069
void inc_status_sort_scan()
Definition: sql_class.cc:2593
PSI_stage_key m_current_stage_key
Definition: sql_class.h:1516
Relay_log_info * rli_slave
Definition: sql_class.h:1097
uint open_options
Definition: sql_class.h:2599
double double_value
Definition: sql_class.h:2881
List< Security_context > m_view_ctx_list
Definition: sql_class.h:1380
bool is_current_stmt_binlog_enabled_and_caches_empty() const
Checks whether binlog caches are disabled (binlog does not cache data) or empty in case binloggging i...
Definition: sql_class.cc:3125
Query_arena * stmt_arena
Definition: sql_class.h:2237
enum_binlog_format current_stmt_binlog_format
Indicates the format in which the current statement will be logged.
Definition: sql_class.h:1949
void reset_query()
Definition: sql_class.h:4363
void clear_clone_vio()
Clear clone network Vio for remote clone.
Definition: sql_class.h:3070
void inc_status_created_tmp_tables()
Definition: sql_class.cc:2515
uint get_rand_seed() const override
Provide thread specific random seed for MDL_context's PRNG.
Definition: sql_class.h:3195
ha_rows m_sent_row_count
Number of rows we actually sent to the client, including "synthetic" rows in ROLLUP etc.
Definition: sql_class.h:2469
std::atomic< PSI_thread * > m_psi
Performance schema thread instrumentation for this session.
Definition: sql_class.h:4174
void raise_error_printf(uint code,...)
Raise an exception condition, with a formatted message.
Definition: sql_class.cc:1019
bool m_is_low_level_commit_ordering_enabled
Flag indicating whether additional ordering in the ha_commit_low function is enabled.
Definition: sql_class.h:1635
void set_status_no_index_used()
Definition: sql_class.cc:2601
size_t m_opened_temptable_count
Each THD can open multiple temptables, we create these temptable objects in the temptable engine.
Definition: sql_class.h:4993
static const int OWNED_SIDNO_ANONYMOUS
Definition: sql_class.h:3852
bool push_event_tracking_data(Event_tracking_class event, const Event_tracking_information *Event_tracking_information)
Definition: sql_class.cc:3435
Vio * clone_vio
Definition: sql_class.h:2198
bool is_server_upgrade_thread() const
Definition: sql_class.h:2632
void end_statement()
Definition: sql_class.cc:2163
LEX_CSTRING m_query_string
The query associated with this statement.
Definition: sql_class.h:1020
const CHARSET_INFO * collation()
Definition: sql_class.h:3203
bool charset_is_collation_connection
Definition: sql_class.h:2857
LEX_CSTRING m_invoker_user
It points to the invoker in the Query_log_event.
Definition: sql_class.h:4569
bool is_extrenal_xa() const
Definition: sql_class.h:3940
void reset_binlog_local_stmt_filter()
Definition: sql_class.h:1898
mysql_mutex_t LOCK_query_plan
Protects query plan (SELECT/UPDATE/DELETE's) from being freed/changed while another thread explains i...
Definition: sql_class.h:1316
void time_out_user_resource_limits()
Definition: sql_class.cc:2787
void clear_active_vio()
Definition: sql_class.h:3054
const Protocol * get_protocol() const
Definition: sql_class.h:1398
ulonglong m_lock_usec
Time spent waiting for TABLE locks and DATA locks.
Definition: sql_class.h:1667
bool need_binlog_invoker() const
Definition: sql_class.h:4518
bool is_dd_system_thread() const
Definition: sql_class.h:2606
ulong max_client_packet_length
Definition: sql_class.h:1572
int thd_tx_priority
Definition: sql_class.h:2676
LEX_CSTRING m_db
Name of the current (default) database.
Definition: sql_class.h:1041
std::atomic< bool > m_safe_to_display
Definition: sql_class.h:1022
binlog_filter_state get_binlog_local_stmt_filter() const
Definition: sql_class.h:1912
uchar * binlog_row_event_extra_data
Definition: sql_class.h:1758
THR_LOCK_INFO lock_info
Definition: sql_class.h:1255
bool derived_tables_processing
Definition: sql_class.h:2861
void pop_event_tracking_data()
Definition: sql_class.cc:3480
void record_first_successful_insert_id_in_cur_stmt(ulonglong id_arg)
Definition: sql_class.h:2355
unsigned short m_regular_statement_handle_count
Count of Regular Statement Handles in use.
Definition: sql_class.h:4968
long long_value
Definition: sql_class.h:2878
LEX_CSTRING m_catalog
Currently selected catalog.
Definition: sql_class.h:1028
Opt_trace_context opt_trace
optimizer trace of current statement
Definition: sql_class.h:4206
bool in_loadable_function
Definition: sql_class.h:4936
bool send_result_set_row(const mem_root_deque< Item * > &row_items)
Send one result set row.
Definition: sql_class.cc:2998
bool is_system_thread() const
Definition: sql_class.h:2603
void set_admin_connection(bool admin)
Definition: sql_class.h:1647
class THD::Query_plan query_plan
std::list< std::function< bool(const THD &)> > m_skip_gtid_rollback_checkers
Callback functions that determine if GTID rollback shall be skipped.
Definition: sql_class.h:4018
void reset_sub_statement_state(Sub_statement_state *backup, uint new_state)
Definition: sql_class.cc:2376
bool is_a_srv_session_thd
Variable to mark if the object is part of a Srv_session object, which aggregates THD.
Definition: sql_class.h:4742
Thd_mem_cnt m_mem_cnt
Controlled memory stats for this session.
Definition: sql_class.h:964
LEX * lex
Definition: sql_class.h:1008
bool status_var_aggregated
Definition: sql_class.h:1184
ulonglong current_found_rows
Dynamic, collected and set also in subqueries.
Definition: sql_class.h:2396
const char * stack_base() const
Definition: sql_class.h:1345
void increment_questions_counter()
Definition: sql_class.cc:2770
void increment_user_connections_counter()
Definition: sql_class.cc:2745
void set_clone_vio(Vio *vio)
Set active clone network Vio for remote clone.
Definition: sql_class.h:3063
Time_zone * time_zone()
Definition: sql_class.h:3207
void set_system_user(bool system_user_flag)
Sets the system_user flag atomically for the current session.
Definition: sql_class.h:5059
const Diagnostics_area * get_stmt_da() const
Returns first Diagnostics Area for the current statement.
Definition: sql_class.h:3366
query_id_t query_id
Definition: sql_class.h:2571
void set_safe_display(bool safe)
Set if the query string to be safe to display.
Definition: sql_class.h:4352
ulonglong get_lock_usec()
Definition: sql_class.h:1670
Session_sysvar_resource_manager session_sysvar_res_mgr
Definition: sql_class.h:4595
auto register_skip_gtid_rollback_checker(const std::invocable< const THD & > auto &shall_skip)
Register a callback function that will determine if a subsequent GTID rollback shall be skipped.
Definition: sql_class.h:4036
void send_statement_status()
Definition: sql_class.cc:3017
void capture_stack_base(const void *local_marker)
Resolve and save the stack base for the current execution context.
Definition: sql_class.h:1336
bool is_connected(bool use_cached_connection_alive=false) final
Return false if connection to client is broken.
Definition: sql_class.cc:3300
LEX_CSTRING get_invoker_user() const
Definition: sql_class.h:4526
bool fill_information_schema_tables() const
Definition: sql_class.h:3308
void set_waiting_for_disk_space(bool waiting)
Set the waiting_for_disk_space flag.
Definition: sql_class.h:4791
std::atomic< mysql_mutex_t * > current_mutex
The mutex used with current_cond.
Definition: sql_class.h:1596
void decrement_user_connections_counter()
Definition: sql_class.cc:2751
~THD() override
Definition: sql_class.cc:1530
my_thread_id m_thread_id
This counter is 32 bit because of the client protocol.
Definition: sql_class.h:2588
void set_command(enum enum_server_command command)
Definition: sql_class.cc:2615
bool event_notify(struct st_mysql_event_generic *event_data)
Definition: sql_class.cc:3488
bool is_admin_connection() const
Definition: sql_class.h:1648
Protocol * m_protocol
Definition: sql_class.h:1429
void set_current_stmt_binlog_format_row_if_mixed()
Definition: sql_class.h:3535
String m_normalized_query
Definition: sql_class.h:1021
union THD::@181 sys_var_tmp
void init_query_mem_roots()
Initialize memory roots necessary for query processing and (!) pre-allocate memory for it.
Definition: sql_class.cc:1229
void fatal_error()
Mark the current error as fatal.
Definition: sql_class.h:3345
void set_connection_admin(bool connection_admin_flag)
Sets the connection_admin flag atomically for the current session.
Definition: sql_class.h:5078
const LEX_CSTRING & catalog() const
Definition: sql_class.h:1511
void clear_next_event_pos()
Definition: sql_class.cc:2704
void set_server_id(uint32 sid)
Definition: sql_class.h:1794
bool m_secondary_engine_forced
Flag that tells whether secondary storage engine is forced for execution.
Definition: sql_class.h:4845
bool set_db(const LEX_CSTRING &new_db)
Set the current database; use deep copy of C-string.
Definition: sql_class.cc:958
void exit_cond(const PSI_stage_info *stage, const char *src_function, const char *src_file, int src_line) override
End a wait on a condition.
Definition: sql_class.h:3128
bool is_engine_ha_data_detached() const
Definition: sql_class.cc:3109
bool is_attachable_ro_transaction_active() const
Definition: sql_class.h:3512
Sql_condition * raise_condition(uint sql_errno, const char *sqlstate, Sql_condition::enum_severity_level level, const char *msg, bool fatal_error=false)
Raise a generic SQL condition.
Definition: sql_class.cc:1082
PSI_transaction_locker * m_transaction_psi
Current transaction instrumentation.
Definition: sql_class.h:2548
void set_query_id(query_id_t new_query_id)
Assign a new value to thd->query_id.
Definition: sql_class.h:4411
Session_tracker session_tracker
Definition: sql_class.h:4594
const LEX_CSTRING & query() const
Definition: sql_class.h:4300
bool enable_slow_log
Definition: sql_class.h:2859
Internal_error_handler * pop_internal_handler()
Remove the error handler last pushed.
Definition: sql_class.cc:1007
bool audit_plugins_present
Definition: sql_class.h:4960
Event_tracking_data get_event_tracking_data()
Definition: sql_class.h:4939
enum enum_mark_columns mark_used_columns
MARK_COLUMNS_NONE: Means mark_used_columns is not set and no indicator to handler of fields used is s...
Definition: sql_class.h:987
int is_killed() const final
Has the owner thread been killed?
Definition: sql_class.h:3145
struct timeval user_time
Definition: sql_class.h:1656
struct THD_timer_info * timer_cache
After resetting(cancelling) timer, current timer object is cached with timer_cache timer to reuse.
Definition: sql_class.h:1922
bool is_fatal_sub_stmt_error
true if we are in a sub-statement and the current error can not be safely recovered until we left the...
Definition: sql_class.h:2839
bool optimizer_switch_flag(ulonglong flag) const
Tells whether the given optimizer_switch flag is on.
Definition: sql_class.h:1888
Diagnostics_area * m_query_rewrite_plugin_da_ptr
Definition: sql_class.h:4548
void vsyntax_error_at(const POS &location, const char *format, va_list args)
Definition: sql_class.cc:2917
longlong get_row_count_func() const
Definition: sql_class.h:2456
ulong rand_saved_seed2
Definition: sql_class.h:2575
enum THD::Commit_error commit_error
bool m_sql_foreign_keys
Definition: sql_class.h:4996
ulonglong previous_found_rows
Stores the result of the FOUND_ROWS() function.
Definition: sql_class.h:2390
int binlog_flush_pending_rows_event(bool stmt_end)
Definition: sql_class.h:1804
void inc_status_sort_rows(ha_rows count)
Definition: sql_class.cc:2584
enum durability_properties durability_property
Definition: sql_class.h:2769
bool waiting_for_disk_space
Definition: sql_class.h:4783
SSL_handle get_ssl() const
Definition: sql_class.h:1402
bool m_audited
Definition: sql_class.h:2947
void clear_current_stmt_binlog_format_row()
Definition: sql_class.h:3564
void set_user_connect(USER_CONN *uc)
Definition: sql_class.cc:2739
enum enum_server_command get_command() const
Definition: sql_class.h:4278
bool is_regular() const =delete
double m_current_query_cost
Current query cost.
Definition: sql_class.h:1195
bool might_have_commit_order_waiters() const final
Indicates that owner thread might have some commit order (non-MDL) waits for it which are still taken...
Definition: sql_class.h:3146
Discrete_intervals_list auto_inc_intervals_in_cur_stmt_for_binlog
Definition: sql_class.h:2316
bool tx_read_only
Definition: sql_class.h:2665
void syntax_error_at(const POS &location)
Definition: sql_class.h:4602
Prealloced_array< Ha_data, PREALLOC_NUM_HA > ha_data
Definition: sql_class.h:1708
const CHARSET_INFO * db_charset
Definition: sql_class.h:2526
int is_current_stmt_binlog_format_row() const
Determine the binlog format of the current statement.
Definition: sql_class.h:1818
const Gtid_set * get_gtid_next_list_const() const
Return the value of @gtid_next_list: either a Gtid_set or NULL.
Definition: sql_class.h:3597
bool parsing_json_duality_view
Definition: sql_class.h:2865
void set_next_event_pos(const char *_filename, ulonglong _pos)
Definition: sql_class.cc:2688
bool is_mem_cnt_error()
Definition: sql_class.h:4919
void set_plugin(const st_plugin_int *plugin)
Sets the plugin id to the value provided as parameter.
Definition: sql_class.h:4728
const Protocol_classic * get_protocol_classic() const
Asserts that the protocol is of type text or binary and then returns the m_protocol casted to Protoco...
Definition: sql_class.h:1421
String packet
Definition: sql_class.h:1996
void set_tmp_table_seq_id(uint arg)
Definition: sql_class.h:4731
bool stmt_depends_on_first_successful_insert_id_in_prev_stmt
Definition: sql_class.h:2301
void push_internal_handler(Internal_error_handler *handler)
Add an internal error handler to the thread execution context.
Definition: sql_class.cc:986
void copy_status_var(System_status_var *dst_var)
Copy status variables into a structure pointed by the specified pointer and keep track of the pointer...
Definition: sql_class.h:1239
bool is_operating_gtid_table_implicitly
Definition: sql_class.h:2404
void syntax_error()
Definition: sql_class.h:4597
bool handle_condition(uint sql_errno, const char *sqlstate, Sql_condition::enum_severity_level *level, const char *msg)
Handle a sql condition.
Definition: sql_class.cc:994
Event_reference_caching_cache * events_cache_
Definition: sql_class.h:4958
void set_current_stmt_binlog_format_row()
Definition: sql_class.h:3559
Prepared_statement_map stmt_map
All prepared statements of this connection.
Definition: sql_class.h:1333
uint server_status
Definition: sql_class.h:2599
friend void push_warning(THD *thd, Sql_condition::enum_severity_level severity, uint code, const char *message_text)
Push the warning to error list if there is still room in the list.
Definition: sql_error.cc:704
void set_secondary_engine_statement_context(std::unique_ptr< Secondary_engine_statement_context > context)
Definition: sql_class.cc:945
bool bool_value
Definition: sql_class.h:2877
bool is_killable
Definition: sql_class.h:1587
void set_query_for_display(const char *query_arg, size_t query_length_arg)
Set query to be displayed in performance schema (threads table etc.).
Definition: sql_class.h:4325
bool is_system_user()
Returns if the user of the session has the SYSTEM_USER privilege or not.
Definition: sql_class.h:5050
bool is_current_stmt_binlog_log_replica_updates_disabled() const
Determine if binlogging is currently disabled for this session.
Definition: sql_class.cc:3120
void debug_assert_query_locked() const
For safe and protected access to the query string, the following rules should be followed: 1: Only th...
Definition: sql_class.cc:2622
void force_one_auto_inc_interval(ulonglong next_id)
Definition: sql_class.h:2381
uint64_t sql_mode_t
Definition: sql_lexer_thd.h:38
sp_rcontext * sp_runtime_ctx
Current SP-runtime context.
Definition: sql_class.h:2868
void inc_examined_row_count(ha_rows count)
Definition: sql_class.cc:2502
bool is_strict_mode() const
Definition: sql_class.h:3199
bool skip_gtid_rollback
Definition: sql_class.h:4014
Parser_state * m_parser_state
Internal parser state.
Definition: sql_lexer_thd.h:66
void update_charset()
Definition: sql_class.cc:2002
void inc_status_select_full_join()
Definition: sql_class.cc:2528
List< char > * get_binlog_accessed_db_names() const
Definition: sql_class.h:2032
void pop_protocol()
Pops the top protocol of the Protocol stack and sets the previous one as the current protocol.
Definition: sql_class.cc:3345
void enable_mem_cnt()
Definition: sql_class.h:4912
bool m_inside_system_variable_global_update
Flag to indicate this thread is executing sys_var::update for a OPT_GLOBAL variable.
Definition: sql_class.h:4882
bool is_current_stmt_binlog_row_enabled_with_write_set_extraction() const
Determine if binloging is enabled in row format and write set extraction is enabled for this session.
Definition: sql_class.cc:3129
bool gtid_table_persist_requested() const
Definition: sql_class.h:3956
void set_binlog_local_stmt_filter()
Definition: sql_class.h:1907
bool is_cmd_skip_readonly() const
Definition: sql_class.h:2009
thr_lock_type update_lock_default
Type of lock to be used for all DML statements, except INSERT, in cases when lock is not specified ex...
Definition: sql_class.h:1684
enum enum_thread_type system_thread
Definition: sql_class.h:2600
void clear_copy_status_var()
Clear copy of the status variables.
Definition: sql_class.h:1230
void raise_note_printf(uint code,...)
Raise an completion condition (note), with a formatted message.
Definition: sql_class.cc:1056
bool is_mem_cnt_error_issued
Definition: sql_class.h:4918
void reset_skip_transaction_read_only_check()
Definition: sql_class.h:2019
const char * current_key_name
Definition: sql_class.h:4916
ha_rows num_truncated_fields
Definition: sql_class.h:2462
partition_info * work_part_info
Definition: sql_class.h:2919
bool has_incremented_gtid_automatic_count
Flag indicating whether this session incremented the number of sessions with GTID_NEXT set to AUTOMAT...
Definition: sql_class.h:4965
void * fetch_external(unsigned int slot)
Definition: sql_class.cc:3393
bool is_attachable_transaction_active() const
Definition: sql_class.h:3519
enum_thd_life_cycle_stages
Represents life cycle stages of THD instance.
Definition: sql_class.h:2991
@ ACTIVE_AND_CLEAN
Definition: sql_class.h:2993
@ SCHEDULED_FOR_DISPOSAL
Definition: sql_class.h:2994
@ RESOURCES_RELEASED
Definition: sql_class.h:2996
@ DISPOSED
Definition: sql_class.h:2997
@ ACTIVE
Definition: sql_class.h:2992
@ CLEANED_UP
Definition: sql_class.h:2995
System_variables variables
Definition: sql_lexer_thd.h:64
void set_log_reset()
Set when binlog reset operation is started.
Definition: sql_class.h:3900
struct rand_struct rand
Definition: sql_class.h:1176
bool is_slave_error
True if a slave error.
Definition: sql_class.h:2849
List< char > * binlog_accessed_db_names
Definition: sql_class.h:1973
void set_original_commit_timestamp_for_slave_thread()
Copies variables.original_commit_timestamp to ((Slave_worker *)rli_slave)->original_commit_timestamp,...
Definition: sql_class.cc:2712
bool is_stmt_prepare_or_first_stmt_execute() const =delete
binlog_filter_state
Definition: sql_class.h:1892
@ BINLOG_FILTER_CLEAR
Definition: sql_class.h:1894
@ BINLOG_FILTER_UNKNOWN
Definition: sql_class.h:1893
@ BINLOG_FILTER_SET
Definition: sql_class.h:1895
bool is_init_file_system_thread() const
Definition: sql_class.h:2619
void set_secondary_engine_forced(bool forced)
Indicate whether secondary storage engine is forced for this execution.
Definition: sql_class.h:4826
ha_rows m_examined_row_count
Number of rows read and/or evaluated for a statement.
Definition: sql_class.h:2481
bool query_start_usec_used
Definition: sql_class.h:2840
time_t query_start_in_secs() const
Definition: sql_class.h:3211
THD * next_to_commit
Used by MYSQL_BIN_LOG to maintain the commit queue for binary log group commit.
Definition: sql_class.h:2688
void set_transaction(Transaction_ctx *transaction_ctx)
Changes the Transaction_ctx instance within THD-object.
Definition: sql_class.cc:938
enum_thd_life_cycle_stages m_thd_life_cycle_stage
Definition: sql_class.h:2999
mysql_mutex_t LOCK_group_replication_connection_mutex
Definition: sql_class.h:4909
void raise_warning_printf(uint code,...)
Raise a completion condition (warning), with a formatted message.
Definition: sql_class.cc:1036
bool is_classic_protocol() const
Definition: sql_class.cc:3295
Prealloced_array< Binlog_user_var_event *, 2 > user_var_events
Definition: sql_class.h:2681
PSI_stage_key get_current_stage_key() const
Definition: sql_class.h:1563
bool send_result_metadata(const mem_root_deque< Item * > &list, uint flags)
Send name and type of result to client.
Definition: sql_class.cc:2957
bool is_stmt_prepare_or_first_sp_execute() const =delete
void set_protocol_dependent_variables(Protocol *proto)
Sets the THD::variables values that depend on the protocol.
Definition: sql_class.cc:1247
mysql_mutex_t LOCK_thd_protocol
Protects THD::m_protocol when it gets removed in x plugin.
Definition: sql_class.h:1284
bool parsing_system_view
Definition: sql_class.h:2863
Diagnostics_area * m_stmt_da
Definition: sql_class.h:4550
bool is_binlog_applier() const
The function checks whether the thread is processing queries from binlog, as automatically generated ...
Definition: sql_class.h:1108
bool skip_readonly_check
Definition: sql_class.h:1929
const String & rewritten_query() const
Get the rewritten query (with passwords obfuscated etc.) from the THD.
Definition: sql_class.h:4390
void cleanup(void)
Definition: sql_class.cc:1329
cached_properties
Definition: sql_class.h:1084
void set_is_killable(bool is_killable_arg)
Assign a new value to is_killable Protected with the LOCK_thd_data mutex.
Definition: sql_class.h:4432
void inc_status_created_tmp_disk_tables()
Definition: sql_class.cc:2507
const Transaction_ctx * get_transaction() const
Definition: sql_class.h:2180
bool is_connection_admin()
Returns if the user of the session has the CONNECTION_ADMIN privilege or not.
Definition: sql_class.h:5069
void store_cached_properties(cached_properties prop_mask=cached_properties::ALL)
Definition: sql_class.cc:915
mysql::gtid::Tsid owned_tsid
For convenience, this contains the TSID component of the GTID stored in owned_gtid.
Definition: sql_class.h:3858
bool shall_skip_gtid_rollback() const
Invoke the callback functions that determine if GTID rollback shall be skipped, and return true as so...
Definition: sql_class.h:4027
struct timeval start_time
Definition: sql_class.h:1655
binlog_filter_state m_binlog_filter_state
Indicate if the current statement should be discarded instead of written to the binlog.
Definition: sql_class.h:1943
const CHARSET_INFO * charset() const
Definition: sql_class.h:3439
void init(void)
Definition: sql_class.cc:1147
void copy_table_access_properties(THD *thd)
Copy session properties that affect table access from the parent session to the current session.
Definition: sql_class.cc:931
bool is_secondary_storage_engine_eligible() const
Checks if queries in this session can use a secondary storage engine for execution.
Definition: sql_class.cc:3225
void set_status_no_good_index_used()
Definition: sql_class.cc:2608
std::unique_ptr< LEX > main_lex
The lex to hold the parsed tree of conventional (non-prepared) queries.
Definition: sql_class.h:1005
const char * where
Definition: sql_class.h:1570
LEX_CSTRING get_invoker_host() const
Definition: sql_class.h:4527
ha_rows get_sent_row_count() const
Definition: sql_class.h:2502
bool charset_is_character_set_filesystem
Definition: sql_class.h:2858
void reset_copy_status_var()
Copy status variables into a structure pointed by the specified pointer passed into copy_status_var m...
Definition: sql_class.h:1248
bool safe_to_display() const
Definition: sql_class.h:4348
void reset_first_successful_insert_id()
Definition: sql_class.h:2368
void set_time()
Definition: sql_class.cc:3352
bool is_fsp_truncate_mode() const
Definition: sql_class.h:3218
Access_bitmask want_privilege
Used by Item::check_column_privileges() to tell which privileges to check for.
Definition: sql_class.h:996
uint32 file_id
Definition: sql_class.h:1652
Internal_error_handler * m_internal_handler
The current internal error handler for this thread, or NULL.
Definition: sql_class.h:4534
void push_diagnostics_area(Diagnostics_area *da, bool copy_conditions=true)
Push the given Diagnostics Area on top of the stack, making it the new first Diagnostics Area.
Definition: sql_class.h:3408
void disable_low_level_commit_ordering()
Enables ordering in ha_commit_low.
Definition: sql_class.cc:3139
Plugin_array audit_class_plugins
Array of active audit plugins which have been used by this THD.
Definition: sql_class.h:2926
const NET * get_net() const
Definition: sql_class.h:1998
bool transaction_rollback_request
Set by a storage engine to request the entire transaction (that possibly spans multiple engines) to r...
Definition: sql_class.h:2827
void set_active_vio(Vio *vio)
Definition: sql_class.h:3046
void release_external_store()
Definition: sql_class.cc:3777
uint16 peer_port
Definition: sql_class.h:1654
Secondary_engine_optimization secondary_engine_optimization() const
Can secondary storage engines be used for query execution in this session?
Definition: sql_class.h:4812
bool binlog_need_explicit_defaults_ts
The member is served for marking a query that CREATEs or ALTERs a table declared with a TIMESTAMP col...
Definition: sql_class.h:2697
void set_skip_transaction_read_only_check()
Definition: sql_class.h:2006
uint in_sub_stmt
Definition: sql_class.h:1693
void inc_lock_usec(ulonglong usec)
Definition: sql_class.cc:3365
void disable_mem_cnt()
Definition: sql_class.h:4913
void rollback_item_tree_changes()
Restore locations set by calls to nocheck_register_item_tree_change().
Definition: sql_class.cc:2117
bool se_persists_gtid() const
Definition: sql_class.h:3924
char * m_trans_fixed_log_file
Definition: sql_class.h:1990
bool is_low_level_commit_ordering_enabled() const
Obtains flag indicating whether additional ordering in the ha_commit_low function is enabled.
Definition: sql_class.cc:3144
bool unioned_events_trans
Definition: sql_class.h:2901
char * strmake(const char *str, size_t size) const
Definition: sql_lexer_thd.h:52
Secondary_engine_statement_context * secondary_engine_statement_context()
Definition: sql_class.h:1126
bool copy_db_to(char const **p_db, size_t *p_db_length) const
Definition: sql_class.h:4125
void increment_con_per_hour_counter()
Definition: sql_class.cc:2758
std::atomic< bool > m_cached_is_connection_alive
Keep cached values of "connection alive" and "rw status".
Definition: sql_class.h:1324
uint get_tmp_table_seq_id()
Definition: sql_class.h:4730
const Diagnostics_area * get_stacked_da() const
Returns the second Diagnostics Area for the current statement.
Definition: sql_class.h:3369
void mark_transaction_to_rollback(bool all)
Mark transaction to rollback and mark error as fatal to a sub-statement.
Definition: sql_class.cc:2678
Attachable_trx * m_attachable_trx
Definition: sql_class.h:2175
void raise_warning(uint code)
Raise a completion condition (warning).
Definition: sql_class.cc:1031
enum_check_fields check_for_truncated_fields
Definition: sql_class.h:2678
uint get_binlog_table_maps() const
Definition: sql_class.h:2026
PSI_idle_locker * m_idle_psi
Idle instrumentation.
Definition: sql_class.h:2555
Diagnostics_area * get_parser_da()
Returns thread-local Diagnostics Area for parsing.
Definition: sql_class.h:3382
void set_time(const struct timeval *t)
Definition: sql_class.h:3214
collation_unordered_map< std::string, unique_ptr_with_deleter< user_var_entry > > user_vars
Hash for user variables.
Definition: sql_class.h:1175
bool sql_parser()
Call parser to transform statement into a parse tree.
Definition: sql_class.cc:3185
bool rand_used
Definition: sql_class.h:2841
NET net
Definition: sql_class.h:1995
ulonglong m_current_query_partial_plans
Current query partial plans.
Definition: sql_class.h:1201
void set_sql_foreign_keys(bool flag)
Definition: sql_class.h:5002
sp_cache * sp_func_cache
Definition: sql_class.h:2870
Cost_model_server m_cost_model_hypergraph
Definition: sql_class.h:4579
int tx_priority
Definition: sql_class.h:2671
uint32_t m_fk_cascade_chain_tables
Member to store count of tables in foreign key cascade chains.
Definition: sql_class.h:4998
std::unique_ptr< Transaction_ctx > m_transaction
Definition: sql_class.h:2045
table_map table_map_for_update
Definition: sql_class.h:2243
void cleanup_after_parse_error()
Restore session state in case of parse error.
Definition: sql_class.cc:3271
handlerton * m_eligible_secondary_engine_handlerton
Definition: sql_class.h:1080
mysql_mutex_t LOCK_thd_sysvar
Protects THD::variables while being updated.
Definition: sql_class.h:1275
ulong ulong_value
Definition: sql_class.h:2879
void update_previous_found_rows()
Definition: sql_class.h:3240
void raise_note(uint code)
Raise a completion condition (note), with a fixed message.
Definition: sql_class.cc:1048
void awake(THD::killed_state state_to_set)
Awake a thread.
Definition: sql_class.cc:1608
void change_item_tree(Item **place, Item *new_value)
Record a transient change to a pointer to an Item within another Item.
Definition: sql_class.h:3445
void mark_plugin_fake_ddl(bool flag)
Definition: sql_class.h:4735
mysql_mutex_t LOCK_thd_data
Protects THD data accessed from other threads.
Definition: sql_class.h:1263
bool convert_string(LEX_STRING *to, const CHARSET_INFO *to_cs, const char *from, size_t from_length, const CHARSET_INFO *from_cs, bool report_error=false)
void cleanup_after_query()
Definition: sql_class.cc:1868
void restore_globals()
Definition: sql_class.cc:1838
void inc_status_sort_range()
Definition: sql_class.cc:2576
query_id_t first_query_id
Definition: sql_class.h:2907
Ha_data * get_ha_data(int slot)
Retrieve Ha_data for a given slot.
Definition: sql_class.h:1714
Vio * active_vio
Definition: sql_class.h:2195
uint tmp_table_seq_id
Sequential number of internal tmp table created in the statement.
Definition: sql_class.h:4760
MEM_ROOT * user_var_events_alloc
Definition: sql_class.h:2682
THD(bool enable_plugins=true)
Definition: sql_class.cc:675
uint32 unmasked_server_id
Definition: sql_class.h:1650
const char * m_proc_info
Definition: sql_class.h:1530
void push_protocol(Protocol *protocol)
Inserts the new protocol at the top of the protocol stack, and make it the current protocol for this ...
Definition: sql_class.cc:3337
void end_attachable_transaction()
End an active attachable transaction.
Definition: sql_class.cc:2333
bool is_secondary_engine_forced() const
Definition: sql_class.h:4830
const char * proc_info() const
Definition: sql_class.h:1548
bool is_attachable_rw_transaction_active() const
Definition: sql_class.h:3526
void clear_log_reset()
Cleared after flushing SE logs during binlog reset.
Definition: sql_class.h:3903
const st_plugin_int * get_plugin() const
Returns the plugin, the thd belongs to.
Definition: sql_class.h:4723
enum enum_server_command m_command
Type of current query: COM_STMT_PREPARE, COM_QUERY, etc.
Definition: sql_class.h:1641
void reset_db(const LEX_CSTRING &new_db)
Set the current database; use shallow copy of C-string.
Definition: sql_class.h:4113
Se_GTID_flagset m_se_gtid_flags
Flags for SE GTID persistence.
Definition: sql_class.h:3881
Gtid_set * get_gtid_next_list()
Return the value of @gtid_next_list: either a Gtid_set or NULL.
Definition: sql_class.h:3590
mysql_mutex_t LOCK_current_cond
Mutex protecting access to current_mutex and current_cond.
Definition: sql_class.h:1591
void set_secondary_engine_optimization(Secondary_engine_optimization state)
Enables or disables use of secondary storage engines in this session.
Definition: sql_class.h:4802
Transaction_ctx * get_transaction()
Definition: sql_class.h:2178
bool is_initialize_system_thread() const
Definition: sql_class.h:2614
ulong rand_saved_seed1
Definition: sql_class.h:2575
sp_cache * sp_proc_cache
Definition: sql_class.h:2869
Item_change_list change_list
This is used to track transient changes to items during optimization of a prepared statement/stored p...
Definition: sql_class.h:2223
bool in_active_multi_stmt_transaction() const
true if the session is in a multi-statement transaction mode (
Definition: sql_class.h:3305
void refresh_reference_caches()
Definition: sql_class.h:4947
bool check_clone_vio()
Check if clone network Vio is active.
Definition: sql_class.h:3077
std::unique_ptr< PROFILING > profiling
Definition: sql_class.h:2528
void reset_current_stmt_binlog_format_row()
Definition: sql_class.h:3569
bool m_disable_password_validation
Definition: sql_class.h:1393
bool in_multi_stmt_transaction_mode() const
Returns true if session is in a multi-statement transaction mode.
Definition: sql_class.h:3267
void begin_attachable_ro_transaction()
Start a read-only attachable transaction.
Definition: sql_class.cc:2329
uint get_protocol_rw_status()
Return the cached protocol rw status.
Definition: sql_class.cc:3324
bool do_union
Definition: sql_class.h:2890
const LEX_CSTRING & db() const
Definition: sql_class.h:4079
const Internal_error_handler * get_internal_handler() const
Definition: sql_class.h:4177
ulonglong read_first_successful_insert_id_in_prev_stmt(void)
Definition: sql_class.h:2359
uint32 binlog_unsafe_warning_flags
Bit field for the state of binlog warnings.
Definition: sql_class.h:1963
void raise_error(uint code)
Raise an exception condition.
Definition: sql_class.cc:1014
std::atomic< killed_state > killed
Definition: sql_class.h:2784
ulonglong start_utime
Query start time, expressed in microseconds.
Definition: sql_class.h:1660
Security_context * m_security_ctx
Definition: sql_class.h:1365
bool is_stmt_prepare() const =delete
void restore_ha_data(const Prealloced_array< Ha_data, PREALLOC_NUM_HA > &backup)
Restore ha_data from the provided backup copy.
Definition: sql_class.h:1733
bool unioned_events
Definition: sql_class.h:2895
bool m_is_plugin_fake_ddl
Creating or dropping plugin native table through a plugin service.
Definition: sql_class.h:4753
void set_sent_row_count(ha_rows count)
Definition: sql_class.cc:2492
uint query_name_consts
number of name_const() substitutions, see sp_head.cc:subst_spvars()
Definition: sql_class.h:2873
NET_SERVER m_net_server_extension
Additional network instrumentation for the server only.
Definition: sql_class.h:1166
void inc_status_count_hit_tmp_table_size()
Definition: sql_class.cc:2523
ulonglong conn_mem_alloc_number
Definition: sql_class.h:4917
String m_rewritten_query
In some cases, we may want to modify the query (i.e.
Definition: sql_class.h:1071
bool m_server_idle
True if the server code is IDLE for this connection.
Definition: sql_class.h:2561
Relay_log_info * rli_fake
Definition: sql_class.h:1095
mysql_mutex_t LOCK_thd_security_ctx
Protects THD::m_security_ctx from inspection (e.g.
Definition: sql_class.h:1290
void backup_ha_data(Prealloced_array< Ha_data, PREALLOC_NUM_HA > *backup)
Copy ha_data into the provided argument.
Definition: sql_class.h:1719
uint32 server_id
Definition: sql_class.h:1651
bool is_fatal_error() const
Definition: sql_class.h:3346
Transactional_ddl_context m_transactional_ddl
Definition: sql_class.h:4867
void set_gtid_table_persist_requested()
Mark GTID table persistence as requested for the currently owned GTID.
Definition: sql_class.h:3950
bool duplicate_slave_id
This is only used by master dump threads.
Definition: sql_class.h:4707
bool charset_is_system_charset
is set if a statement accesses a temporary table created through CREATE TEMPORARY TABLE.
Definition: sql_class.h:2857
void reset_rewritten_query()
Reset thd->m_rewritten_query.
Definition: sql_class.h:4400
void release_resources()
Release most resources, prior to THD destruction.
Definition: sql_class.cc:1452
Security_context * security_context() const
Definition: sql_class.h:1367
bool check_event_subscribers(Event_tracking_class event, unsigned long subevent, bool check_audited)
Check if there are event subscribers for the event.
Definition: sql_class.cc:3410
size_t get_temptable_count() const
Return currently owned temptable count.
Definition: sql_class.h:4976
void restore_backup_open_tables_state(Open_tables_backup *backup)
Definition: sql_class.cc:2315
void pop_lock_usec(ulonglong top)
Definition: sql_class.h:1676
void enter_locked_tables_mode(enum_locked_tables_mode mode_arg)
Definition: sql_class.h:4438
bool time_zone_used
Definition: sql_class.h:2841
ulonglong ulonglong_value
Definition: sql_class.h:2880
void enter_stage(const PSI_stage_info *stage, PSI_stage_info *old_stage, const char *calling_func, const char *calling_file, const unsigned int calling_line) SUPPRESS_TSAN
Definition: sql_class.cc:587
uint binlog_table_maps
Definition: sql_class.h:1969
void inc_status_select_range_check()
Definition: sql_class.cc:2552
int send_explain_fields(Query_result *result)
Definition: sql_class.cc:2014
void clear_error()
Clear the current error, if any.
Definition: sql_class.h:3325
bool is_bootstrap_system_thread() const
Definition: sql_class.h:2625
void binlog_invoker()
Definition: sql_class.h:4517
bool is_one_phase_commit()
Definition: sql_class.cc:3215
void set_gtid_persisted_by_se()
Set by SE when it guarantees GTID persistence.
Definition: sql_class.h:3909
void inc_status_sort_merge_passes()
Definition: sql_class.cc:2568
void mark_as_srv_session()
Definition: sql_class.h:4717
MEM_ROOT main_mem_root
This memory root is used for two purposes:
Definition: sql_class.h:4544
struct System_status_var status_var
Definition: sql_class.h:1178
bool m_enable_plugins
Definition: sql_class.h:2939
struct System_status_var * copy_status_var_ptr
Definition: sql_class.h:1179
void clear_owned_gtids()
Definition: sql_class.h:3977
killed_state
Definition: sql_class.h:2777
@ KILL_QUERY
Definition: sql_class.h:2780
@ KILL_CONNECTION
Definition: sql_class.h:2779
@ KILLED_NO_VALUE
Definition: sql_class.h:2782
@ KILL_TIMEOUT
Definition: sql_class.h:2781
@ NOT_KILLED
Definition: sql_class.h:2778
void set_eligible_secondary_engine_handlerton(handlerton *hton)
Definition: sql_class.cc:950
void cleanup_after_statement_execution()
cleanup all secondary engine relevant members after statement execution.
Definition: sql_class.cc:954
std::vector< char > m_connection_attributes
Session's connection attributes for the connected client.
Definition: sql_class.h:1189
Locked_tables_list locked_tables_list
Definition: sql_class.h:2917
void get_definer(LEX_USER *definer)
Definition: sql_class.cc:2661
const char * m_trans_log_file
The binary log position of the transaction.
Definition: sql_class.h:1989
bool is_commit_in_middle_of_statement
Definition: sql_class.h:4071
Diagnostics_area * get_stmt_da()
Returns first Diagnostics Area for the current statement.
Definition: sql_class.h:3363
mysql_cond_t COND_group_replication_connection_cond_var
Definition: sql_class.h:4910
std::atomic< bool > m_is_connection_admin
Flag that indicates if the user of current session has CONNECTION_ADMIN privilege.
Definition: sql_class.h:4857
void inc_status_select_full_range_join()
Definition: sql_class.cc:2536
Diagnostics_area m_parser_da
cf.
Definition: sql_class.h:4546
void notify_shared_lock(MDL_context_owner *ctx_in_use, bool needs_thr_lock_abort) override
A callback to the server internals that is used to address special cases of the locking protocol.
Definition: sql_class.cc:1780
const USER_CONN * get_user_connect() const
Definition: sql_class.h:2488
void shutdown_clone_vio()
Shutdown clone vio, if active.
Definition: sql_class.cc:2075
void pin_gtid()
Defer freeing owned GTID and TSID till unpinned.
Definition: sql_class.h:3884
PSI_idle_locker_state m_idle_state
Idle instrumentation state.
Definition: sql_class.h:2558
bool is_plugin_fake_ddl() const
Definition: sql_class.h:4734
bool arg_of_last_insert_id_function
Definition: sql_class.h:2246
void set_skip_readonly_check()
Definition: sql_class.h:2000
Se_GTID_flag
SE GTID persistence flag types.
Definition: sql_class.h:3861
@ SE_GTID_PERSIST_EXPLICIT
Explicit request for SE to persist GTID for current transaction.
Definition: sql_class.h:3871
@ SE_GTID_TABLE_PERSIST_REQUESTED
GTID table persistence was requested for current ownership.
Definition: sql_class.h:3873
@ SE_GTID_RESET_LOG
If RESET log in progress.
Definition: sql_class.h:3869
@ SE_GTID_CLEANUP
Cleanup GTID during unpin.
Definition: sql_class.h:3865
@ SE_GTID_PERSIST
SE would persist GTID for current transaction.
Definition: sql_class.h:3867
@ SE_GTID_MAX
Max element holding the biset size.
Definition: sql_class.h:3875
@ SE_GTID_PIN
Pin owned GTID.
Definition: sql_class.h:3863
bool se_persists_gtid_explicit() const
Definition: sql_class.h:3934
bool for_debug_only_is_set_persist_options
Definition: sql_class.h:1278
void rpl_reattach_engine_ha_data()
When the thread is a binlog or slave applier it reattaches the engine ha_data associated with it and ...
Definition: sql_class.cc:3099
bool release_resources_done() const
Definition: sql_class.cc:1426
bool is_operating_substatement_implicitly
Definition: sql_class.h:2421
void update_slow_query_status()
Evaluate the current time, and if it exceeds the long-query-time setting, mark the query as slow.
Definition: sql_class.cc:3380
const char * m_stack_base
Definition: sql_class.h:1348
uint tmp_table
Definition: sql_class.h:2598
void call_actions_before_gtid_state_update(bool is_commit)
Execute and remove registered before-GTID-state-update actions.
Definition: sql_class.h:4056
Commit_error
Definition: sql_class.h:2756
@ CE_NONE
Definition: sql_class.h:2757
@ CE_COMMIT_ERROR
Definition: sql_class.h:2761
@ CE_ERROR_COUNT
Definition: sql_class.h:2762
@ CE_SYNC_ERROR
Definition: sql_class.h:2760
@ CE_FLUSH_ERROR
Definition: sql_class.h:2758
@ CE_FLUSH_GNO_EXHAUSTED_ERROR
Definition: sql_class.h:2759
Security_context m_main_security_ctx
Definition: sql_class.h:1364
malloc_unordered_map< std::string, User_level_lock * > ull_hash
Definition: sql_class.h:1582
static const char *const DEFAULT_WHERE
Definition: sql_class.h:1163
void reset_skip_readonly_check()
Definition: sql_class.h:2014
Global_read_lock global_read_lock
Definition: sql_class.h:2193
void inc_sent_row_count(ha_rows count)
Definition: sql_class.cc:2497
void increment_temptable_count()
Increment the owned temptable counter.
Definition: sql_class.h:4972
bool thread_specific_used
is set if some thread specific value(s) used in a statement.
Definition: sql_class.h:2852
void set_open_tables(TABLE *open_tables_arg)
Assign a new value to open_tables.
Definition: sql_class.h:4422
bool is_cmd_skip_transaction_read_only() const
Definition: sql_class.h:2011
bool owned_gtid_is_empty()
Definition: sql_class.h:3998
resourcegroups::Resource_group_ctx m_resource_group_ctx
Resource group context indicating the current resource group and if there are any warnings related to...
Definition: sql_class.h:1047
enum_reset_lex
Definition: sql_class.h:2112
@ DO_NOT_RESET_LEX
Definition: sql_class.h:2112
@ RESET_LEX
Definition: sql_class.h:2112
uchar password
Definition: sql_class.h:2809
const Cost_model_server * cost_model() const
Retrieve the optimizer cost model for this connection.
Definition: sql_class.cc:3871
void set_proc_info(const char *proc_info)
Definition: sql_class.h:1562
handlerton * eligible_secondary_engine_handlerton() const
Definition: sql_class.h:1132
void start_disposal()
Set THD in ACTIVE life stage to disposal stage.
Definition: sql_class.cc:1439
uint32_t fk_cascade_chain_tables()
Definition: sql_class.h:5004
std::vector< std::function< void(bool)> > m_actions_before_gtid_state_update
Actions to execute before owned GTID state is externalized.
Definition: sql_class.h:4021
Diagnostics_area * get_query_rewrite_plugin_da()
Returns thread-local Diagnostics Area to be used by query rewrite plugins.
Definition: sql_class.h:3393
bool in_lock_tables
Definition: sql_class.h:2842
sql_digest_state m_digest_state
Top level statement digest.
Definition: sql_class.h:2538
ulonglong found_rows() const
Definition: sql_class.h:3232
Definition: table.h:2958
Definition: sql_class.h:258
void restore_mode()
Restore original memory counter mode.
Definition: sql_class.h:290
void no_error_mode()
Set NO ERROR memory counter mode.
Definition: sql_class.h:294
ulonglong glob_mem_counter
Definition: sql_class.h:265
void set_orig_mode(uint mode_arg)
Function sets original memory counter mode.
Definition: sql_class.h:308
void set_curr_mode(uint mode_arg)
Function sets current memory counter mode.
Definition: sql_class.h:302
void flush()
Function flushes memory counters before deleting the memory counter object.
Definition: sql_class.cc:334
void free_cnt(size_t size)
Decrease memory counter at 'free' operation.
Definition: sql_class.cc:259
bool is_error() const
Check if memory counter error is issued.
Definition: sql_class.h:314
ulonglong mem_counter
Definition: sql_class.h:263
void set_thd_error_status() const
Set THD error status using memory counter diagnostics area.
Definition: sql_class.cc:399
THD * m_thd
Definition: sql_class.h:261
int reset()
Function resets current memory counter mode and adjusts global memory counter according to thread mem...
Definition: sql_class.cc:274
Diagnostics_area m_da
Definition: sql_class.h:262
bool is_error_mode() const
Check if memory counter is in error mode.
Definition: sql_class.h:324
~Thd_mem_cnt()
Definition: sql_class.h:275
ulonglong max_conn_mem
Definition: sql_class.h:264
bool m_enabled
Definition: sql_class.h:260
void alloc_cnt(size_t size)
Increase memory counter at 'alloc' operation.
Definition: sql_class.cc:170
void set_thd(THD *thd)
Definition: sql_class.h:279
uint orig_mode
Definition: sql_class.h:268
int generate_error(int err_no, ulonglong mem_limit, ulonglong mem_size)
Generate OOM error and set therad to KILL_CONNECTION state.
Definition: sql_class.cc:355
void disable()
Definition: sql_class.cc:157
uint curr_mode
Definition: sql_class.h:267
bool is_error_log_mode() const
Check if memory counter is in error log mode.
Definition: sql_class.h:330
bool is_connection_stage
Definition: sql_class.h:270
void enable()
Definition: sql_class.h:280
Thd_mem_cnt()
Definition: sql_class.h:274
This class represents abstract time zone and provides basic interface for MYSQL_TIME <-> my_time_t co...
Definition: tztime.h:49
Definition: transaction_info.h:67
This class keeps the context of transactional DDL statements.
Definition: sql_class.h:893
void post_ddl()
End the transactional context created by calling post ddl hook for engine on which table is being cre...
Definition: sql_class.cc:3841
dd::String_type m_tablename
Definition: sql_class.h:922
void init(dd::String_type db, dd::String_type tablename, const handlerton *hton)
Initialize the transactional ddl context when executing CREATE TABLE ... SELECT command with engine w...
Definition: sql_class.cc:3791
~Transactional_ddl_context()
Definition: sql_class.h:899
THD * m_thd
Definition: sql_class.h:915
Transactional_ddl_context(THD *thd)
Definition: sql_class.h:895
dd::String_type m_db
Definition: sql_class.h:921
bool inited()
Definition: sql_class.h:907
const handlerton * m_hton
Definition: sql_class.h:918
void rollback()
Remove the table share used while creating the table, if the transaction is being rolledback.
Definition: sql_class.cc:3809
@ XA_NOTR
Definition: xa.h:298
std::unordered_map, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:219
RAII class for immunizing the THD from kill operations.
Definition: dd_kill_immunizer.h:46
Definition: dictionary_client.h:166
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4753
std::unordered_map, but with my_malloc, so that you can track the memory used using PSI memory keys.
Definition: map_helpers.h:157
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:172
Represents Transaction Source Identifier which is composed of source UUID and transaction tag.
Definition: tsid.h:44
void clear()
Clears data - uuid and tag.
Definition: tsid.cpp:127
Definition: partition_info.h:209
Definition: sp_cache.cc:42
Definition: sp_rcontext.h:77
To be used for pool-of-threads (implemented differently on various OSs)
Definition: sql_class.h:215
void * data
Definition: sql_class.h:217
~thd_scheduler()=default
thd_scheduler()
Definition: sql_class.h:219
Definition: item_func.h:3167
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:50
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:57
#define PSI_THREAD_CALL(M)
Definition: psi_thread.h:36
static char buf[MAX_BUF]
Definition: conf_to_src.cc:74
#define U
Definition: ctype-tis620.cc:73
thread_local THD * current_thd
Definition: current_thd.cc:26
durability_properties
Definition: dur_prop.h:31
static bool report_error(THD *thd, int error_code, Sql_condition::enum_severity_level level, Args... args)
Definition: error_handler.cc:291
Rows_log_event * binlog_get_pending_rows_event(bool is_transactional) const
This function retrieves a pending row event from a cache which is specified through the parameter is_...
Definition: binlog.cc:8287
bool is_ddl_gtid_compatible()
Definition: binlog.cc:9432
bool is_binlog_cache_empty(bool is_transactional) const
Return true if the statement/transaction cache is currently empty, false otherwise.
Definition: binlog.cc:8014
int binlog_write_row(TABLE *table, bool is_transactional, const uchar *new_data, const unsigned char *extra_row_info)
Definition: binlog.cc:9888
int decide_logging_format(Table_ref *tables)
Decide on logging format to use for the statement and issue errors or warnings as needed.
Definition: binlog.cc:8738
void check_and_emit_warning_for_non_composable_engines(Table_ref *table_ref)
Iterates over the table and call check_and_registered_engine and emits error for non-composable engin...
Definition: binlog.cc:8576
bool binlog_configure_trx_cache_size(ulong new_size)
Configure size of binlog transaction cache.
Definition: binlog.cc:8078
int binlog_update_row(TABLE *table, bool is_transactional, const uchar *old_data, const uchar *new_data, const uchar *extra_row_info)
Definition: binlog.cc:9913
Rows_log_event * binlog_prepare_pending_rows_event(TABLE *table, uint32 serv_id, size_t needed, bool is_transactional, const unsigned char *extra_row_info, uint32 source_part_id=INT_MAX)
Definition: binlog.cc:9592
int binlog_delete_row(TABLE *table, bool is_transactional, const uchar *old_data, const unsigned char *extra_row_info)
Definition: binlog.cc:9986
bool is_dml_gtid_compatible(bool some_transactional_table, bool some_non_transactional_table, bool non_transactional_tables_are_tmp)
is_dml_gtid_compatible() and is_ddl_gtid_compatible() check if the statement that is about to be proc...
Definition: binlog.cc:9514
int binlog_query(enum_binlog_query_type qtype, const char *query, size_t query_len, bool is_trans, bool direct, bool suppress_use, int errcode)
Log the current query.
Definition: binlog.cc:10300
void add_to_binlog_accessed_dbs(const char *db)
Definition: binlog.cc:8315
void issue_unsafe_warnings()
Auxiliary method used by binlog_query() to raise warnings.
Definition: binlog.cc:10242
int binlog_write_table_map(TABLE *table, bool is_transactional, bool binlog_rows_query)
This function writes a table map to the binary log.
Definition: binlog.cc:8242
int binlog_setup_trx_data()
Definition: binlog.cc:8039
const uint32_t UNDEFINED_SERVER_VERSION
Definition: binlog_event.h:161
void unlock_global_read_lock(THD *thd)
Unlock global read lock.
Definition: lock.cc:1089
bool lock_global_read_lock(THD *thd)
Take global read lock, wait if there is protection against lock.
Definition: lock.cc:1049
bool make_global_read_lock_block_commit(THD *thd)
Make global read lock also block commits.
Definition: lock.cc:1118
void set_explicit_lock_duration(THD *thd)
Set explicit duration for metadata locks which are used to implement GRL.
Definition: lock.cc:1146
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:217
char * strmake_root(MEM_ROOT *root, const char *str, size_t len)
Definition: my_alloc.cc:287
char * strdup_root(MEM_ROOT *root, const char *str)
Definition: my_alloc.cc:279
void * memdup_root(MEM_ROOT *root, const void *str, size_t len)
Definition: my_alloc.cc:296
MYSQL_PLUGIN_IMPORT CHARSET_INFO * default_charset_info
Definition: charset.cc:193
size_t dirname_length(const char *name)
Get the string length of the directory part of name, including the last FN_LIBCHAR.
Definition: mf_dirname.cc:62
ALWAYS_INLINE const char * resolve_stack_pointer(const void *local_marker)
Resolve a stack address suitable for stack-usage accounting.
Definition: my_sys.h:102
void reset_for_next_command()
Definition: sql_parse.cc:5201
struct PSI_idle_locker PSI_idle_locker
Definition: psi_idle_bits.h:41
unsigned int PSI_stage_key
Instrumented stage key.
Definition: psi_stage_bits.h:43
struct PSI_statement_locker PSI_statement_locker
Definition: psi_statement_bits.h:105
struct PSI_thread PSI_thread
Definition: psi_thread_bits.h:82
struct PSI_transaction_locker PSI_transaction_locker
Definition: psi_transaction_bits.h:41
static constexpr unsigned PSI_INSTRUMENT_ME
Definition: psi_bits.h:43
#define mysql_mutex_assert_not_owner(M)
Wrapper, to use safe_mutex_assert_not_owner with instrumented mutexes.
Definition: mysql_mutex.h:126
#define mysql_mutex_assert_owner(M)
Wrapper, to use safe_mutex_assert_owner with instrumented mutexes.
Definition: mysql_mutex.h:112
#define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2)
Definition: mysql_statement.h:115
#define MYSQL_SET_STATEMENT_QUERY_ID(LOCKER, P1)
Definition: mysql_statement.h:124
static int flags[50]
Definition: hp_test1.cc:40
static int flag
Definition: hp_test1.cc:40
Instrumentation helpers for mysys threads.
#define T
Definition: jit_executor_value.cc:373
struct MYSQL_LEX_CSTRING LEX_CSTRING
Definition: lex_string.h:43
enum_locked_tables_mode
Type of locked tables mode.
Definition: locked_tables_list.h:47
@ LTM_LOCK_TABLES
Definition: locked_tables_list.h:49
@ LTM_PRELOCKED_UNDER_LOCK_TABLES
Definition: locked_tables_list.h:51
@ LTM_NONE
Definition: locked_tables_list.h:48
A better implementation of the UNIX ctype(3) library.
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_latin1
Definition: ctype-latin1.cc:365
MYSQL_PLUGIN_IMPORT CHARSET_INFO * system_charset_info
Definition: mysqld.cc:1582
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
This file includes constants used by all storage engines.
my_off_t ha_rows
Definition: my_base.h:1229
enum_server_command
A list of all MySQL protocol commands.
Definition: my_command.h:48
Header for compiler-dependent features.
#define SUPPRESS_TSAN
Definition: my_compiler.h:130
#define DBUG_EXECUTE_IF(keyword, a1)
Definition: my_dbug.h:171
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:181
#define DBUG_TRACE
Definition: my_dbug.h:146
Some integer typedefs for easier portability.
int myf
Definition: my_inttypes.h:94
unsigned long long int ulonglong
Definition: my_inttypes.h:56
ulonglong my_off_t
Definition: my_inttypes.h:72
unsigned char uchar
Definition: my_inttypes.h:52
long long int longlong
Definition: my_inttypes.h:55
#define MYF(v)
Definition: my_inttypes.h:97
uint16_t uint16
Definition: my_inttypes.h:65
uint32_t uint32
Definition: my_inttypes.h:67
Common #defines and includes for file and socket I/O.
#define FN_REFLEN
Definition: my_io.h:87
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
enum_sql_command
Definition: my_sqlcommand.h:46
@ SQLCOM_END
Definition: my_sqlcommand.h:216
Common header for many mysys elements.
uint64_t table_map
Definition: my_table_map.h:30
Types to make different thread packages compatible.
pthread_t my_thread_t
Definition: my_thread_bits.h:48
uint32 my_thread_id
Definition: my_thread_local.h:34
static int count
Definition: myisam_ftdump.cc:45
static bool backup
Definition: myisampack.cc:198
unsigned int STDCALL mysql_errno(MYSQL *mysql)
Definition: client.cc:9483
@ SERVER_STATUS_IN_TRANS
Is raised when a multi-statement transaction has been started, either explicitly, by means of BEGIN o...
Definition: mysql_com.h:823
#define SCRAMBLE_LENGTH
Length of random string sent by server on handshake; this is also length of obfuscated password,...
Definition: mysql_com.h:128
Definitions private to the server, used in the networking layer to notify specific events.
Instrumentation helpers for conditions.
ABI for instrumented mutexes.
Instrumentation helpers for statements.
char * user
Definition: mysqladmin.cc:67
const char * host
Definition: mysqladmin.cc:66
void error(const char *format,...)
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1077
std::string format(const routing_guidelines::Session_info &session_info, bool extended_session_info)
Definition: dest_metadata_cache.cc:170
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
Definition: buf0block_hint.cc:30
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:44
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:51
Definition: os0file.h:89
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
bool empty(const Histogram &histogram)
Return true if 'histogram' was built on an empty table.
Definition: histogram.h:694
static thread_local uint next_id
Definition: content_tree.cc:217
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:79
size_t size(const char *const c)
Definition: base64.h:46
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2724
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2732
std::list< T, ut::allocator< T > > list
Specialization of list which uses ut_allocator.
Definition: ut0new.h:2728
This contains the declaration of class Opt_trace_context, which is needed to declare THD.
Performance schema instrumentation (declarations).
Include file for Sun RPC to compile out of the box.
Instrumentation helpers for mutexes.
Performance schema instrumentation interface.
Performance schema instrumentation interface.
PSI_memory_key key_memory_THD_handler_tables_hash
Definition: psi_memory_key.cc:94
PSI_memory_key key_memory_user_var_entry
Definition: psi_memory_key.cc:149
PSI_memory_key key_memory_User_level_lock
Definition: psi_memory_key.cc:98
Performance schema instrumentation interface.
Performance schema instrumentation interface.
Performance schema instrumentation interface.
Performance schema instrumentation interface.
#define OPTION_NOT_AUTOCOMMIT
Definition: query_options.h:74
#define OPTION_USE_SQL_FOREIGN_KEY_HANDLING
Definition: query_options.h:134
#define OPTION_BEGIN
Definition: query_options.h:75
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42
required uint64 version
Definition: replication_group_member_actions.proto:41
repeated Action action
Definition: replication_group_member_actions.proto:43
required string event
Definition: replication_group_member_actions.proto:32
enum_check_fields
Definition: field.h:169
enum_tx_isolation
Definition: handler.h:3340
ha_notification_type
Definition: handler.h:964
char empty_c_string[1]
Definition: sql_class.cc:132
PSI_thread * thd_get_psi(THD *thd)
Get reference to Performance Schema object for THD object.
Definition: sql_thd_api.cc:110
void my_message_sql(uint error, const char *str, myf MyFlags)
All global error messages are sent here where the first one is stored for the client.
Definition: mysqld.cc:3983
void my_eof(THD *thd)
A short cut for thd->get_stmt_da()->set_eof_status().
Definition: sql_class.cc:3857
void thd_enter_stage(void *opaque_thd, const PSI_stage_info *new_stage, PSI_stage_info *old_stage, const char *src_function, const char *src_file, int src_line)
Definition: sql_thd_internal_api.cc:212
bool is_xa_tran_detached_on_prepare(const THD *thd)
Returns true if xa transactions are detached as part of executing XA PREPARE.
Definition: sql_class.h:5085
constexpr size_t PREALLOC_NUM_HA
Definition: sql_class.h:203
void thd_exit_cond(void *opaque_thd, const PSI_stage_info *stage, const char *src_function, const char *src_file, int src_line)
Set thread leaving a condition.
Definition: sql_thd_internal_api.cc:203
std::stack< Event_tracking_data > Event_tracking_data_stack
Definition: sql_class.h:929
bool add_item_to_list(THD *thd, Item *item)
Definition: sql_class.cc:3160
enum_mem_cnt_mode
Definition: sql_class.h:235
@ MEM_CNT_DEFAULT
Memory counter object doesn't update global memory counter and doesn't throw OOM error.
Definition: sql_class.h:240
@ MEM_CNT_GENERATE_ERROR
if MEM_CNT_GENERATE_ERROR is set, memory counter object generates OOM error if any.
Definition: sql_class.h:250
@ MEM_CNT_UPDATE_GLOBAL_COUNTER
if MEM_CNT_UPDATE_GLOBAL_COUNTER is set, memory counter object updates global memory counter.
Definition: sql_class.h:245
@ MEM_CNT_GENERATE_LOG_ERROR
if MEM_CNT_GENERATE_LOG_ERROR is set, memory counter object generates OOM error to error log if any.
Definition: sql_class.h:255
bool is_sql_fk_checks_enabled(THD *thd)
Check if foreign handling at SQL is enabled.
Definition: sql_class.h:5111
thread_local TDM expected_from_debug_flag
Definition: sql_class.h:209
Secondary_engine_optimization
Enum that represents which phase of secondary engine optimization the current statement is in.
Definition: sql_class.h:715
@ SECONDARY
The current statement should use tables from a secondary storage engine if possible.
@ PRIMARY_ONLY
The current statement should only use tables from primary storage engines.
@ PRIMARY_TENTATIVELY
The current statement should only use tables from the primary storage engine.
bool is_engine_substitution_allowed(const THD *thd)
Check if engine substitution is allowed in the current thread context.
Definition: sql_class.h:5040
void my_ok(THD *thd, ulonglong affected_rows=0, ulonglong id=0, const char *message=nullptr)
A short cut for thd->get_stmt_da()->set_ok_status().
Definition: sql_class.cc:3851
void thd_enter_cond(void *opaque_thd, mysql_cond_t *cond, mysql_mutex_t *mutex, const PSI_stage_info *stage, PSI_stage_info *old_stage, const char *src_function, const char *src_file, int src_line)
Set thread entering a condition.
Definition: sql_thd_internal_api.cc:190
char const * show_system_thread(enum_thread_type thread)
Definition: sql_class.h:766
#define RETURN_NAME_AS_STRING(NAME)
void thd_set_waiting_for_disk_space(void *opaque_thd, const bool waiting)
Definition: sql_thd_internal_api.cc:223
bool is_cascade_triggers_enabled(THD *thd)
Check if SQL FK cascade should fire triggers.
Definition: sql_class.h:5137
TDM
Definition: sql_class.h:208
@ ZERO
@ NOT_AVAILABLE
unsigned int thd_get_current_thd_terminology_use_previous()
Return @session.terminology_use_previous for the current THD.
Definition: sql_thd_api.cc:734
std::pair< Event_tracking_class, Event_tracking_information * > Event_tracking_data
Definition: sql_class.h:928
void thd_set_psi(THD *thd, PSI_thread *psi)
Set reference to Performance Schema object for THD object.
Definition: sql_thd_api.cc:131
bool is_rpl_source_older(const THD *thd, uint version)
Return if source replication node is older than the given version.
Definition: sql_class.h:5097
bool secondary_engine_lock_tables_mode(const THD &cthd)
Return lock_tables_mode for secondary engine.
Definition: sql_class.h:5016
bool use_sql_fk_checks_for_table(THD *thd, TABLE *table)
Check if SQL foreign key handling can be used for a table.
Definition: sql_class.cc:3879
struct rpl_event_coordinates LOG_POS_COORD
the struct aggregates two parameters that identify an event uniquely in scope of communication of a p...
I_List< Item_change_record > Item_change_list
Definition: sql_class.h:555
File containing constants that can be used throughout the server.
enum_mark_columns
Definition: sql_const.h:232
Event_tracking_class
Event tracking classes If a new event tracking class is introduced, this class should be kept in sync...
Definition: sql_event_tracking_to_audit_event_mapping.h:41
static MEM_ROOT mem
Definition: sql_servers.cc:100
Our own string classes, used pervasively throughout the executor.
case opt name
Definition: sslopt-case.h:29
Definition: binlog.h:90
Definition: m_ctype.h:421
TODO: Move this structure to mysql/binlog/event/control_events.h when we start using C++11.
Definition: rpl_gtid.h:1102
bool is_empty() const
Return true if sidno is zero (and assert that gno is zero too in this case).
Definition: rpl_gtid.h:1127
void clear()
Set both components to 0.
Definition: rpl_gtid.h:1111
void dbug_print(const Tsid_map *tsid_map, const char *text="", bool need_lock=false) const
Print this Gtid to the trace file if debug is enabled; no-op otherwise.
Definition: rpl_gtid.h:1211
rpl_sidno sidno
SIDNO of this Gtid.
Definition: rpl_gtid.h:1106
Storage engine specific thread local data.
Definition: sql_class.h:797
void * ha_ptr_backup
A memorizer to engine specific "native" transaction object to provide storage engine detach-re-attach...
Definition: sql_class.h:813
void * ha_ptr
Storage engine specific thread local data.
Definition: sql_class.h:802
Ha_data()
Definition: sql_class.h:832
plugin_ref lock
NULL: engine is not bound to this thread non-NULL: engine is bound to this thread,...
Definition: sql_class.h:830
Ha_trx_info ha_info[2]
0: Life time: one statement within a transaction.
Definition: sql_class.h:824
Definition: table.h:2825
The LEX object currently serves three different purposes:
Definition: sql_lex.h:4021
Definition: binlog_index.h:86
Metadata lock object key.
Definition: mdl.h:366
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
void * Alloc(size_t length)
Allocate memory.
Definition: my_alloc.h:145
Definition: mysql_lex_string.h:40
const char * str
Definition: mysql_lex_string.h:41
size_t length
Definition: mysql_lex_string.h:42
Definition: mysql_lex_string.h:35
Definition: lock.h:39
Bison "location" class.
Definition: parse_location.h:43
Definition: mysql_com_server.h:59
Definition: mysql_com.h:921
State data storage for start_idle_wait_v1_t.
Definition: psi_idle_bits.h:52
Stage instrument information.
Definition: psi_stage_bits.h:74
Interface for an instrumented stage progress.
Definition: psi_stage_bits.h:63
State data storage for get_thread_statement_locker_v5_t.
Definition: psi_statement_bits.h:173
State data storage for get_thread_transaction_locker_v1_t, get_thread_transaction_locker_v1_t.
Definition: psi_transaction_bits.h:53
Definition: com_data.h:46
Definition: transaction_info.h:58
Per thread status variables.
Definition: system_variables.h:539
ulonglong last_query_partial_plans
Definition: system_variables.h:616
double last_query_cost
Definition: system_variables.h:615
Definition: table.h:1456
Definition: sql_lexer_thd.h:56
sql_mode_t sql_mode
Definition: sql_lexer_thd.h:59
const CHARSET_INFO * character_set_client
Definition: sql_lexer_thd.h:60
An utility struct for Attachable_trx.
Definition: sql_class.h:2048
bool m_in_lock_tables
THD::in_lock_tables value.
Definition: sql_class.h:2087
void backup(THD *thd)
Definition: sql_class.cc:406
ulonglong m_thd_option_bits
THD options.
Definition: sql_class.h:2078
~Transaction_state()
Definition: sql_class.cc:3168
void restore(THD *thd)
Definition: sql_class.cc:423
PSI_transaction_locker * m_transaction_psi
Current transaction instrumentation.
Definition: sql_class.h:2081
Prealloced_array< Ha_data, PREALLOC_NUM_HA > m_ha_data
Ha_data array.
Definition: sql_class.h:2069
uint m_server_status
Server status flags.
Definition: sql_class.h:2084
bool m_time_zone_used
Current time zone (i.e.
Definition: sql_class.h:2098
bool m_transaction_rollback_request
Transaction rollback request flag.
Definition: sql_class.h:2108
Transaction_ctx * m_trx
Transaction_ctx instance.
Definition: sql_class.h:2072
Open_tables_backup m_open_tables_state
Open-tables state.
Definition: sql_class.h:2060
bool m_tx_read_only
Transaction read-only state.
Definition: sql_class.h:2075
sql_mode_t m_sql_mode
SQL_MODE.
Definition: sql_class.h:2063
Transaction_state()
Definition: sql_class.cc:3164
enum_sql_command m_sql_command
SQL-command.
Definition: sql_class.h:2055
Query_tables_list * m_query_tables_list
Definition: sql_class.h:2057
enum_tx_isolation m_tx_isolation
Transaction isolation level.
Definition: sql_class.h:2066
Definition: sql_timer.cc:54
Definition: thr_lock.h:119
For locks with EXPLICIT duration, MDL returns a new ticket every time a lock is granted.
Definition: item_func.cc:5643
Definition: violite.h:315
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2852
Replacement of system's struct timeval to ensure we can carry 64 bit values even on a platform which ...
Definition: my_time_t.h:45
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: mysql_com.h:1116
Definition: resource_group_basic_types.h:54
Definition: result.h:30
the struct aggregates two parameters that identify an event uniquely in scope of communication of a p...
Definition: sql_class.h:344
my_off_t pos
Definition: sql_class.h:346
char * file_name
Definition: sql_class.h:345
State data storage for digest_start, digest_add_token.
Definition: sql_digest_stream.h:36
Definition: sql_audit.h:56
Definition: sql_plugin_ref.h:45
Definition: mysqlslap.cc:222
Definition: sql_connect.h:70
struct xid_t is binary compatible with the XID structure as in the X/Open CAE Specification,...
Definition: xa.h:83
constexpr sql_mode_t MODE_NO_ENGINE_SUBSTITUTION
Definition: system_variables.h:154
constexpr sql_mode_t MODE_TIME_TRUNCATE_FRACTIONAL
Definition: system_variables.h:161
constexpr sql_mode_t MODE_STRICT_TRANS_TABLES
Definition: system_variables.h:135
constexpr sql_mode_t MODE_INTERPRET_UTF8_AS_UTF8MB4
Definition: system_variables.h:163
enum_binlog_format
Definition: system_variables.h:46
@ BINLOG_FORMAT_MIXED
statement if safe, otherwise row - autodetected
Definition: system_variables.h:47
@ BINLOG_FORMAT_ROW
row-based
Definition: system_variables.h:49
@ BINLOG_FORMAT_STMT
statement-based
Definition: system_variables.h:48
constexpr sql_mode_t MODE_STRICT_ALL_TABLES
Definition: system_variables.h:137
thr_lock_type
Definition: thr_lock.h:51
enum_thread_type
Definition: thread_type.h:34
@ NON_SYSTEM_THREAD
Definition: thread_type.h:35
@ SYSTEM_THREAD_BACKGROUND
Definition: thread_type.h:44
@ SYSTEM_THREAD_INIT_FILE
Definition: thread_type.h:48
@ SYSTEM_THREAD_SLAVE_IO
Definition: thread_type.h:36
@ SYSTEM_THREAD_EVENT_SCHEDULER
Definition: thread_type.h:39
@ SYSTEM_THREAD_COMPRESS_GTID_TABLE
Definition: thread_type.h:43
@ SYSTEM_THREAD_SLAVE_WORKER
Definition: thread_type.h:42
@ SYSTEM_THREAD_DD_RESTART
Definition: thread_type.h:46
@ SYSTEM_THREAD_SERVER_UPGRADE
Definition: thread_type.h:49
@ SYSTEM_THREAD_SERVER_INITIALIZE
Definition: thread_type.h:47
@ SYSTEM_THREAD_SLAVE_SQL
Definition: thread_type.h:37
@ SYSTEM_THREAD_DD_INITIALIZE
Definition: thread_type.h:45
@ SYSTEM_THREAD_INFO_REPOSITORY
Definition: thread_type.h:41
@ SYSTEM_THREAD_EVENT_WORKER
Definition: thread_type.h:40
@ SYSTEM_THREAD_NDBCLUSTER_BINLOG
Definition: thread_type.h:38
Definition: dtoa.cc:595
Vio Lite.
enum_vio_type
Definition: violite.h:79
#define SSL_handle
Definition: violite.h:449