MySQL 8.0.31
Source Code Documentation
Runtime Environment
Collaboration diagram for Runtime Environment:

Modules

 Event Scheduler
 
 Mysys - low level utilities for MySQL
 
 Serialized Dictionary Information
 Code to serialize and deserialize data dictionary objects, and for storing and retrieving the serialized representation from files or tablespaces.
 
 Server time functions
 
 Stored Routines
 

Classes

class  Kill_non_super_conn
 This class implements callback function used by killall_non_super_threads to kill all threads that do not have either SYSTEM_VARIABLES_ADMIN + CONNECTION_ADMIN privileges or legacy SUPER privilege. More...
 
class  Parser_oom_handler
 

Macros

#define SP_COM_STRING(LP)
 
#define MY_YACC_INIT   1000
 
#define MY_YACC_MAX   32000
 

Functions

static void sql_kill (THD *thd, my_thread_id id, bool only_kill_query)
 
bool command_satisfy_acl_cache_requirement (unsigned command)
 
bool all_tables_not_ok (THD *thd, TABLE_LIST *tables)
 Returns true if all tables should be ignored. More...
 
bool is_normal_transaction_boundary_stmt (enum_sql_command sql_cmd)
 This function checks if the sql_command is one that identifies the boundaries (begin, end or savepoint) of a transaction. More...
 
bool is_xa_transaction_boundary_stmt (enum_sql_command sql_cmd)
 This function checks if the sql_command is one that identifies the boundaries (begin, end or savepoint) of an XA transaction. More...
 
bool check_database_filters (THD *thd, const char *db, enum_sql_command sql_cmd)
 Checks whether the event for the given database, db, should be ignored or not. More...
 
bool some_non_temp_table_to_be_updated (THD *thd, TABLE_LIST *tables)
 
bool stmt_causes_implicit_commit (const THD *thd, uint mask)
 Returns whether the command in thd->lex->sql_command should cause an implicit commit. More...
 
static bool run_post_replication_filters_actions (THD *thd)
 Iterates over all post replication filter actions registered and executes them. More...
 
static bool check_and_report_require_row_format_violation (THD *thd)
 This function determines if the current statement parsed violates the require_row_format check. More...
 
void init_sql_command_flags ()
 
bool sqlcom_can_generate_row_events (enum enum_sql_command command)
 
bool is_update_query (enum enum_sql_command command)
 
bool is_explainable_query (enum enum_sql_command command)
 
bool is_log_table_write_query (enum enum_sql_command command)
 Check if a sql command is allowed to write to log tables. More...
 
static bool sqlcom_needs_autocommit_off (const LEX *lex)
 Check if statement (typically DDL) needs auto-commit mode temporarily turned off. More...
 
void execute_init_command (THD *thd, LEX_STRING *init_command, mysql_rwlock_t *var_lock)
 
void free_items (Item *item)
 
void cleanup_items (Item *item)
 This works because items are allocated with (*THR_MALLOC)->Alloc(). More...
 
void bind_fields (Item *first)
 Bind Item fields to Field objects. More...
 
bool do_command (THD *thd)
 Read one command from connection and execute it (query or simple command). More...
 
static bool deny_updates_if_read_only_option (THD *thd, TABLE_LIST *all_tables)
 Determine if an attempt to update a non-temporary table while the read-only option was enabled has been made. More...
 
static void check_secondary_engine_statement (THD *thd, Parser_state *parser_state, const char *query_string, size_t query_length)
 Check if a statement should be restarted in another storage engine, and restart the statement if needed. More...
 
void set_gr_incoming_connection (gr_incoming_connection_cb x)
 
gr_incoming_connection_cb get_gr_incoming_connection ()
 
void call_gr_incoming_connection_cb (THD *thd, int fd, SSL *ssl_ctx)
 
static void copy_bind_parameter_values (THD *thd, PS_PARAM *parameters, unsigned long count)
 Deep copy the name and value of named parameters into the THD memory. More...
 
bool dispatch_command (THD *thd, const COM_DATA *com_data, enum enum_server_command command)
 Perform one connection-level (COM_XXXX) command. More...
 
bool shutdown (THD *thd, enum mysql_enum_shutdown_level level)
 Shutdown the mysqld server. More...
 
int prepare_schema_table (THD *thd, LEX *lex, Table_ident *table_ident, enum enum_schema_tables schema_table_idx)
 Create a TABLE_LIST object for an INFORMATION_SCHEMA table. More...
 
bool alloc_query (THD *thd, const char *packet, size_t packet_length)
 Read query from packet and store in thd->query. More...
 
static bool sp_process_definer (THD *thd)
 
static bool lock_tables_open_and_lock_tables (THD *thd, TABLE_LIST *tables)
 Auxiliary call that opens and locks tables for LOCK TABLES statement and initializes the list of locked tables. More...
 
static void binlog_gtid_end_transaction (THD *thd)
 This is a wrapper for MYSQL_BIN_LOG::gtid_end_transaction. More...
 
int mysql_execute_command (THD *thd, bool first_level)
 Execute command saved in thd and lex->sql_command. More...
 
bool show_precheck (THD *thd, LEX *lex, bool lock)
 Do special checking for SHOW statements. More...
 
