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