MySQL 8.0.33
Source Code Documentation
sql_thd_internal_api.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2023, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef SQL_THD_INTERNAL_API_INCLUDED
24#define SQL_THD_INTERNAL_API_INCLUDED
25
26/*
27 This file defines THD-related API calls that are meant for internal
28 usage (e.g. InnoDB, Thread Pool) only. There are therefore no stability
29 guarantees.
30*/
31
32#include <stddef.h>
33#include <sys/types.h>
34
35#include "dur_prop.h" // durability_properties
36#include "lex_string.h"
37#include "m_ctype.h"
39#include "sql/handler.h" // enum_tx_isolation
40
41class THD;
42class partition_info;
43
45void destroy_internal_thd(THD *thd);
46
47/**
48 Set up various THD data for a new connection.
49 @note PFS instrumentation is not set by this function.
50
51 @param thd THD object
52 @param stack_start Start of stack for connection
53*/
54void thd_init(THD *thd, char *stack_start);
55
56/**
57 Set up various THD data for a new connection
58
59 @param thd THD object
60 @param stack_start Start of stack for connection
61 @param bound True if bound to a physical thread.
62 @param psi_key Instrumentation key for the thread.
63 @param psi_seqnum Instrumentation sequence number for the thread.
64*/
65void thd_init(THD *thd, char *stack_start, bool bound, PSI_thread_key psi_key,
66 unsigned int psi_seqnum);
67
68/**
69 Create a THD and do proper initialization of it.
70
71 @param enable_plugins Should dynamic plugin support be enabled?
72 @param background_thread Is this a background thread?
73 @param bound True if bound to a physical thread.
74 @param psi_key Instrumentation key for the thread.
75 @param psi_seqnum Instrumentation sequence number for the thread.
76
77 @note Dynamic plugin support is only possible for THDs that
78 are created after the server has initialized properly.
79 @note THDs for background threads are currently not added to
80 the global THD list. So they will e.g. not be visible in
81 SHOW PROCESSLIST and the server will not wait for them to
82 terminate during shutdown.
83*/
84THD *create_thd(bool enable_plugins, bool background_thread, bool bound,
85 PSI_thread_key psi_key, unsigned int psi_seqnum);
86
87/**
88 Cleanup the THD object, remove it from the global list of THDs
89 and delete it.
90
91 @param thd Pointer to THD object.
92 @param clear_pfs_instr If true, then clear thread PFS instrumentations.
93*/
94void destroy_thd(THD *thd, bool clear_pfs_instr);
95
96/**
97 Cleanup the THD object, remove it from the global list of THDs
98 and delete it.
99
100 @param thd Pointer to THD object.
101*/
102void destroy_thd(THD *thd);
103
104/**
105 Set thread stack in THD object
106
107 @param thd Thread object
108 @param stack_start Start of stack to set in THD object
109*/
110void thd_set_thread_stack(THD *thd, const char *stack_start);
111
112/**
113 Returns the partition_info working copy.
114 Used to see if a table should be created with partitioning.
115
116 @param thd thread context
117
118 @return Pointer to the working copy of partition_info or NULL.
119*/
121
123
124const CHARSET_INFO *thd_charset(THD *thd);
125
126/**
127 Get the current query string for the thread.
128
129 @param thd The MySQL internal thread pointer
130
131 @return query string and length. May be non-null-terminated.
132
133 @note This function is not thread safe and should only be called
134 from the thread owning thd. @see thd_query_safe().
135*/
137
138/**
139 Get the current query string for the thread.
140
141 @param thd The MySQL internal thread pointer
142 @param buf Buffer where the query string will be copied
143 @param buflen Length of the buffer
144
145 @return Length of the query
146
147 @note This function is thread safe as the query string is
148 accessed under mutex protection and the string is copied
149 into the provided buffer. @see thd_query_unsafe().
150*/
151size_t thd_query_safe(THD *thd, char *buf, size_t buflen);
152
153/**
154 Check if a user thread is a replication slave thread
155 @param thd user thread
156 @retval 0 the user thread is not a replication slave thread
157 @retval 1 the user thread is a replication slave thread
158*/
159int thd_slave_thread(const THD *thd);
160
161/**
162 Check if a user thread is running a non-transactional update
163 @param thd user thread
164 @retval 0 the user thread is not running a non-transactional update
165 @retval 1 the user thread is running a non-transactional update
166*/
167int thd_non_transactional_update(const THD *thd);
168
169/**
170 Get the user thread's binary logging format
171 @param thd user thread
172 @return Value to be used as index into the binlog_format_names array
173*/
174int thd_binlog_format(const THD *thd);
175
176/**
177 Check if binary logging is filtered for thread's current db.
178 @param thd Thread handle
179 @retval 1 the query is not filtered, 0 otherwise.
180*/
181bool thd_binlog_filter_ok(const THD *thd);
182
183/**
184 Check if the query may generate row changes which may end up in the binary.
185 @param thd Thread handle
186 @retval 1 the query may generate row changes, 0 otherwise.
187*/
189
190/**
191 Gets information on the durability property requested by a thread.
192 @param thd Thread handle
193 @return a durability property.
194*/
196
197/**
198 Get the auto_increment_offset auto_increment_increment.
199 @param thd Thread object
200 @param off auto_increment_offset
201 @param inc auto_increment_increment
202*/
203void thd_get_autoinc(const THD *thd, ulong *off, ulong *inc);
204
205/**
206 Get the tmp_table_size threshold.
207 @param thd Thread object
208 @return Value of currently set tmp_table_size threshold.
209*/
210size_t thd_get_tmp_table_size(const THD *thd);
211
212/**
213 Is strict sql_mode set.
214 Needed by InnoDB.
215 @param thd Thread object
216 @return True if sql_mode has strict mode (all or trans).
217 @retval true sql_mode has strict mode (all or trans).
218 @retval false sql_mode has not strict mode (all or trans).
219*/
220bool thd_is_strict_mode(const THD *thd);
221
222/**
223 Is an error set in the DA.
224 Needed by InnoDB to catch behavior modified by an error handler.
225 @param thd Thread object
226 @return True if THD::is_error() returns true.
227 @retval true An error has been raised.
228 @retval false No error has been raised.
229*/
230bool thd_is_error(const THD *thd);
231
232/**
233 Test a file path whether it is same as mysql data directory path.
234
235 @param path null terminated character string
236
237 @retval true The path is different from mysql data directory.
238 @retval false The path is same as mysql data directory.
239*/
240bool is_mysql_datadir_path(const char *path);
241
242/**
243 Create a temporary file.
244
245 @details
246 The temporary file is created in a location specified by the parameter
247 path. if path is null, then it will be created on the location given
248 by the mysql server configuration (--tmpdir option). The caller
249 does not need to delete the file, it will be deleted automatically.
250
251 @param path location for creating temporary file
252 @param prefix prefix for temporary file name
253 @retval -1 error
254 @retval >=0 a file handle that can be passed to dup or my_close
255*/
256
257int mysql_tmpfile_path(const char *path, const char *prefix);
258
259/**
260 Check if the server is in the process of being initialized.
261
262 Check the thread type of the THD. If this is a thread type
263 being used for initializing the DD or the server, return
264 true.
265
266 @param thd Needed since this is an opaque type in the SE.
267
268 @retval true The thread is a bootstrap thread.
269 @retval false The thread is not a bootstrap thread.
270*/
271
273
274/**
275 Is statement updating the data dictionary tables.
276
277 @details
278 The thread switches to the data dictionary tables update context using
279 the dd::Update_dictionary_tables_ctx while updating dictionary tables.
280 If thread is in this context then the method returns true otherwise
281 false.
282 This method is used by the InnoDB while updating the tables to mark
283 transaction as DDL if this method returns true.
284
285 @param thd Thread handle.
286
287 @retval true Updates data dictionary tables.
288 @retval false Otherwise.
289*/
290bool thd_is_dd_update_stmt(const THD *thd);
291
292my_thread_id thd_thread_id(const THD *thd);
293
294/**
295 Method to disable resource groups.
296
297 @param reason Reason to disable resource groups.
298*/
299void disable_resource_groups(const char *reason);
300
301/**
302 Method to bind system thread to SYS_internal resource group.
303
304 @note This method is invoked by only thread pool to set SYS_internal resource
305 group to query worker thread.
306
307 @returns false on success and true on error.
308*/
310
311/**
312 Bind THD (user) resource group to a system thread.
313
314 @note This method is invoked by only thread pool to bind user resource group
315 to a query worker thread. Method is optimised for the thread pool usage.
316
317
318 @param thd Thread handle.
319 @param[in,out] saved_thd_resource_grp THD resource group applied
320 to system thread before(if
321 any).
322 @param[in,out] saved_thd_resource_group_version Version of a resource group
323 in-memory instance saved
324 with a system thread.
325
326 @returns false on success and true on error.
327*/
329 THD *thd, void **saved_thd_resource_grp,
330 uint *saved_thd_resource_group_version);
331
332/**
333 Unbind THD (user) resource group attached to a system thread.
334
335 @note This method is invoked by only thread pool to unbind user resource group
336 from a query worker thread. Method is optimised for the thread pool
337 usage.
338
339 @param thd Thread handle.
340 @param[in,out] saved_thd_resource_grp THD resource group applied
341 to system thread before(if
342 any).
343 @param[out] saved_thd_resource_group_version Version of a resource group
344 in-memory instance saved
345 with a system thread.
346
347 @returns false on success and true on error.
348*/
350 THD *thd, void **saved_thd_resource_grp,
351 uint *saved_thd_resource_group_version);
352
353/**
354 Release THD resource group saved with a system thread.
355
356 @note This method is invoked by only thread pool to release resource group
357 saved with a system thread.
358
359 @param[in,out] saved_thd_resource_grp THD resource group saved
360 with a system thread (if
361 any).
362 @param[out] saved_thd_resource_group_version Version of a resource group
363 in-memory instance saved
364 with a system thread.
365 @param only_if_defunct If set to true then THD
366 resource group is released
367 only if it is defunct.
368*/
369bool release_saved_thd_resource_group(void **saved_thd_resource_grp,
370 uint *saved_thd_resource_group_version,
371 bool only_if_defunct);
372#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:33
Definition: partition_info.h:208
durability_properties
Definition: dur_prop.h:30
unsigned int PSI_thread_key
Instrumented thread key.
Definition: psi_thread_bits.h:49
A better implementation of the UNIX ctype(3) library.
uint32 my_thread_id
Definition: my_thread_local.h:33
static char * path
Definition: mysqldump.cc:133
Type inc(Shards< COUNT > &shards, size_t id)
Increment the counter of a shard by 1.
Definition: ut0counter.h:292
Definition: buf0block_hint.cc:29
Performance schema instrumentation interface.
enum_tx_isolation
Definition: handler.h:2984
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:296
void thd_set_thread_stack(THD *thd, const char *stack_start)
Set thread stack in THD object.
Definition: sql_thd_internal_api.cc:185
void destroy_internal_thd(THD *thd)
Definition: sql_thd_internal_api.cc:95
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:155
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:284
bool thd_is_strict_mode(const THD *thd)
Is strict sql_mode set.
Definition: sql_thd_internal_api.cc:319
int mysql_tmpfile_path(const char *path, const char *prefix)
Create a temporary file.
Definition: sql_thd_internal_api.cc:342
size_t thd_get_tmp_table_size(const THD *thd)
Get the tmp_table_size threshold.
Definition: sql_thd_internal_api.cc:301
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:280
bool thd_is_dd_update_stmt(const THD *thd)
Is statement updating the data dictionary tables.
Definition: sql_thd_internal_api.cc:362
bool thd_is_bootstrap_thread(THD *thd)
Check if the server is in the process of being initialized.
Definition: sql_thd_internal_api.cc:356
bool bind_thread_to_sys_internal_resource_group()
Method to bind system thread to SYS_internal resource group.
Definition: sql_thd_internal_api.cc:405
enum_tx_isolation thd_get_trx_isolation(const THD *thd)
Definition: sql_thd_internal_api.cc:245
int thd_slave_thread(const THD *thd)
Check if a user thread is a replication slave thread.
Definition: sql_thd_internal_api.cc:266
LEX_CSTRING thd_query_unsafe(THD *thd)
Get the current query string for the thread.
Definition: sql_thd_internal_api.cc:251
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:256
bool thd_is_error(const THD *thd)
Is an error set in the DA.
Definition: sql_thd_internal_api.cc:321
my_thread_id thd_thread_id(const THD *thd)
Definition: sql_thd_internal_api.cc:379
THD * create_internal_thd()
Definition: sql_thd_internal_api.cc:69
void disable_resource_groups(const char *reason)
Method to disable resource groups.
Definition: sql_thd_internal_api.cc:381
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:288
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:268
int thd_binlog_format(const THD *thd)
Get the user thread's binary logging format.
Definition: sql_thd_internal_api.cc:273
bool unbind_system_thread_from_thd_resource_group(THD *thd, void **saved_thd_resource_grp, uint *saved_thd_resource_group_version)
Unbind THD (user) resource group attached to a system thread.
Definition: sql_thd_internal_api.cc:532
const CHARSET_INFO * thd_charset(THD *thd)
Definition: sql_thd_internal_api.cc:249
partition_info * thd_get_work_part_info(THD *thd)
Returns the partition_info working copy.
Definition: sql_thd_internal_api.cc:243
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:323
bool bind_system_thread_to_thd_resource_group(THD *thd, void **saved_thd_resource_grp, uint *saved_thd_resource_group_version)
Bind THD (user) resource group to a system thread.
Definition: sql_thd_internal_api.cc:481
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:168
bool release_saved_thd_resource_group(void **saved_thd_resource_grp, uint *saved_thd_resource_group_version, bool only_if_defunct)
Release THD resource group saved with a system thread.
Definition: sql_thd_internal_api.cc:586
void thd_init(THD *thd, char *stack_start)
Set up various THD data for a new connection.
Definition: sql_thd_internal_api.cc:114
Definition: m_ctype.h:382
Definition: mysql_lex_string.h:39
unsigned int uint
Definition: uca9-dump.cc:74