bool my_yyoverflow (short **yyss, YYSTYPE **yyvs, YYLTYPE **yyls, ulong *yystacksize)
 
void mysql_reset_thd_for_next_command (THD *thd)
 Reset the part of THD responsible for the state of command processing. More...
 
void dispatch_sql_command (THD *thd, Parser_state *parser_state)
 Parse an SQL command from a text string and pass the resulting AST to the query executor. More...
 
bool mysql_test_parse_for_slave (THD *thd)
 Usable by the replication SQL thread only: just parse a query to know if it can be ignored because of replicate-*-table rules. More...
 
void add_to_list (SQL_I_List< ORDER > &list, ORDER *order)
 save order by and tables in own lists. More...
 
static bool reparse_common_table_expr (THD *thd, const char *text, size_t text_length, uint text_offset, PT_subquery **node)
 Produces a PT_subquery object from a subquery's text. More...
 
TABLE_LISTnest_join (THD *thd, Query_block *select, TABLE_LIST *embedding, mem_root_deque< TABLE_LIST * > *jlist, size_t table_cnt, const char *legend)
 Plumbing for nest_last_join, q.v. More...
 
bool push_new_name_resolution_context (Parse_context *pc, TABLE_LIST *left_op, TABLE_LIST *right_op)
 Push a new name resolution context for a JOIN ... ON clause to the context stack of a query block. More...
 
void add_join_on (TABLE_LIST *b, Item *expr)
 Add an ON condition to the second operand of a JOIN ... ON. More...
 
const CHARSET_INFOget_bin_collation (const CHARSET_INFO *cs)
 
static uint kill_one_thread (THD *thd, my_thread_id id, bool only_kill_query)
 kill on thread. More...
 
void killall_non_super_threads (THD *thd)
 
bool prepare_index_and_data_dir_path (THD *thd, const char **data_file_name, const char **index_file_name, const char *table_name)
 prepares the index and data directory path. More...
 
int append_file_to_dir (THD *thd, const char **filename_ptr, const char *table_name)
 If pointer is not a null pointer, append filename to it. More...
 
Comp_creatorcomp_eq_creator (bool invert)
 
Comp_creatorcomp_equal_creator (bool invert)
 
Comp_creatorcomp_ge_creator (bool invert)
 
Comp_creatorcomp_gt_creator (bool invert)
 
Comp_creatorcomp_le_creator (bool invert)
 
Comp_creatorcomp_lt_creator (bool invert)
 
Comp_creatorcomp_ne_creator (bool invert)
 
Itemall_any_subquery_creator (Item *left_expr, chooser_compare_func_creator cmp, bool all, Query_block *query_block)
 Construct ALL/ANY/SOME subquery Item. More...
 
void create_table_set_open_action_and_adjust_tables (LEX *lex)
 Set proper open mode and table type for element representing target table of CREATE TABLE statement, also adjust statement table list if necessary. More...
 
void get_default_definer (THD *thd, LEX_USER *definer)
 Set the specified definer to the default value, which is the current user in the thread. More...
 
LEX_USERcreate_default_definer (THD *thd)
 Create default definer for the specified THD. More...
 
LEX_USERget_current_user (THD *thd, LEX_USER *user)
 Returns information about user or current user. More...
 
static bool check_string_byte_length (const LEX_CSTRING &str, const char *err_msg, size_t max_byte_length)
 Check that byte length of a string does not exceed some limit. More...
 
bool check_string_char_length (const LEX_CSTRING &str, const char *err_msg, size_t max_char_length, const CHARSET_INFO *cs, bool no_error)
 
int test_if_data_home_dir (const char *dir)
 
bool check_host_name (const LEX_CSTRING &str)
 Check that host name string is valid. More...
 
bool parse_sql (THD *thd, Parser_state *parser_state, Object_creation_ctx *creation_ctx)
 Transform an SQL statement into an AST that is ready for resolving, using the supplied parser state and object creation context. More...
 
static const std::string & Command_names::translate (const System_variables &sysvars)
 Given a system_variable object, returns the string to use for m_replace_com, according to the setting of terminology_use_previous stored in the object. More...
 
static const std::string & Command_names::str_session (enum_server_command cmd)
 Return a description string for a given enum_server_command. More...
 
static const std::string & Command_names::str_global (enum_server_command cmd)
 Return a description string for a given enum_server_command. More...
 
void THD::reset_for_next_command ()
 
bool Alter_info::add_field (THD *thd, const LEX_STRING *field_name, enum enum_field_types type, const char *length, const char *decimal, uint type_modifier, Item *default_value, Item *on_update_value, LEX_CSTRING *comment, const char *change, List< String > *interval_list, const CHARSET_INFO *cs, bool has_explicit_collation, uint uint_geom_type, Value_generator *gcol_info, Value_generator *default_val_expr, const char *opt_after, std::optional< gis::srid_t > srid, Sql_check_constraint_spec_list *check_cons_list, dd::Column::enum_hidden_type hidden, bool is_array=false)
 Store field definition for create. More...
 
bool PT_common_table_expr::make_subquery_node (THD *thd, PT_subquery **node)
 
