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