MySQL  8.0.19
Source Code Documentation
sql_thd_internal_api.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, 2018, 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  @return
207  @retval true The path is different from mysql data directory.
208  @retval false The path is same as mysql data directory.
209 */
210 bool is_mysql_datadir_path(const char *path);
211 
212 /**
213  Create a temporary file.
214 
215  @details
216  The temporary file is created in a location specified by the parameter
217  path. if path is null, then it will be created on the location given
218  by the mysql server configuration (--tmpdir option). The caller
219  does not need to delete the file, it will be deleted automatically.
220 
221  @param path location for creating temporary file
222  @param prefix prefix for temporary file name
223  @retval -1 error
224  @retval >=0 a file handle that can be passed to dup or my_close
225 */
226 
227 int mysql_tmpfile_path(const char *path, const char *prefix);
228 
229 /**
230  Check if the server is in the process of being initialized.
231 
232  Check the thread type of the THD. If this is a thread type
233  being used for initializing the DD or the server, return
234  true.
235 
236  @param thd Needed since this is an opaque type in the SE.
237 
238  @retval true The thread is a bootstrap thread.
239  @retval false The thread is not a bootstrap thread.
240 */
241 
242 bool thd_is_bootstrap_thread(THD *thd);
243 
244 /**
245  Is statement updating the data dictionary tables.
246 
247  @details
248  The thread switches to the data dictionary tables update context using
249  the dd::Update_dictionary_tables_ctx while updating dictionary tables.
250  If thread is in this context then the method returns true otherwise
251  false.
252  This method is used by the InnoDB while updating the tables to mark
253  transaction as DDL if this method returns true.
254 
255  @param thd Thread handle.
256 
257  @retval true Updates data dictionary tables.
258  @retval false Otherwise.
259 */
260 bool thd_is_dd_update_stmt(const THD *thd);
261 
262 my_thread_id thd_thread_id(const THD *thd);
263 #endif // SQL_THD_INTERNAL_API_INCLUDED
MYSQL_LEX_CSTRING
Definition: mysql_lex_string.h:39
THD
Definition: sql_class.h:764
thd_is_strict_mode
bool thd_is_strict_mode(const THD *thd)
Is strict sql_mode set.
Definition: sql_thd_internal_api.cc:236
durability_properties
durability_properties
Definition: dur_prop.h:30
thd_is_dd_update_stmt
bool thd_is_dd_update_stmt(const THD *thd)
Is statement updating the data dictionary tables.
Definition: sql_thd_internal_api.cc:278
mysql_tmpfile_path
int mysql_tmpfile_path(const char *path, const char *prefix)
Create a temporary file.
Definition: sql_thd_internal_api.cc:259
CHARSET_INFO
Definition: m_ctype.h:354
psi_thread_bits.h
thd_sqlcom_can_generate_row_events
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:219
thd_charset
const CHARSET_INFO * thd_charset(THD *thd)
Definition: sql_thd_internal_api.cc:184
thd_get_autoinc
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:231
handler.h
thd_non_transactional_update
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:203
destroy_thd
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:110
thd_get_work_part_info
partition_info * thd_get_work_part_info(THD *thd)
Returns the partition_info working copy.
Definition: sql_thd_internal_api.cc:178
dur_prop.h
is_mysql_datadir_path
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:240
Counter::inc
void inc(Shards< COUNT > &shards, size_t id)
Increment the counter of a shard by 1.
Definition: ut0counter.h:255
thd_get_trx_isolation
enum_tx_isolation thd_get_trx_isolation(const THD *thd)
Definition: sql_thd_internal_api.cc:180
m_ctype.h
lex_string.h
thd_set_thread_stack
void thd_set_thread_stack(THD *thd, const char *stack_start)
Set thread stack in THD object.
Definition: sql_thd_internal_api.cc:120
thd_get_durability_property
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:223
thd_binlog_format
int thd_binlog_format(const THD *thd)
Get the user thread's binary logging format.
Definition: sql_thd_internal_api.cc:208
thd_is_bootstrap_thread
bool thd_is_bootstrap_thread(THD *thd)
Check if the server is in the process of being initialized.
Definition: sql_thd_internal_api.cc:273
path
static char * path
Definition: mysqldump.cc:130
my_thread_id
uint32 my_thread_id
Definition: my_thread_local.h:33
PSI_thread_key
unsigned int PSI_thread_key
Instrumented thread key.
Definition: psi_thread_bits.h:48
thd_thread_id
my_thread_id thd_thread_id(const THD *thd)
Definition: sql_thd_internal_api.cc:295
ulong
unsigned long ulong
Definition: my_inttypes.h:48
thd_query_safe
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:191
thd_is_error
bool thd_is_error(const THD *thd)
Is an error set in the DA.
Definition: sql_thd_internal_api.cc:238
partition_info
Definition: partition_info.h:208
create_thd
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:98
thd_binlog_filter_ok
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:215
thd_query_unsafe
LEX_CSTRING thd_query_unsafe(THD *thd)
Get the current query string for the thread.
Definition: sql_thd_internal_api.cc:186
enum_tx_isolation
enum_tx_isolation
Definition: handler.h:2614
thd_init
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:65
thd_slave_thread
int thd_slave_thread(const THD *thd)
Check if a user thread is a replication slave thread.
Definition: sql_thd_internal_api.cc:201