bool Query_block::find_common_table_expr (THD *thd, Table_ident *table_id, TABLE_LIST *tl, Parse_context *pc, bool *found)
 Tries to match an identifier to the CTEs in scope; if matched, it modifies *table_name, *tl', and the matched with-list-element. More...
 
bool PT_with_clause::lookup (TABLE_LIST *tl, PT_common_table_expr **found)
 Looks up a table reference into the list of CTEs. More...
 
bool PT_common_table_expr::match_table_ref (TABLE_LIST *tl, bool in_self, bool *found)
 
TABLE_LISTQuery_block::add_table_to_list (THD *thd, Table_ident *table, const char *alias, ulong table_options, thr_lock_type flags=TL_UNLOCK, enum_mdl_type mdl_type=MDL_SHARED_READ, List< Index_hint > *hints=nullptr, List< String > *partition_names=nullptr, LEX_STRING *option=nullptr, Parse_context *pc=nullptr)
 Add a table to list of used tables. More...
 
bool Query_block::init_nested_join (THD *thd)
 Initialize a new table list for a nested join. More...
 
TABLE_LISTQuery_block::end_nested_join ()
 End a nested join table list. More...
 
TABLE_LISTQuery_block::nest_last_join (THD *thd, size_t table_cnt=2)
 Nest last join operations. More...
 
bool Query_block::add_joined_table (TABLE_LIST *table)
 Add a table to the current join list. More...
 
void Query_block::set_lock_for_table (const Lock_descriptor &descriptor, TABLE_LIST *table)
 
void Query_block::set_lock_for_tables (thr_lock_type lock_type)
 Set lock for all tables in current query block. More...
 

Variables

uint sql_command_flags [SQLCOM_END+1]
 Mark all commands that somehow changes a table. More...
 
uint server_command_flags [COM_END+1]
 
static std::atomic< gr_incoming_connection_cbcom_incoming_gr_stream_cb
 
static const std::string Command_names::m_names []
 Array indexed by enum_server_command, where each element is a description string. More...
 
static const std::string Command_names::m_replace_str {"Register Slave"}
 Name to use when compatibility is enabled. More...
 

Detailed Description

Macro Definition Documentation

◆ MY_YACC_INIT

#define MY_YACC_INIT   1000

◆ MY_YACC_MAX

#define MY_YACC_MAX   32000

◆ SP_COM_STRING

#define SP_COM_STRING (   LP)
Value:
((LP)->sql_command == SQLCOM_CREATE_SPFUNCTION || \
(LP)->sql_command == SQLCOM_ALTER_FUNCTION || \
(LP)->sql_command == SQLCOM_SHOW_CREATE_FUNC || \
(LP)->sql_command == SQLCOM_DROP_FUNCTION \
? "FUNCTION" \
: "PROCEDURE")
@ SQLCOM_SHOW_CREATE_FUNC
Definition: my_sqlcommand.h:142
@ SQLCOM_ALTER_FUNCTION
Definition: my_sqlcommand.h:140
@ SQLCOM_CREATE_SPFUNCTION
Definition: my_sqlcommand.h:136
@ SQLCOM_DROP_FUNCTION
Definition: my_sqlcommand.h:89

Function Documentation

◆ add_field()

bool Alter_info::add_field ( THD thd,
const LEX_STRING field_name,
enum enum_field_types  type,
const char *  length,
const char *  decimals,
uint  type_modifier,
Item default_value,
Item on_update_value,
LEX_CSTRING comment,
const char *  change,
List< String > *  interval_list,
const CHARSET_INFO cs,
bool  has_explicit_collation,
uint  uint_geom_type,
Value_generator gcol_info,
Value_generator default_val_expr,
const char *  opt_after,
std::optional< gis::srid_t srid,
Sql_check_constraint_spec_list col_check_const_spec_list,
dd::Column::enum_hidden_type  hidden,
bool  is_array = false 
)

Store field definition for create.

Parameters
thdThe thread handler.
field_nameThe field name.
typeThe type of the field.
lengthThe length of the field or NULL.
decimalsThe length of a decimal part or NULL.
type_modifierType modifiers & constraint flags of the field.
default_valueThe default value or NULL.
on_update_valueThe ON UPDATE expression or NULL.
commentThe comment.
changeThe old column name (if renaming) or NULL.
interval_listThe list of ENUM/SET values or NULL.
csThe character set of the field.
has_explicit_collationColumn has an explicit COLLATE attribute.
uint_geom_typeThe GIS type of the field.
gcol_infoThe generated column data or NULL.
default_val_exprThe expression for generating default values, if there is one, or nullptr.
opt_afterThe name of the field to add after or the
See also
first_keyword pointer to insert first.
Parameters
sridThe SRID for this column (only relevant if this is a geometry column).
col_check_const_spec_listList of column check constraints.
hiddenColumn hidden type.
is_arrayWhether it's a typed array field
Returns
Return 0 if ok

◆ add_join_on()

void add_join_on ( TABLE_LIST b,
Item expr 
)

Add an ON condition to the second operand of a JOIN ... ON.

Add an ON condition to the right operand of a JOIN ... ON clause.

Parameters
bthe second operand of a JOIN ... ON
exprthe condition to be added to the ON clause

◆ add_joined_table()

bool Query_block::add_joined_table ( TABLE_LIST table)

