MySQL 8.4.0
Source Code Documentation
sql_thd_internal_api.cc File Reference
#include "sql/sql_thd_internal_api.h"
#include <algorithm>
#include "my_config.h"
#include <fcntl.h>
#include <string.h>
#include "m_string.h"
#include "mysql/components/services/bits/psi_stage_bits.h"
#include "pfs_thread_provider.h"
#include <unistd.h>
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_macros.h"
#include "my_psi_config.h"
#include "my_sys.h"
#include "mysql/psi/mysql_file.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/psi/mysql_socket.h"
#include "mysql/thread_type.h"
#include "nulls.h"
#include "sql/binlog.h"
#include "sql/current_thd.h"
#include "sql/mysqld.h"
#include "sql/mysqld_thd_manager.h"
#include "sql/protocol_classic.h"
#include "sql/query_options.h"
#include "sql/rpl_filter.h"
#include "sql/sql_class.h"
#include "sql/sql_lex.h"
#include "sql/sql_parse.h"
#include "sql/system_variables.h"
#include "sql/transaction_info.h"
#include "violite.h"

Functions

THDcreate_internal_thd ()
 
void destroy_internal_thd (THD *thd)
 
void thd_init (THD *thd, char *stack_start)
 Set up various THD data for a new connection. More...
 
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. More...
 
THDcreate_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. More...
 
void destroy_thd (THD *thd, bool clear_pfs_events)
 Cleanup the THD object, remove it from the global list of THDs and delete it. More...
 
void destroy_thd (THD *thd)
 Cleanup the THD object, remove it from the global list of THDs and delete it. More...
 
void thd_set_thread_stack (THD *thd, const char *stack_start)
 Set thread stack in THD object. More...
 
void thd_enter_cond (void *opaque_thd, mysql_cond_t *cond, mysql_mutex_t *mutex, const PSI_stage_info *stage, PSI_stage_info *old_stage, const char *src_function, const char *src_file, int src_line)
 Set thread entering a condition. More...
 
void thd_exit_cond (void *opaque_thd, const PSI_stage_info *stage, const char *src_function, const char *src_file, int src_line)
 Set thread leaving a condition. More...
 
void thd_enter_stage (void *opaque_thd, const PSI_stage_info *new_stage, PSI_stage_info *old_stage, const char *src_function, const char *src_file, int src_line)
 
void thd_set_waiting_for_disk_space (void *opaque_thd, const bool waiting)
 
void thd_increment_bytes_sent (size_t length)
 
void thd_increment_bytes_received (size_t length)
 
partition_infothd_get_work_part_info (THD *thd)
 Returns the partition_info working copy. More...
 
enum_tx_isolation thd_get_trx_isolation (const THD *thd)
 
const CHARSET_INFOthd_charset (THD *thd)
 
LEX_CSTRING thd_query_unsafe (THD *thd)
 Get the current query string for the thread. More...
 
size_t thd_query_safe (THD *thd, char *buf, size_t buflen)
 Get the current query string for the thread. More...
 
int thd_slave_thread (const THD *thd)
 Check if a user thread is a replication slave thread. More...
 
int thd_non_transactional_update (const THD *thd)
 Check if a user thread is running a non-transactional update. More...
 
int thd_binlog_format (const THD *thd)
 Get the user thread's binary logging format. More...
 
bool thd_binlog_filter_ok (const THD *thd)
 Check if binary logging is filtered for thread's current db. More...
 
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. More...
 
enum durability_properties thd_get_durability_property (const THD *thd)
 Gets information on the durability property requested by a thread. More...
 
void thd_get_autoinc (const THD *thd, ulong *off, ulong *inc)
 Get the auto_increment_offset auto_increment_increment. More...
 
size_t thd_get_tmp_table_size (const THD *thd)
 Get the tmp_table_size threshold. More...
 
bool thd_is_strict_mode (const THD *thd)
 Is strict sql_mode set. More...
 
bool thd_is_error (const THD *thd)
 Is an error set in the DA. More...
 
bool is_mysql_datadir_path (const char *path)
 Test a file path whether it is same as mysql data directory path. More...
 
int mysql_tmpfile_path (const char *path, const char *prefix)
 Create a temporary file. More...
 
bool thd_is_bootstrap_thread (THD *thd)
 Check if the server is in the process of being initialized. More...
 
bool thd_is_dd_update_stmt (const THD *thd)
 Is statement updating the data dictionary tables. More...
 
