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