MySQL 9.0.0
Source Code Documentation
|
#include <string.h>
#include <sys/types.h>
#include <algorithm>
#include <atomic>
#include "lex_string.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_io.h"
#include "my_macros.h"
#include "my_sqlcommand.h"
#include "my_thread.h"
#include "my_thread_local.h"
#include "mysql/components/services/bits/psi_stage_bits.h"
#include "mysql/components/services/bits/psi_thread_bits.h"
#include "mysql/plugin.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/service_thd_engine_lock.h"
#include "mysql/strings/m_ctype.h"
#include "mysql_com.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/sql_security_ctx.h"
#include "sql/conn_handler/connection_handler_manager.h"
#include "sql/current_thd.h"
#include "sql/handler.h"
#include "sql/mysqld.h"
#include "sql/protocol_classic.h"
#include "sql/query_options.h"
#include "sql/resourcegroups/platform/thread_attrs_api.h"
#include "sql/rpl_replica_commit_order_manager.h"
#include "sql/rpl_rli.h"
#include "sql/sql_alter.h"
#include "sql/sql_callback.h"
#include "sql/sql_class.h"
#include "sql/sql_error.h"
#include "sql/sql_lex.h"
#include "sql/sql_plugin.h"
#include "sql/sql_plugin_ref.h"
#include "sql/sql_thd_internal_api.h"
#include "sql/strfunc.h"
#include "sql/system_variables.h"
#include "sql/transaction_info.h"
#include "sql/xa.h"
#include "sql_string.h"
#include "string_with_len.h"
#include "violite.h"
Functions | |
void * | thd_get_scheduler_data (THD *thd) |
Get reference to scheduler data object. More... | |
void | thd_set_scheduler_data (THD *thd, void *data) |
Set reference to Scheduler data object for THD object. More... | |
PSI_thread * | thd_get_psi (THD *thd) |
Get reference to Performance Schema object for THD object. More... | |
ulong | thd_get_net_wait_timeout (THD *thd) |
Get net_wait_timeout for THD object. More... | |
void | thd_set_psi (THD *thd, PSI_thread *psi) |
Set reference to Performance Schema object for THD object. More... | |
void | thd_set_killed (THD *thd) |
Set the state on connection to killed. More... | |
void | thd_clear_errors (THD *thd) |
Clear errors from the previous THD. More... | |
void | thd_close_connection (THD *thd) |
Close the socket used by this connection. More... | |
THD * | thd_get_current_thd () |
Get current THD object from thread local data. More... | |
void | reset_thread_globals (THD *thd) |
Reset thread globals associated. More... | |
void | thd_lock_data (THD *thd) |
Lock data that needs protection in THD object. More... | |
void | thd_unlock_data (THD *thd) |
Unlock data that needs protection in THD object. More... | |
bool | thd_is_transaction_active (THD *thd) |
Support method to check if connection has already started transaction. More... | |
bool | thd_in_active_multi_stmt_transaction (const THD *thd) |
Predicate for determining if connection is in active multi-statement transaction. More... | |
int | thd_connection_has_data (THD *thd) |
Check if there is buffered data on the socket representing the connection. More... | |
uint | thd_get_net_read_write (THD *thd) |
Get reading/writing on socket from THD object. More... | |
void | thd_set_net_read_write (THD *thd, uint val) |
Set reading/writing on socket, used by SHOW PROCESSLIST. More... | |
void | thd_set_not_killable (THD *thd) |
Mark the THD as not killable as it is not currently used by a thread. More... | |
my_socket | thd_get_fd (THD *thd) |
Get socket file descriptor for this connection. More... | |
MYSQL_SOCKET | thd_get_mysql_socket (THD *thd) |
Get MYSQL_SOCKET struct for this connection. More... | |
void | thd_store_globals (THD *thd) |
Set thread specific environment required for thd cleanup in thread pool. More... | |
my_thread_attr_t * | get_connection_attrib () |
Get thread attributes for connection threads. More... | |
ulong | get_max_connections () |
Get max number of connections. More... | |
void | thd_binlog_pos (const MYSQL_THD thd, const char **file_var, unsigned long long *pos_var) |
Get binary log position for latest written entry. More... | |
int | mysql_tmpfile (const char *prefix) |
Create a temporary file. More... | |
int | thd_in_lock_tables (const MYSQL_THD thd) |
int | thd_tablespace_op (const MYSQL_THD thd) |
static void | set_thd_stage_info (MYSQL_THD thd, const PSI_stage_info *new_stage, PSI_stage_info *old_stage, const char *calling_func, const char *calling_file, const unsigned int calling_line) |
const char * | set_thd_proc_info (MYSQL_THD thd_arg, const char *info, const char *calling_function, const char *calling_file, const unsigned int calling_line) |
void ** | thd_ha_data (const MYSQL_THD thd, const struct handlerton *hton) |
void | thd_storage_lock_wait (MYSQL_THD thd, long long value) |
void * | thd_get_ha_data (const MYSQL_THD thd, const struct handlerton *hton) |
Provide a handler data getter to simplify coding. More... | |
void | thd_set_ha_data (MYSQL_THD thd, const struct handlerton *hton, const void *ha_data) |
Provide a handler data setter to simplify coding. More... | |
long long | thd_test_options (const MYSQL_THD thd, long long test_options) |
int | thd_sql_command (const MYSQL_THD thd) |
int | thd_tx_isolation (const MYSQL_THD thd) |
int | thd_tx_is_read_only (const MYSQL_THD thd) |
int | thd_tx_priority (const MYSQL_THD thd) |
MYSQL_THD | thd_tx_arbitrate (MYSQL_THD requestor, MYSQL_THD holder) |
int | thd_tx_is_dd_trx (const MYSQL_THD thd) |
void | thd_inc_row_count (MYSQL_THD thd) |
static size_t | truncated_str_length (const CHARSET_INFO *cs, const char *start, size_t original_size, size_t max_size) |
Returns the size of the beginning part of a (multibyte) string, which can fit in max_size bytes. More... | |
char * | thd_security_context (MYSQL_THD thd, char *buffer, size_t length, size_t max_query_len) |
Dumps a text description of a thread, its security context (user, host) and the current query. More... | |
void | thd_get_xid (const MYSQL_THD thd, MYSQL_XID *xid) |
Get the XID for this connection's transaction. More... | |
int | thd_killed (const void *v_thd) |
Check the killed state of a connection. More... | |
void | thd_set_kill_status (const MYSQL_THD thd) |
Set the killed status of the current statement. More... | |
unsigned long | thd_get_thread_id (const MYSQL_THD thd) |
Return the thread id of a user thread. More... | |
int | thd_allow_batch (MYSQL_THD thd) |
Check if batching is allowed for the thread. More... | |
void | thd_mark_transaction_to_rollback (MYSQL_THD thd, int all) |
Mark transaction to rollback and mark error as fatal to a sub-statement if in sub statement mode. More... | |
void * | thd_alloc (MYSQL_THD thd, size_t size) |
Allocate memory in the connection's local memory pool. More... | |
void * | thd_calloc (MYSQL_THD thd, size_t size) |
char * | thd_strdup (MYSQL_THD thd, const char *str) |
char * | thd_strmake (MYSQL_THD thd, const char *str, size_t size) |
MYSQL_LEX_STRING * | thd_make_lex_string (MYSQL_THD thd, MYSQL_LEX_STRING *lex_str, const char *str, size_t size, int allocate_lex_string) |
Create a LEX_STRING in this connection's local memory pool. More... | |
void * | thd_memdup (MYSQL_THD thd, const void *str, size_t size) |
void | thd_wait_begin (MYSQL_THD thd, int wait_type) |
Interface for MySQL Server, plugins and storage engines to report when they are going to sleep/stall. More... | |
void | thd_wait_end (MYSQL_THD thd) |
Interface for MySQL Server, plugins and storage engines to report when they waking up from a sleep/stall. More... | |
void | thd_report_row_lock_wait (THD *self, THD *wait_for) |
void | thd_report_lock_wait (THD *self, THD *wait_for, bool) |
Call it just when the engine find a transaction should wait another transaction to release a lock. More... | |
void | remove_ssl_err_thread_state () |
Interface for cleaning the openssl per thread error queue. More... | |
unsigned int | thd_get_num_vcpus () |
Interface to get the number of VCPUs. More... | |
bool | thd_check_connection_admin_privilege (MYSQL_THD thd) |
unsigned int | thd_get_current_thd_terminology_use_previous () |
Return @session.terminology_use_previous for the current THD. More... | |
my_thread_attr_t * get_connection_attrib | ( | void | ) |
Get thread attributes for connection threads.
Returns the server connection attribute.
Reference | to thread attribute for connection threads |
ulong get_max_connections | ( | void | ) |
Get max number of connections.
Max | number of connections for MySQL Server |
int mysql_tmpfile | ( | const char * | prefix | ) |
Create a temporary file.
The temporary file is created in a location specified by the mysql server configuration (–tmpdir option). The caller does not need to delete the file, it will be deleted automatically.
prefix | prefix for temporary file name |
-1 | error |
>= | 0 a file handle that can be passed to dup or my_close |
void remove_ssl_err_thread_state | ( | ) |
Interface for cleaning the openssl per thread error queue.
Interface to remove the per thread openssl error queue.
void reset_thread_globals | ( | THD * | thd | ) |
Reset thread globals associated.
thd | THD object |
const char * set_thd_proc_info | ( | MYSQL_THD | thd_arg, |
const char * | info, | ||
const char * | calling_function, | ||
const char * | calling_file, | ||
const unsigned int | calling_line | ||
) |
|
static |
void * thd_alloc | ( | MYSQL_THD | thd, |
size_t | size | ||
) |
Allocate memory in the connection's local memory pool.
When properly used in place of my_malloc()
, this can significantly improve concurrency. Don't use this or related functions to allocate large chunks of memory. Use for temporary storage only. The memory will be freed automatically at the end of the statement; no explicit code is required to prevent memory leaks.
int thd_allow_batch | ( | MYSQL_THD | thd | ) |
Check if batching is allowed for the thread.
thd | user thread |
1 | batching allowed |
0 | batching not allowed |
void thd_binlog_pos | ( | const MYSQL_THD | thd, |
const char ** | file_var, | ||
unsigned long long * | pos_var | ||
) |
Get binary log position for latest written entry.
thd | Use thread connection handle |
file_var | Pointer to variable that will hold the file name. |
pos_var | Pointer to variable that will hold the file position. |
void * thd_calloc | ( | MYSQL_THD | thd, |
size_t | size | ||
) |
bool thd_check_connection_admin_privilege | ( | MYSQL_THD | thd | ) |
void thd_clear_errors | ( | THD * | thd | ) |
Clear errors from the previous THD.
thd | THD object |
void thd_close_connection | ( | THD * | thd | ) |
Close the socket used by this connection.
thd | THD object |
int thd_connection_has_data | ( | THD * | thd | ) |
Check if there is buffered data on the socket representing the connection.
thd | THD object |
THD * thd_get_current_thd | ( | ) |
Get current THD object from thread local data.
The | THD object for the thread, NULL if not connection thread |
unsigned int thd_get_current_thd_terminology_use_previous | ( | ) |
Return @session.terminology_use_previous for the current THD.
Get socket file descriptor for this connection.
thd | THD object |
Socket | of the connection |
void * thd_get_ha_data | ( | const MYSQL_THD | thd, |
const struct handlerton * | hton | ||
) |
Provide a handler data getter to simplify coding.
MYSQL_SOCKET thd_get_mysql_socket | ( | THD * | thd | ) |
Get MYSQL_SOCKET struct for this connection.
thd | THD object |
MYSQL_SOCKET | struct of the connection |
uint thd_get_net_read_write | ( | THD * | thd | ) |
Get reading/writing on socket from THD object.
thd | THD object |
net.reading_or_writing | value for thread on THD. |
ulong thd_get_net_wait_timeout | ( | THD * | thd | ) |
Get net_wait_timeout for THD object.
thd | THD object |
net_wait_timeout | value for thread on THD |
unsigned int thd_get_num_vcpus | ( | ) |
Interface to get the number of VCPUs.
PSI_thread * thd_get_psi | ( | THD * | thd | ) |
Get reference to Performance Schema object for THD object.
thd | THD object |
Performance | schema object for thread on THD |
void * thd_get_scheduler_data | ( | THD * | thd | ) |
Get reference to scheduler data object.
thd | THD object |
Scheduler | data object on THD |
unsigned long thd_get_thread_id | ( | const MYSQL_THD | thd | ) |
Return the thread id of a user thread.
thd | user thread connection handle |
Get the XID for this connection's transaction.
thd | user thread connection handle |
xid | location where identifier is stored |
void ** thd_ha_data | ( | const MYSQL_THD | thd, |
const struct handlerton * | hton | ||
) |
bool thd_in_active_multi_stmt_transaction | ( | const THD * | thd | ) |
Predicate for determining if connection is in active multi-statement transaction.
int thd_in_lock_tables | ( | const MYSQL_THD | thd | ) |
void thd_inc_row_count | ( | MYSQL_THD | thd | ) |
bool thd_is_transaction_active | ( | THD * | thd | ) |
Support method to check if connection has already started transaction.
thd | Current thread |
true | if connection already started transaction |
int thd_killed | ( | const void * | v_thd | ) |
Check the killed state of a connection.
In MySQL support for the KILL statement is cooperative. The KILL statement only sets a "killed" flag. This function returns the value of that flag. A thread should check it often, especially inside time-consuming loops, and gracefully abort the operation if it is non-zero.
v_thd | user thread connection handle |
0 | the connection is active |
1 | the connection has been killed |
void thd_lock_data | ( | THD * | thd | ) |
Lock data that needs protection in THD object.
thd | THD object |
MYSQL_LEX_STRING * thd_make_lex_string | ( | MYSQL_THD | thd, |
MYSQL_LEX_STRING * | lex_str, | ||
const char * | str, | ||
size_t | size, | ||
int | allocate_lex_string | ||
) |
Create a LEX_STRING in this connection's local memory pool.
thd | user thread connection handle |
lex_str | pointer to LEX_STRING object to be initialized |
str | initializer to be copied into lex_str |
size | length of str, in bytes |
allocate_lex_string | flag: if TRUE, allocate new LEX_STRING object, instead of using lex_str value |
void thd_mark_transaction_to_rollback | ( | MYSQL_THD | thd, |
int | all | ||
) |
Mark transaction to rollback and mark error as fatal to a sub-statement if in sub statement mode.
thd | user thread connection handle |
all | if all != 0, rollback the main transaction |
void * thd_memdup | ( | MYSQL_THD | thd, |
const void * | str, | ||
size_t | size | ||
) |
Call it just when the engine find a transaction should wait another transaction to release a lock.
Interface for Engine to report lock conflict. The caller should guarantee self and thd_wait_for does not be freed, while it is called.
[in] | self | The thd session which is waiting for the lock to release |
[in] | wait_for | The session which is holding the lock |
[in] | may_survive_prepare | true: edge MAY remain even after wait_for session PREPAREs its transaction, false: edge CERTAINLY will be removed before or during PREPARE of transaction run by the wait_for session. |
[in] | self | The thd session which is waiting for the lock to release |
[in] | wait_for | The session which is holding the lock |
char * thd_security_context | ( | MYSQL_THD | thd, |
char * | buffer, | ||
size_t | length, | ||
size_t | max_query_len | ||
) |
Dumps a text description of a thread, its security context (user, host) and the current query.
thd | thread context |
buffer | pointer to preferred result buffer |
length | length of buffer |
max_query_len | how many chars of query to copy (0 for all) |
void thd_set_ha_data | ( | MYSQL_THD | thd, |
const struct handlerton * | hton, | ||
const void * | ha_data | ||
) |
Provide a handler data setter to simplify coding.
void thd_set_kill_status | ( | const MYSQL_THD | thd | ) |
Set the killed status of the current statement.
thd | user thread connection handle |
void thd_set_killed | ( | THD * | thd | ) |
Set the state on connection to killed.
thd | THD object |
void thd_set_net_read_write | ( | THD * | thd, |
uint | val | ||
) |
Set reading/writing on socket, used by SHOW PROCESSLIST.
thd | THD object |
val | Value to set it to (0 or 1) |
void thd_set_not_killable | ( | THD * | thd | ) |
Mark the THD as not killable as it is not currently used by a thread.
thd | THD object |
void thd_set_psi | ( | THD * | thd, |
PSI_thread * | psi | ||
) |
Set reference to Performance Schema object for THD object.
thd | THD object |
psi | Performance schema object for thread |
void thd_set_scheduler_data | ( | THD * | thd, |
void * | data | ||
) |
Set reference to Scheduler data object for THD object.
thd | THD object |
data | Scheduler data object to set on THD |
int thd_sql_command | ( | const MYSQL_THD | thd | ) |
void thd_storage_lock_wait | ( | MYSQL_THD | thd, |
long long | value | ||
) |
void thd_store_globals | ( | THD * | thd | ) |
Set thread specific environment required for thd cleanup in thread pool.
thd | THD object |
char * thd_strdup | ( | MYSQL_THD | thd, |
const char * | str | ||
) |
char * thd_strmake | ( | MYSQL_THD | thd, |
const char * | str, | ||
size_t | size | ||
) |
int thd_tablespace_op | ( | const MYSQL_THD | thd | ) |
long long thd_test_options | ( | const MYSQL_THD | thd, |
long long | test_options | ||
) |
int thd_tx_is_dd_trx | ( | const MYSQL_THD | thd | ) |
int thd_tx_is_read_only | ( | const MYSQL_THD | thd | ) |
int thd_tx_isolation | ( | const MYSQL_THD | thd | ) |
int thd_tx_priority | ( | const MYSQL_THD | thd | ) |
void thd_unlock_data | ( | THD * | thd | ) |
Unlock data that needs protection in THD object.
thd | THD object |
void thd_wait_begin | ( | MYSQL_THD | thd, |
int | wait_type | ||
) |
Interface for MySQL Server, plugins and storage engines to report when they are going to sleep/stall.
This is currently only implemented by by the threadpool and used to have better knowledge of which threads that currently are actively running on CPUs. When not running with TP this makes a call, possibly through a service, to an empty function.
thd_wait_end MUST be called immediately after waking up again.
More info can be found in the TP documentation.
thd | Calling thread context. If nullptr is passed, current_thd is used. |
wait_type | An enum value from the enum thd_wait_type (defined in include/mysql/service_thd_wait.h) but passed as int to preserve compatibility with exported service api. |
void thd_wait_end | ( | MYSQL_THD | thd | ) |
Interface for MySQL Server, plugins and storage engines to report when they waking up from a sleep/stall.
This is currently only implemented by by the threadpool and used to have better knowledge of which threads that currently are actively running on CPUs. When not running with TP this makes a call, possibly through a service, to an empty function.
More info can be found in the TP documentation.
thd | Calling thread context. If nullptr is passed, current_thd is used. |
|
static |
Returns the size of the beginning part of a (multibyte) string, which can fit in max_size bytes.
[in] | cs | charset_info |
[in] | start | pointer to the string |
[in] | original_size | the length of the string (in bytes) |
[in] | max_size | the size of the buffer which needs to hold the string |