MySQL 8.4.0
Source Code Documentation
sql_thd_internal_api.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 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_THD_INTERNAL_API_INCLUDED
25#define SQL_THD_INTERNAL_API_INCLUDED
26
27/*
28 This file defines THD-related API calls that are meant for internal
29 usage (e.g. InnoDB, Thread Pool) only. There are therefore no stability
30 guarantees.
31*/
32
33#include <stddef.h>
34#include <sys/types.h>
35
36#include "dur_prop.h" // durability_properties
37#include "lex_string.h"
40#include "sql/handler.h" // enum_tx_isolation
41
42class THD;
43class partition_info;
44
46void destroy_internal_thd(THD *thd);
47
48/**
49 Set up various THD data for a new connection.
50 @note PFS instrumentation is not set by this function.
51
52 @param thd THD object
53 @param stack_start Start of stack for connection
54*/
55void thd_init(THD *thd, char *stack_start);
56
57/**
58 Set up various THD data for a new connection
59
60 @param thd THD object
61 @param stack_start Start of stack for connection
62 @param bound True if bound to a physical thread.
63 @param psi_key Instrumentation key for the thread.
64 @param psi_seqnum Instrumentation sequence number for the thread.
65*/
66void thd_init(THD *thd, char *stack_start, bool bound, PSI_thread_key psi_key,
67 unsigned int psi_seqnum);
68
69/**
70 Create a THD and do proper initialization of it.
71
72 @param enable_plugins Should dynamic plugin support be enabled?
73 @param background_thread Is this a background thread?
74 @param bound True if bound to a physical thread.
75 @param psi_key Instrumentation key for the thread.
76 @param psi_seqnum Instrumentation sequence number for the thread.
77
78 @note Dynamic plugin support is only possible for THDs that
79 are created after the server has initialized properly.
80 @note THDs for background threads are currently not added to
81 the global THD list. So they will e.g. not be visible in
82 SHOW PROCESSLIST and the server will not wait for them to
83 terminate during shutdown.
84*/
85THD *create_thd(bool enable_plugins, bool background_thread, bool bound,
86 PSI_thread_key psi_key, unsigned int psi_seqnum);
87
88/**
89 Cleanup the THD object, remove it from the global list of THDs
90 and delete it.
91
92 @param thd Pointer to THD object.
93 @param clear_pfs_instr If true, then clear thread PFS instrumentations.
94*/
95void destroy_thd(THD *thd, bool clear_pfs_instr);
96
97/**
98 Cleanup the THD object, remove it from the global list of THDs
99 and delete it.
100
101 @param thd Pointer to THD object.
102*/
103void destroy_thd(THD *thd);
104
105/**
106 Set thread stack in THD object
107
108 @param thd Thread object
109 @param stack_start Start of stack to set in THD object
110*/
111void thd_set_thread_stack(THD *thd, const char *stack_start);
112
113/**
114 Returns the partition_info working copy.
115 Used to see if a table should be created with partitioning.
116
117 @param thd thread context
118
119 @return Pointer to the working copy of partition_info or NULL.
120*/
122
124
125const CHARSET_INFO *thd_charset(THD *thd);
126
127/**
128 Get the current query string for the thread.
129
130 @param thd The MySQL internal thread pointer
131
132 @return query string and length. May be non-null-terminated.
133
134 @note This function is not thread safe and should only be called
135 from the thread owning thd. @see thd_query_safe().
136*/
138
139/**
140 Get the current query string for the thread.
141
142 @param thd The MySQL internal thread pointer
143 @param buf Buffer where the query string will be copied
144 @param buflen Length of the buffer
145
146 @return Length of the query
147
148 @note This function is thread safe as the query string is
149 accessed under mutex protection and the string is copied
150 into the provided buffer. @see thd_query_unsafe().
151*/
152size_t thd_query_safe(THD *thd, char *buf, size_t buflen);
153
154/**
155 Check if a user thread is a replication slave thread
156 @param thd user thread
157 @retval 0 the user thread is not a replication slave thread
158 @retval 1 the user thread is a replication slave thread
159*/
160int thd_slave_thread(const THD *thd);
161
162/**
163 Check if a user thread is running a non-transactional update
164 @param thd user thread
165 @retval 0 the user thread is not running a non-transactional update
166 @retval 1 the user thread is running a non-transactional update
167*/
168int thd_non_transactional_update(const THD *thd);
169
170/**
171 Get the user thread's binary logging format
172 @param thd user thread
173 @return Value to be used as index into the binlog_format_names array
174*/
175int thd_binlog_format(const THD *thd);
176
177/**
178 Check if binary logging is filtered for thread's current db.
179 @param thd Thread handle
180 @retval 1 the query is not filtered, 0 otherwise.
181*/
182bool thd_binlog_filter_ok(const THD *thd);
183
184/**
185 Check if the query may generate row changes which may end up in the binary.
186 @param thd Thread handle
187 @retval 1 the query may generate row changes, 0 otherwise.
188*/
190
191/**
192 Gets information on the durability property requested by a thread.
193 @param thd Thread handle
194 @return a durability property.
195*/
197
198/**
199 Get the auto_increment_offset auto_increment_increment.
200 @param thd Thread object
201 @param off auto_increment_offset
202 @param inc auto_increment_increment
203*/
204void thd_get_autoinc(const THD *thd, ulong *off, ulong *inc);
205
206/**
207 Get the tmp_table_size threshold.
208 @param thd Thread object
209 @return Value of currently set tmp_table_size threshold.
210*/
211size_t thd_get_tmp_table_size(const THD *thd);
212
213/**
214 Is strict sql_mode set.
215 Needed by InnoDB.
216 @param thd Thread object
217 @return True if sql_mode has strict mode (all or trans).
218 @retval true sql_mode has strict mode (all or trans).
219 @retval false sql_mode has not strict mode (all or trans).
220*/
221bool thd_is_strict_mode(const THD *thd);
222
223/**
224 Is an error set in the DA.
225 Needed by InnoDB to catch behavior modified by an error handler.
226 @param thd Thread object
227 @return True if THD::is_error() returns true.
228 @retval true An error has been raised.
229 @retval false No error has been raised.
230*/
231bool thd_is_error(const THD *thd);
232
233/**
234 Test a file path whether it is same as mysql data directory path.
235
236 @param path null terminated character string
237
238 @retval true The path is different from mysql data directory.
239 @retval false The path is same as mysql data directory.
240*/
241bool is_mysql_datadir_path(const char *path);
242
243/**
244 Create a temporary file.
245
246 @details
247 The temporary file is created in a location specified by the parameter
248 path. if path is null, then it will be created on the location given
249 by the mysql server configuration (--tmpdir option). The caller
250 does not need to delete the file, it will be deleted automatically.
251
252 @param path location for creating temporary file
253 @param prefix prefix for temporary file name
254 @retval -1 error
255 @retval >=0 a file handle that can be passed to dup or my_close
256*/
257
258int mysql_tmpfile_path(const char *path, const char *prefix);
259
260/**
261 Check if the server is in the process of being initialized.
262
263 Check the thread type of the THD. If this is a thread type
264 being used for initializing the DD or the server, return
265 true.
266
267 @param thd Needed since this is an opaque type in the SE.
268
269 @retval true The thread is a bootstrap thread.
270 @retval false The thread is not a bootstrap thread.
271*/
272
274
275/**
276 Is statement updating the data dictionary tables.
277
278 @details
279 The thread switches to the data dictionary tables update context using
280 the dd::Update_dictionary_tables_ctx while updating dictionary tables.
281 If thread is in this context then the method returns true otherwise
282 false.
283 This method is used by the InnoDB while updating the tables to mark
284 transaction as DDL if this method returns true.
285
286 @param thd Thread handle.
287
288 @retval true Updates data dictionary tables.
289 @retval false Otherwise.
290*/
291bool thd_is_dd_update_stmt(const THD *thd);
292
293my_thread_id thd_thread_id(const THD *thd);
294#endif // SQL_THD_INTERNAL_API_INCLUDED
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: partition_info.h:209
durability_properties
Definition: dur_prop.h:31
unsigned int PSI_thread_key
Instrumented thread key.
Definition: psi_thread_bits.h:50
A better implementation of the UNIX ctype(3) library.
uint32 my_thread_id
Definition: my_thread_local.h:34
static char * path
Definition: mysqldump.cc:149
Type inc(Shards< COUNT > &shards, size_t id)
Increment the counter of a shard by 1.
Definition: ut0counter.h:293
Definition: buf0block_hint.cc:30
Performance schema instrumentation interface.
enum_tx_isolation
Definition: handler.h:3185
void thd_get_autoinc(const THD *thd, ulong *off, ulong *inc)
Get the auto_increment_offset auto_increment_increment.
Definition: sql_thd_internal_api.cc:302
void thd_set_thread_stack(THD *thd, const char *stack_start)
Set thread stack in THD object.
Definition: sql_thd_internal_api.cc:186
void destroy_internal_thd(THD *thd)
Definition: sql_thd_internal_api.cc:96
THD * create_thd(bool enable_plugins, bool background_thread, bool bound, PSI_thread_key psi_key, unsigned int psi_seqnum)
Create a THD and do proper initialization of it.
Definition: sql_thd_internal_api.cc:156
bool thd_sqlcom_can_generate_row_events(const THD *thd)
Check if the query may generate row changes which may end up in the binary.
Definition: sql_thd_internal_api.cc:290
bool thd_is_strict_mode(const THD *thd)
Is strict sql_mode set.
Definition: sql_thd_internal_api.cc:325
int mysql_tmpfile_path(const char *path, const char *prefix)
Create a temporary file.
Definition: sql_thd_internal_api.cc:348
size_t thd_get_tmp_table_size(const THD *thd)
Get the tmp_table_size threshold.
Definition: sql_thd_internal_api.cc:307
bool thd_binlog_filter_ok(const THD *thd)
Check if binary logging is filtered for thread's current db.
Definition: sql_thd_internal_api.cc:286
bool thd_is_dd_update_stmt(const THD *thd)
Is statement updating the data dictionary tables.
Definition: sql_thd_internal_api.cc:369
bool thd_is_bootstrap_thread(THD *thd)
Check if the server is in the process of being initialized.
Definition: sql_thd_internal_api.cc:363
enum_tx_isolation thd_get_trx_isolation(const THD *thd)
Definition: sql_thd_internal_api.cc:251
int thd_slave_thread(const THD *thd)
Check if a user thread is a replication slave thread.
Definition: sql_thd_internal_api.cc:272
LEX_CSTRING thd_query_unsafe(THD *thd)
Get the current query string for the thread.
Definition: sql_thd_internal_api.cc:257
size_t thd_query_safe(THD *thd, char *buf, size_t buflen)
Get the current query string for the thread.
Definition: sql_thd_internal_api.cc:262
bool thd_is_error(const THD *thd)
Is an error set in the DA.
Definition: sql_thd_internal_api.cc:327
my_thread_id thd_thread_id(const THD *thd)
Definition: sql_thd_internal_api.cc:386
THD * create_internal_thd()
Definition: sql_thd_internal_api.cc:70
durability_properties thd_get_durability_property(const THD *thd)
Gets information on the durability property requested by a thread.
Definition: sql_thd_internal_api.cc:294
int thd_non_transactional_update(const THD *thd)
Check if a user thread is running a non-transactional update.
Definition: sql_thd_internal_api.cc:274
int thd_binlog_format(const THD *thd)
Get the user thread's binary logging format.
Definition: sql_thd_internal_api.cc:279
const CHARSET_INFO * thd_charset(THD *thd)
Definition: sql_thd_internal_api.cc:255
partition_info * thd_get_work_part_info(THD *thd)
Returns the partition_info working copy.
Definition: sql_thd_internal_api.cc:249
bool is_mysql_datadir_path(const char *path)
Test a file path whether it is same as mysql data directory path.
Definition: sql_thd_internal_api.cc:329
void destroy_thd(THD *thd, bool clear_pfs_instr)
Cleanup the THD object, remove it from the global list of THDs and delete it.
Definition: sql_thd_internal_api.cc:169
void thd_init(THD *thd, char *stack_start)
Set up various THD data for a new connection.
Definition: sql_thd_internal_api.cc:115
Definition: m_ctype.h:423
Definition: mysql_lex_string.h:40