my_thread_id thd_thread_id (const THD *thd)
 

Function Documentation

◆ create_internal_thd()

THD * create_internal_thd ( )

◆ create_thd()

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.

Parameters
enable_pluginsShould dynamic plugin support be enabled?
background_threadIs this a background thread?
boundTrue if bound to a physical thread.
psi_keyInstrumentation key for the thread.
psi_seqnumInstrumentation sequence number for the thread.
Note
Dynamic plugin support is only possible for THDs that are created after the server has initialized properly.
THDs for background threads are currently not added to the global THD list. So they will e.g. not be visible in SHOW PROCESSLIST and the server will not wait for them to terminate during shutdown.

◆ destroy_internal_thd()

void destroy_internal_thd ( THD thd)

◆ destroy_thd() [1/2]

void destroy_thd ( THD thd)

Cleanup the THD object, remove it from the global list of THDs and delete it.

Parameters
thdPointer to THD object.

◆ destroy_thd() [2/2]

void destroy_thd ( THD thd,
bool  clear_pfs_instr 
)

Cleanup the THD object, remove it from the global list of THDs and delete it.

Parameters
thdPointer to THD object.
clear_pfs_instrIf true, then clear thread PFS instrumentations.

◆ 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.

Parameters
pathnull terminated character string
Return values
trueThe path is different from mysql data directory.
falseThe path is same as mysql data directory.

◆ mysql_tmpfile_path()

int mysql_tmpfile_path ( const char *  path,
const char *  prefix 
)

Create a temporary file.

The temporary file is created in a location specified by the parameter path. if path is null, then it will be created on the location given by the mysql server configuration (–tmpdir option). The caller does not need to delete the file, it will be deleted automatically.

Parameters
pathlocation for creating temporary file
prefixprefix for temporary file name
Return values
-1error
>=0a file handle that can be passed to dup or my_close

◆ thd_binlog_filter_ok()

bool thd_binlog_filter_ok ( const THD thd)

Check if binary logging is filtered for thread's current db.

Parameters
thdThread handle
Return values
1the query is not filtered, 0 otherwise.

◆ thd_binlog_format()

int thd_binlog_format ( const THD thd)

Get the user thread's binary logging format.

Parameters
thduser thread
Returns
Value to be used as index into the binlog_format_names array

◆ thd_charset()

const CHARSET_INFO * thd_charset ( THD thd)

◆ thd_enter_cond()

void thd_enter_cond ( void *  opaque_thd,
mysql_cond_t cond,
mysql_mutex_t mutex,
const PSI_stage_info stage,
PSI_stage_info old_stage,
const char *  src_function,
const char *  src_file,
int  src_line 
)

Set thread entering a condition.

This function should be called before putting a thread to wait for a condition. mutex should be held before calling this function. After being waken up, thd_exit_cond should be called.

Parameters
opaque_thdThe thread entering the condition, NULL means current thread
condThe condition the thread is going to wait for
mutexThe mutex associated with the condition, this must be held before call this function
stageThe new process message for the thread
old_stageThe old process message for the thread
src_functionThe caller source function name
src_fileThe caller source file name
src_lineThe caller source line number

◆ thd_enter_stage()

void thd_enter_stage ( void *  opaque_thd,
const PSI_stage_info new_stage,
PSI_stage_info old_stage,
const char *  src_function,
const char *  src_file,
int  src_line 
)

◆ thd_exit_cond()

void thd_exit_cond ( void *  opaque_thd,
const PSI_stage_info stage,
const char *  src_function,
const char *  src_file,
int  src_line 
)

Set thread leaving a condition.

This function should be called after a thread being waken up for a condition.

Parameters
opaque_thdThe thread entering the condition, NULL means current thread
stageThe process message, usually this should be the old process message before calling thd_enter_cond
src_functionThe caller source function name
src_fileThe caller source file name
src_lineThe caller source line number

◆ thd_get_autoinc()

void thd_get_autoinc ( const THD thd,
ulong *  off,
ulong *  inc 
)

Get the auto_increment_offset auto_increment_increment.

Parameters
thdThread object
offauto_increment_offset
incauto_increment_increment

◆ thd_get_durability_property()

enum durability_properties thd_get_durability_property ( const THD thd)

Gets information on the durability property requested by a thread.

Parameters
thdThread handle
Returns
a durability property.

◆ thd_get_tmp_table_size()

size_t thd_get_tmp_table_size ( const THD thd)

Get the tmp_table_size threshold.