Add a table to the current join list.

The function puts a table in front of the current join list of Query_block object. Thus, joined tables are put into this list in the reverse order (the most outer join operation follows first).

Parameters
tableThe table to add.
Returns
false if success, true if error (OOM).

◆ add_table_to_list()

TABLE_LIST * Query_block::add_table_to_list ( THD thd,
Table_ident table_name,
const char *  alias,
ulong  table_options,
thr_lock_type  lock_type = TL_UNLOCK,
enum_mdl_type  mdl_type = MDL_SHARED_READ,
List< Index_hint > *  index_hints_arg = nullptr,
List< String > *  partition_names = nullptr,
LEX_STRING option = nullptr,
Parse_context pc = nullptr 
)

Add a table to list of used tables.

Parameters
thdCurrent session.
table_nameTable to add
aliasalias for table (or null if no alias)
table_optionsA set of the following bits:
  • TL_OPTION_UPDATING : Table will be updated
  • TL_OPTION_FORCE_INDEX : Force usage of index
  • TL_OPTION_ALIAS : an alias in multi table DELETE
lock_typeHow table should be locked
mdl_typeType of metadata lock to acquire on the table.
index_hints_arga list of index hints(FORCE/USE/IGNORE INDEX).
partition_namesList to carry partition names from PARTITION (...) clause in statement
optionUsed by cache index
pcCurrent parsing context, if available.
Returns
Pointer to TABLE_LIST element added to the total table list
Return values
0Error

◆ add_to_list()

void add_to_list ( SQL_I_List< ORDER > &  list,
ORDER order 
)

save order by and tables in own lists.

◆ all_any_subquery_creator()

Item * all_any_subquery_creator ( Item left_expr,
chooser_compare_func_creator  cmp,
bool  all,
Query_block query_block 
)

Construct ALL/ANY/SOME subquery Item.

Parameters
left_exprpointer to left expression
cmpcompare function creator
alltrue if we create ALL subquery
query_blockpointer on parsed subquery structure
Returns
constructed Item (or 0 if out of memory)

◆ all_tables_not_ok()

bool all_tables_not_ok ( THD thd,
TABLE_LIST tables 
)

Returns true if all tables should be ignored.

◆ alloc_query()

bool alloc_query ( THD thd,
const char *  packet,
size_t  packet_length 
)

Read query from packet and store in thd->query.

Used in COM_QUERY and COM_STMT_PREPARE.

Sets the following THD variables:

  • query
  • query_length
Return values
falseok
trueerror; In this case thd->fatal_error is set

◆ append_file_to_dir()

int append_file_to_dir ( THD thd,
const char **  filename_ptr,
const char *  table_name 
)

If pointer is not a null pointer, append filename to it.

◆ bind_fields()

void bind_fields ( Item first)

Bind Item fields to Field objects.

Parameters
firstPointer to first item, follow "next" chain to visit all items

◆ binlog_gtid_end_transaction()

static void binlog_gtid_end_transaction ( THD thd)
inlinestatic

This is a wrapper for MYSQL_BIN_LOG::gtid_end_transaction.

For normal statements, the function gtid_end_transaction is called in the commit handler. However, if the statement is filtered out or not written to the binary log, the commit handler is not invoked. Therefore, this wrapper calls gtid_end_transaction in case the current statement is committing but was not written to the binary log. (The function gtid_end_transaction ensures that gtid-related end-of-transaction operations are performed; this includes generating an empty transaction and calling Gtid_state::update_gtids_impl.)

Parameters
thdThread (session) context.

◆ call_gr_incoming_connection_cb()

void call_gr_incoming_connection_cb ( THD thd,
int  fd,
SSL *  ssl_ctx 
)

◆ check_and_report_require_row_format_violation()

static bool check_and_report_require_row_format_violation ( THD thd)
static

This function determines if the current statement parsed violates the require_row_format check.

Given a parsed context within the THD object, this function will infer whether the require row format check is violated or not. If it is, this function returns true, false otherwise. Note that this function can be called from both, normal sessions and replication applier, execution paths.

Parameters
thdThe session context holding the parsed statement.
Returns
true if there was a require row format validation failure.
false if the check was successful, meaning no require row format validation failure.

◆ check_database_filters()

bool check_database_filters ( THD thd,
const char *  db,
enum_sql_command  sql_cmd 
)
inline

Checks whether the event for the given database, db, should be ignored or not.

This is done by checking whether there are active rules in ignore_db or in do_db containers. If there are, then check if there is a match, if not then check the wild_do rules.

NOTE: This means that when using this function replicate-do-db and replicate-ignore-db take precedence over wild do rules.

Parameters
thdThread handle.
dbDatabase name used while evaluating the filtering rules.
sql_cmdRepresents the current query that needs to be verified against the database filter rules.
Returns
true Query should not be filtered out from the execution. false Query should be filtered out from the execution.

◆ check_host_name()

bool check_host_name ( const LEX_CSTRING str)

Check that host name string is valid.

Parameters
[in]strstring to be checked
Returns
Operation status
Return values
falsehost name is ok
truehost name string is longer than max_length or has invalid symbols

◆ check_secondary_engine_statement()

