MySQL 9.1.0
Source Code Documentation
sql_parse.cc File Reference
#include "sql/sql_parse.h"
#include <algorithm>
#include <atomic>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iterator>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "my_command.h"
#include "my_config.h"
#include "dur_prop.h"
#include "field_types.h"
#include "m_string.h"
#include "mem_root_deque.h"
#include "mutex_lock.h"
#include "my_alloc.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_hostname.h"
#include "my_inttypes.h"
#include "my_io.h"
#include "my_macros.h"
#include "my_psi_config.h"
#include "my_sys.h"
#include "my_table_map.h"
#include "my_thread_local.h"
#include "my_time.h"
#include "mysql/com_data.h"
#include "mysql/components/services/bits/plugin_audit_connection_types.h"
#include "mysql/components/services/bits/psi_statement_bits.h"
#include "mysql/components/services/language_service.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/my_loglevel.h"
#include "mysql/plugin_audit.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/psi/mysql_rwlock.h"
#include "mysql/psi/mysql_statement.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/strings/m_ctype.h"
#include "mysql/udf_registration_types.h"
#include "mysql_version.h"
#include "mysqld_error.h"
#include "mysys_err.h"
#include "nulls.h"
#include "pfs_thread_provider.h"
#include "prealloced_array.h"
#include "scope_guard.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/sql_authorization.h"
#include "sql/auth/sql_security_ctx.h"
#include "sql/binlog.h"
#include "sql/clone_handler.h"
#include "sql/comp_creator.h"
#include "sql/create_field.h"
#include "sql/current_thd.h"
#include "sql/dd/cache/dictionary_client.h"
#include "sql/dd/dd.h"
#include "sql/dd/dd_schema.h"
#include "sql/dd/dictionary.h"
#include "sql/dd/info_schema/table_stats.h"
#include "sql/dd/types/column.h"
#include "sql/debug_sync.h"
#include "sql/derror.h"
#include "sql/discrete_interval.h"
#include "sql/error_handler.h"
#include "sql/events.h"
#include "sql/field.h"
#include "sql/gis/srid.h"
#include "sql/item.h"
#include "sql/item_cmpfunc.h"
#include "sql/item_func.h"
#include "sql/item_subselect.h"
#include "sql/item_timefunc.h"
#include "sql/key_spec.h"
#include "sql/locked_tables_list.h"
#include "sql/log.h"
#include "sql/log_event.h"
#include "sql/mdl.h"
#include "sql/mem_root_array.h"
#include "sql/mysqld.h"
#include "sql/mysqld_thd_manager.h"
#include "sql/nested_join.h"
#include "sql/opt_hints.h"
#include "sql/opt_trace.h"
#include "sql/parse_location.h"
#include "sql/parse_tree_node_base.h"
#include "sql/parse_tree_nodes.h"
#include "sql/parser_yystype.h"
#include "sql/persisted_variable.h"
#include "sql/protocol.h"
#include "sql/protocol_classic.h"
#include "sql/psi_memory_key.h"
#include "sql/query_options.h"
#include "sql/query_result.h"
#include "sql/resourcegroups/resource_group_basic_types.h"
#include "sql/resourcegroups/resource_group_mgr.h"
#include "sql/rpl_context.h"
#include "sql/rpl_filter.h"
#include "sql/rpl_group_replication.h"
#include "sql/rpl_gtid.h"
#include "sql/rpl_handler.h"
#include "sql/rpl_replica.h"
#include "sql/rpl_source.h"
#include "sql/rpl_utility.h"
#include "sql/session_tracker.h"
#include "sql/set_var.h"
#include "sql/sp.h"
#include "sql/sp_cache.h"
#include "sql/sp_head.h"
#include "sql/sql_admin.h"
#include "sql/sql_alter.h"
#include "sql/sql_audit.h"
#include "sql/sql_base.h"
#include "sql/sql_binlog.h"
#include "sql/sql_check_constraint.h"
#include "sql/sql_class.h"
#include "sql/sql_cmd.h"
#include "sql/sql_connect.h"
#include "sql/sql_const.h"
#include "sql/sql_db.h"
#include "sql/sql_digest.h"
#include "sql/sql_digest_stream.h"
#include "sql/sql_error.h"
#include "sql/sql_handler.h"
#include "sql/sql_help.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_prepare.h"
#include "sql/sql_profile.h"
#include "sql/sql_query_rewrite.h"
#include "sql/sql_reload.h"
#include "sql/sql_rename.h"
#include "sql/sql_rewrite.h"
#include "sql/sql_show.h"
#include "sql/sql_table.h"
#include "sql/sql_trigger.h"
#include "sql/sql_udf.h"
#include "sql/sql_view.h"
#include "sql/strfunc.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/table_cache.h"
#include "sql/thd_raii.h"
#include "sql/transaction.h"
#include "sql/transaction_info.h"
#include "sql_string.h"
#include "string_with_len.h"
#include "strmake.h"
#include "strxmov.h"
#include "template_utils.h"
#include "thr_lock.h"
#include "violite.h"

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
 

Namespaces

namespace  resourcegroups
 
namespace  dd
 The version of the current data dictionary table definitions.
 

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_ref *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_ref *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_ref *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 failed 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 ()
 
int call_gr_incoming_connection_cb (THD *thd, int fd, SSL *ssl_ctx)
 Call the registered GR callback that delegates an incoming connection which is destined to GR. More...
 
void wait_for_gr_connection_end (THD *thd)
 Wait for a delegated connection to GR, until it ends or GR is shutdown. More...
 
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_ref 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...
 
bool sp_process_definer (THD *thd)
 
static bool lock_tables_open_and_lock_tables (THD *thd, Table_ref *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, MY_SQL_PARSER_STYPE **yyvs, POS **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 statement_id_to_session (THD *thd)
 
void dispatch_sql_command (THD *thd, Parser_state *parser_state, bool is_retry)
 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_refnest_join (THD *thd, Query_block *select, Table_ref *embedding, mem_root_deque< Table_ref * > *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_ref *left_op, Table_ref *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_ref *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...
 
bool merge_charset_and_collation (const CHARSET_INFO *charset, const CHARSET_INFO *collation, const CHARSET_INFO **to)
 (end of group Runtime_Environment) More...
 
bool merge_sp_var_charset_and_collation (const CHARSET_INFO *charset, const CHARSET_INFO *collation, const CHARSET_INFO **to)
 

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