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