static void check_secondary_engine_statement ( THD thd,
Parser_state parser_state,
const char *  query_string,
size_t  query_length 
)
static

Check if a statement should be restarted in another storage engine, and restart the statement if needed.

Parameters
thdthe session
parser_statethe parser state
query_stringthe query to reprepare and execute
query_lengththe length of the query

◆ check_string_byte_length()

static bool check_string_byte_length ( const LEX_CSTRING str,
const char *  err_msg,
size_t  max_byte_length 
)
static

Check that byte length of a string does not exceed some limit.

Parameters
strstring to be checked
err_msgerror message to be displayed if the string is too long
max_byte_lengthmax length
Return values
falsethe passed string is not longer than max_length
truethe passed string is longer than max_length

NOTE The function is not used in existing code but can be useful later?

◆ check_string_char_length()

bool check_string_char_length ( const LEX_CSTRING str,
const char *  err_msg,
size_t  max_char_length,
const CHARSET_INFO cs,
bool  no_error 
)

◆ cleanup_items()

void cleanup_items ( Item item)

This works because items are allocated with (*THR_MALLOC)->Alloc().

Note
The function also handles null pointers (empty list).

◆ command_satisfy_acl_cache_requirement()

bool command_satisfy_acl_cache_requirement ( unsigned  command)

◆ comp_eq_creator()

Comp_creator * comp_eq_creator ( bool  invert)

◆ comp_equal_creator()

Comp_creator * comp_equal_creator ( bool  invert)

◆ comp_ge_creator()

Comp_creator * comp_ge_creator ( bool  invert)

◆ comp_gt_creator()

Comp_creator * comp_gt_creator ( bool  invert)

◆ comp_le_creator()

Comp_creator * comp_le_creator ( bool  invert)

◆ comp_lt_creator()

Comp_creator * comp_lt_creator ( bool  invert)

◆ comp_ne_creator()

Comp_creator * comp_ne_creator ( bool  invert)

◆ copy_bind_parameter_values()

static void copy_bind_parameter_values ( THD thd,
PS_PARAM parameters,
unsigned long  count 
)
static

Deep copy the name and value of named parameters into the THD memory.

We need to do this since the packet bytes will go away during query processing. It doesn't need to be done for the unnamed ones since they're being copied by and into Item_param. So we don't want to duplicate this.

See also
Item_param
Parameters
thdthe thread to copy the parameters to.
parametersthe values to copy
countthe number of parameters to copy

◆ create_default_definer()

LEX_USER * create_default_definer ( THD thd)

Create default definer for the specified THD.

Parameters
[in]thdthread handler
Returns
  • On success, return a valid pointer to the created and initialized LEX_USER, which contains definer information.
  • On error, return 0.

◆ create_table_set_open_action_and_adjust_tables()

void create_table_set_open_action_and_adjust_tables ( LEX lex)

Set proper open mode and table type for element representing target table of CREATE TABLE statement, also adjust statement table list if necessary.

◆ deny_updates_if_read_only_option()

static bool deny_updates_if_read_only_option ( THD thd,
TABLE_LIST all_tables 
)
static

Determine if an attempt to update a non-temporary table while the read-only option was enabled has been made.

This is a helper function to mysql_execute_command.

Note
SQLCOM_UPDATE_MULTI is an exception and delt with elsewhere.
See also
mysql_execute_command
Returns
Status code
Return values
trueThe statement should be denied.
falseThe statement isn't updating any relevant tables.

◆ dispatch_command()

bool dispatch_command ( THD thd,
const COM_DATA com_data,
enum enum_server_command  command 
)

Perform one connection-level (COM_XXXX) command.

Parameters
thdconnection handle
commandtype of command to perform
com_datacom_data union to store the generated command
Return values
0ok
1request of thread shutdown, i. e. if command is COM_QUIT

Clear the set of flags that are expected to be cleared at the beginning of each command.

Enforce password expiration for all RPC commands, except the following:

COM_QUERY/COM_STMT_PREPARE and COM_STMT_EXECUTE do a more fine-grained check later. COM_STMT_CLOSE and COM_STMT_SEND_LONG_DATA don't return anything. COM_PING only discloses information that the server is running, and that's available through other means. COM_QUIT should work even for expired statements.

◆ dispatch_sql_command()

void dispatch_sql_command ( THD thd,
Parser_state parser_state 
)

Parse an SQL command from a text string and pass the resulting AST to the query executor.

Parameters
thdCurrent session.
parser_stateParser state.

◆ do_command()

bool do_command ( THD thd)

Read one command from connection and execute it (query or simple command).

This function is called in loop from thread function.

For profiling to work, it must never be called recursively.

Return values
0success
1request of thread shutdown (see dispatch_command() description)

◆ end_nested_join()

TABLE_LIST * Query_block::end_nested_join ( )

End a nested join table list.

The function returns to the previous join nest level. If the current level contains only one member, the function moves it one level up, eliminating the nest.

Returns
  • Pointer to TABLE_LIST element added to the total table list, if success
  • 0, otherwise

◆ execute_init_command()

void execute_init_command ( THD thd,
LEX_STRING init_command,
mysql_rwlock_t var_lock 
)

◆ find_common_table_expr()