Parameters
thdThread object
Returns
Value of currently set tmp_table_size threshold.

◆ thd_get_trx_isolation()

enum_tx_isolation thd_get_trx_isolation ( const THD thd)

◆ thd_get_work_part_info()

partition_info * thd_get_work_part_info ( THD thd)

Returns the partition_info working copy.

Used to see if a table should be created with partitioning.

Parameters
thdthread context
Returns
Pointer to the working copy of partition_info or NULL.

◆ thd_increment_bytes_received()

void thd_increment_bytes_received ( size_t  length)

◆ thd_increment_bytes_sent()

void thd_increment_bytes_sent ( size_t  length)

◆ thd_init() [1/2]

void thd_init ( THD thd,
char *  stack_start 
)

Set up various THD data for a new connection.

Note
PFS instrumentation is not set by this function.
Parameters
thdTHD object
stack_startStart of stack for connection

◆ thd_init() [2/2]

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.

Parameters
thdTHD object
stack_startStart of stack for connection
boundTrue if bound to a physical thread.
psi_keyInstrumentation key for the thread.
psi_seqnumInstrumentation sequence number for the thread.

◆ thd_is_bootstrap_thread()

bool thd_is_bootstrap_thread ( THD thd)

Check if the server is in the process of being initialized.

Check the thread type of the THD. If this is a thread type being used for initializing the DD or the server, return true.

Parameters
thdNeeded since this is an opaque type in the SE.
Return values
trueThe thread is a bootstrap thread.
falseThe thread is not a bootstrap thread.

◆ thd_is_dd_update_stmt()

bool thd_is_dd_update_stmt ( const THD thd)

Is statement updating the data dictionary tables.

The thread switches to the data dictionary tables update context using the dd::Update_dictionary_tables_ctx while updating dictionary tables. If thread is in this context then the method returns true otherwise false. This method is used by the InnoDB while updating the tables to mark transaction as DDL if this method returns true.

Parameters
thdThread handle.
Return values
trueUpdates data dictionary tables.
falseOtherwise.

◆ thd_is_error()

bool thd_is_error ( const THD thd)

Is an error set in the DA.

Needed by InnoDB to catch behavior modified by an error handler.

Parameters
thdThread object
Returns
True if THD::is_error() returns true.
Return values
trueAn error has been raised.
falseNo error has been raised.

◆ thd_is_strict_mode()

bool thd_is_strict_mode ( const THD thd)

Is strict sql_mode set.

Needed by InnoDB.

Parameters
thdThread object
Returns
True if sql_mode has strict mode (all or trans).
Return values
truesql_mode has strict mode (all or trans).
falsesql_mode has not strict mode (all or trans).

◆ thd_non_transactional_update()

int thd_non_transactional_update ( const THD thd)

Check if a user thread is running a non-transactional update.

Parameters
thduser thread
Return values
0the user thread is not running a non-transactional update
1the user thread is running a non-transactional update

◆ thd_query_safe()

size_t thd_query_safe ( THD thd,
char *  buf,
size_t  buflen 
)

Get the current query string for the thread.

Parameters
thdThe MySQL internal thread pointer
bufBuffer where the query string will be copied
buflenLength of the buffer
Returns
Length of the query
Note
This function is thread safe as the query string is accessed under mutex protection and the string is copied into the provided buffer.
See also
thd_query_unsafe().

◆ thd_query_unsafe()

LEX_CSTRING thd_query_unsafe ( THD thd)

Get the current query string for the thread.

Parameters
thdThe MySQL internal thread pointer
Returns
query string and length. May be non-null-terminated.
Note
This function is not thread safe and should only be called from the thread owning thd.
See also
thd_query_safe().

◆ thd_set_thread_stack()

void thd_set_thread_stack ( THD thd,
const char *  stack_start 
)

Set thread stack in THD object.

Parameters
thdThread object
stack_startStart of stack to set in THD object

◆ thd_set_waiting_for_disk_space()

void thd_set_waiting_for_disk_space ( void *  opaque_thd,
const bool  waiting 
)

◆ thd_slave_thread()

int thd_slave_thread ( const THD thd)

Check if a user thread is a replication slave thread.

Parameters
thduser thread
Return values
0the user thread is not a replication slave thread
1the user thread is a replication slave thread

◆ 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.

Parameters
thdThread handle
Return values
1the query may generate row changes, 0 otherwise.

◆ thd_thread_id()

my_thread_id thd_thread_id ( const THD thd)