bool Query_block::find_common_table_expr ( THD thd,
Table_ident table_name,
TABLE_LIST tl,
Parse_context pc,
bool *  found 
)
private

Tries to match an identifier to the CTEs in scope; if matched, it modifies *table_name, *tl', and the matched with-list-element.

Parameters
thdThread handler
[out]table_nameIdentifier
[in,out]tlTABLE_LIST for the identifier
pcCurrent parsing context, if available
[out]foundIs set to true if found.
Returns
true if error (OOM).

◆ free_items()

void free_items ( Item item)

◆ get_bin_collation()

const CHARSET_INFO * get_bin_collation ( const CHARSET_INFO cs)

◆ get_current_user()

LEX_USER * get_current_user ( THD thd,
LEX_USER user 
)

Returns information about user or current user.

Parameters
[in]thdthread handler
[in]useruser
Returns
  • On success, return a valid pointer to initialized LEX_USER, which contains user information.
  • On error, return 0.

◆ get_default_definer()

void get_default_definer ( THD thd,
LEX_USER definer 
)

Set the specified definer to the default value, which is the current user in the thread.

Parameters
[in]thdthread handler
[out]definerdefiner

◆ get_gr_incoming_connection()

gr_incoming_connection_cb get_gr_incoming_connection ( )

◆ init_nested_join()

bool Query_block::init_nested_join ( THD thd)

Initialize a new table list for a nested join.

The function initializes a structure of the TABLE_LIST type for a nested join. It sets up its nested join list as empty. The created structure is added to the front of the current join list in the Query_block object. Then the function changes the current nest level for joins to refer to the newly created empty list after having saved the info on the old level in the initialized structure.

Parameters
thdcurrent thread
Return values
0if success
1otherwise

◆ init_sql_command_flags()

void init_sql_command_flags ( void  )

ACL DDLs do not access data-dictionary tables. However, they still need to be marked to avoid autocommit. This is necessary because code which saves GTID state or slave state in the system tables at commit time does statement commit on low-level (see System_table_access::close_table()) and thus can pre-maturely commit DDL otherwise.

Some statements doesn't if the ACL CACHE is disabled using the –skip-grant-tables server option.

◆ is_explainable_query()

bool is_explainable_query ( enum enum_sql_command  command)

◆ is_log_table_write_query()

bool is_log_table_write_query ( enum enum_sql_command  command)

Check if a sql command is allowed to write to log tables.

Parameters
commandThe SQL command
Returns
true if writing is allowed

◆ is_normal_transaction_boundary_stmt()

bool is_normal_transaction_boundary_stmt ( enum enum_sql_command  command)

This function checks if the sql_command is one that identifies the boundaries (begin, end or savepoint) of a transaction.

Note
this is used for replication purposes.
Parameters
commandThe parsed SQL_COMM to check.
Returns
true if this is either a BEGIN, COMMIT, SAVEPOINT, ROLLBACK, ROLLBACK_TO_SAVEPOINT.
false any other SQL command.

◆ is_update_query()

bool is_update_query ( enum enum_sql_command  command)

◆ is_xa_transaction_boundary_stmt()

bool is_xa_transaction_boundary_stmt ( enum enum_sql_command  command)

This function checks if the sql_command is one that identifies the boundaries (begin, end or savepoint) of an XA transaction.

It does not consider PREPARE statements.

Note
this is used for replication purposes.
Parameters
commandThe parsed SQL_COMM to check.
Returns
true if this is either a XA_START, XA_END, XA_COMMIT, XA_ROLLBACK.
false any other SQL command.

◆ kill_one_thread()

static uint kill_one_thread ( THD thd,
my_thread_id  id,
bool  only_kill_query 
)
static

kill on thread.

Parameters
thdThread class
idThread id
only_kill_queryShould it kill the query or the connection
Note
This is written such that we have a short lock on LOCK_thd_list

◆ killall_non_super_threads()

void killall_non_super_threads ( THD thd)

◆ lock_tables_open_and_lock_tables()

static bool lock_tables_open_and_lock_tables ( THD thd,
TABLE_LIST tables 
)
static

Auxiliary call that opens and locks tables for LOCK TABLES statement and initializes the list of locked tables.

Parameters
thdThread context.
tablesList of tables to be locked.
Returns
false in case of success, true in case of error.

◆ lookup()

bool PT_with_clause::lookup ( TABLE_LIST tl,
PT_common_table_expr **  found 
)

Looks up a table reference into the list of CTEs.

Parameters
tlTable reference to look up
[out]foundIs set to true/false if found or not
Returns
true if error

◆ make_subquery_node()

bool PT_common_table_expr::make_subquery_node ( THD thd,
PT_subquery **  node 
)
Parameters
thdThread handler
[out]nodePT_subquery
Returns
a PT_subquery to attach to a table reference for this CTE

◆ match_table_ref()

bool PT_common_table_expr::match_table_ref ( TABLE_LIST tl,
bool  in_self,
bool *  found 
)
Parameters
tlTable reference to match
in_selfIf this is a recursive reference
[out]foundIs set to true/false if matches or not
Returns
true if error

◆ my_yyoverflow()

bool my_yyoverflow ( short **  yyss,
YYSTYPE **  yyvs,
YYLTYPE **  yyls,
ulong *  yystacksize 
)

◆ mysql_execute_command()

int mysql_execute_command ( THD thd,
bool  first_level 
)

Execute command saved in thd and lex->sql_command.

Parameters
thdThread handle
first_levelwhether invocation of the mysql_execute_command() is a top level query or sub query. At the highest level, first_level value is true. Stored procedures can execute sub queries. In such cases first_level (recursive mysql_execute_command() call) will be false.
Return values
falseOK
trueError

◆ mysql_reset_thd_for_next_command()

void mysql_reset_thd_for_next_command ( THD thd)

Reset the part of THD responsible for the state of command processing.

This needs to be called before execution of every statement (prepared or conventional). It is not called by substatements of routines.

◆ mysql_test_parse_for_slave()

bool mysql_test_parse_for_slave ( THD thd)

Usable by the replication SQL thread only: just parse a query to know if it can be ignored because of replicate-*-table rules.

Return values
0cannot be ignored
1can be ignored

◆ nest_join()

TABLE_LIST * nest_join ( THD thd,
Query_block select,
TABLE_LIST embedding,
mem_root_deque< TABLE_LIST * > *  jlist,
size_t  table_cnt,
const char *  legend 
)

Plumbing for nest_last_join, q.v.

◆ nest_last_join()

TABLE_LIST * Query_block::nest_last_join ( THD thd,
size_t  table_cnt = 2 
)

Nest last join operations.

The function nest last table_cnt join operations as if they were the components of a cross join operation.

Parameters
thdcurrent thread
table_cnt2 for regular joins: t1 JOIN t2. N for the MySQL join-like extension: (t1, t2, ... tN).
Returns
Pointer to TABLE_LIST element created for the new nested join
Return values
0Error

◆ parse_sql()

bool parse_sql ( THD thd,
Parser_state parser_state,
Object_creation_ctx creation_ctx 
)

Transform an SQL statement into an AST that is ready for resolving, using the supplied parser state and object creation context.

This is a wrapper() for THD::sql_parser() and should generally be used for AST construction.

The function may optionally generate a query digest, invoke this function as follows:

  THD *thd = ...;
  const char *query_text = ...;
  uint query_length = ...;
  Object_creation_ctx *ctx = ...;
  bool rc;

  Parser_state parser_state;
  if (parser_state.init(thd, query_text, query_length)
  {
    ... handle error
  }

  parser_state.m_input.m_has_digest= true;
  parser_state.m_input.m_compute_digest= true;

  rc= parse_sql(the, &parser_state, ctx);
  if (! rc)
  {
    unsigned char md5[MD5_HASH_SIZE];
    char digest_text[1024];
    bool truncated;
    const sql_digest_storage *digest= & thd->m_digest->m_digest_storage;

    compute_digest_md5(digest, & md5[0]);
    compute_digest_text(digest, & digest_text[0], sizeof(digest_text), &
truncated);
  }
Parameters
thdThread context.
parser_stateParser state.
creation_ctxObject creation context.
Returns
Error status.
Return values
falseon success.
trueon parsing error.

◆ prepare_index_and_data_dir_path()

bool prepare_index_and_data_dir_path ( THD thd,
const char **  data_file_name,
const char **  index_file_name,
const char *  table_name 
)

prepares the index and data directory path.

Parameters
thdThread handle
data_file_namePathname for data directory
index_file_namePathname for index directory
table_nameTable name to be appended to the pathname specified
Returns
false success
true An error occurred

◆ prepare_schema_table()

int prepare_schema_table ( THD thd,
LEX lex,
Table_ident table_ident,
enum enum_schema_tables  schema_table_idx 
)

Create a TABLE_LIST object for an INFORMATION_SCHEMA table.

This function is used in the parser to convert a SHOW or DESCRIBE table_name command to a SELECT from INFORMATION_SCHEMA. It prepares a Query_block and a TABLE_LIST object to represent the given command as a SELECT parse tree.

Parameters
thdthread handle
lexcurrent lex
table_identtable alias if it's used
schema_table_idxthe type of the INFORMATION_SCHEMA table to be created
Note
Due to the way this function works with memory and LEX it cannot be used outside the parser (parse tree transformations outside the parser break PS and SP).
Return values
0success
1out of memory or SHOW commands are not allowed in this version of the server.

◆ push_new_name_resolution_context()

bool push_new_name_resolution_context ( Parse_context pc,
TABLE_LIST left_op,
TABLE_LIST right_op 
)

Push a new name resolution context for a JOIN ... ON clause to the context stack of a query block.

Create a new name resolution context for a JOIN ... ON clause, set the first and last leaves of the list of table references to be used for name resolution, and push the newly created context to the stack of contexts of the query.

Parameters
pccurrent parse context
left_opleft operand of the JOIN
right_opright operand of the JOIN
Return values
falseif all is OK
trueif a memory allocation error occurred

◆ reparse_common_table_expr()

static bool reparse_common_table_expr ( THD thd,
const char *  text,
size_t  text_length,
uint  text_offset,
PT_subquery **  node 
)
static

Produces a PT_subquery object from a subquery's text.

Parameters
thdThread handler
textSubquery's text
text_lengthLength of 'text'
text_offsetOffset in bytes of 'text' in the original statement
[out]nodeProduced PT_subquery object
Returns
true if error

◆ reset_for_next_command()

void THD::reset_for_next_command ( )

◆ run_post_replication_filters_actions()

static bool run_post_replication_filters_actions ( THD thd)
static

Iterates over all post replication filter actions registered and executes them.

All actions registered will be executed at most once. They are executed in the order that they were registered. Shall there be an error while iterating through the list of actions and executing them, then the process stops and an error is returned immediately. This means that in that case, some actions may have executed successfully and some not. In other words, this procedure is not atomic.

This function will consume all actions from the list if there is no error. This means that actions run only once per statement. Should there be any sub-statements then actions only run on the top level statement execution.

Parameters
thdThe thread context.
Returns
true If there was an error while executing the registered actions.
false If all actions executed successfully.

◆ set_gr_incoming_connection()

void set_gr_incoming_connection ( gr_incoming_connection_cb  x)

◆ set_lock_for_table()

void Query_block::set_lock_for_table ( const Lock_descriptor descriptor,
TABLE_LIST table 
)

◆ set_lock_for_tables()

void Query_block::set_lock_for_tables ( thr_lock_type  lock_type)

Set lock for all tables in current query block.

Parameters
lock_typeLock to set for tables.
Note
If the lock is a write lock, then tables->updating is set to true. This is to get tables_ok to know that the table is being updated by the query. Sets the type of metadata lock to request according to lock_type.

◆ show_precheck()

bool show_precheck ( THD thd,
LEX lex,
bool  lock 
)

Do special checking for SHOW statements.

Parameters
thdThread context.
lexLEX for SHOW statement.
lockIf true, lock metadata for schema objects
Returns
false if check is successful, true if error

◆ shutdown()

bool shutdown ( THD thd,
enum mysql_enum_shutdown_level  level 
)

Shutdown the mysqld server.

Parameters
thdThread (session) context.
levelShutdown level.
Return values
truesuccess
falseWhen user has insufficient privilege or unsupported shutdown level

◆ some_non_temp_table_to_be_updated()

bool some_non_temp_table_to_be_updated ( THD thd,
TABLE_LIST tables 
)

◆ sp_process_definer()

static bool sp_process_definer ( THD thd)
static

◆ sql_kill()

static void sql_kill ( THD thd,
my_thread_id  id,
bool  only_kill_query 
)
static

◆ sqlcom_can_generate_row_events()

bool sqlcom_can_generate_row_events ( enum enum_sql_command  command)

◆ sqlcom_needs_autocommit_off()

static bool sqlcom_needs_autocommit_off ( const LEX lex)
static

Check if statement (typically DDL) needs auto-commit mode temporarily turned off.

Note
This is necessary to prevent InnoDB from automatically committing InnoDB transaction each time data-dictionary tables are closed after being updated.

◆ stmt_causes_implicit_commit()

bool stmt_causes_implicit_commit ( const THD thd,
uint  mask 
)

Returns whether the command in thd->lex->sql_command should cause an implicit commit.

An active transaction should be implicitly committed if the statement requires so.

Parameters
thdThread handle.
maskBitmask used for the SQL command match.
Return values
trueThis statement shall cause an implicit commit.
falseThis statement shall not cause an implicit commit.

◆ str_global()

const std::string & Command_names::str_global ( enum_server_command  cmd)
static

Return a description string for a given enum_server_command.

This takes @global.terminology_use_previous into account, and returns an old name if one has been defined and the option is enabled.

Parameters
cmdThe enum_server_command
Return values
Thedescription string

◆ str_session()

const std::string & Command_names::str_session ( enum_server_command  cmd)
static

Return a description string for a given enum_server_command.

This takes @session.terminology_use_previous into account, and returns an old name if one has been defined and the option is enabled.

Parameters
cmdThe enum_server_command
Return values
Thedescription string

◆ test_if_data_home_dir()

int test_if_data_home_dir ( const char *  dir)

◆ translate()

const std::string & Command_names::translate ( const System_variables sysvars)
staticprivate

Given a system_variable object, returns the string to use for m_replace_com, according to the setting of terminology_use_previous stored in the object.

Parameters
sysvarsThe System_variables object holding the configuration that should be considered when doing the translation.
Returns
The instrumentation name that was in use in the configured version, for m_replace_com.

Variable Documentation

◆ com_incoming_gr_stream_cb

std::atomic<gr_incoming_connection_cb> com_incoming_gr_stream_cb
static

◆ m_names

const std::string Command_names::m_names
staticprivate

Array indexed by enum_server_command, where each element is a description string.

◆ m_replace_str

const std::string Command_names::m_replace_str {"Register Slave"}
staticprivate

Name to use when compatibility is enabled.

◆ server_command_flags

uint server_command_flags[COM_END+1]

◆ sql_command_flags

uint sql_command_flags[SQLCOM_END+1]

Mark all commands that somehow changes a table.

This is used to check number of updates / hour.

sql_command is actually set to SQLCOM_END sometimes so we need the +1 to include it in the array.

See COMMAND_FLAG_xxx for different type of commands 2 - query that returns meaningful ROW_COUNT() - a number of modified rows