MySQL 8.3.0
Source Code Documentation
LEX Struct Reference

The LEX object currently serves three different purposes: More...

#include <sql_lex.h>

Inheritance diagram for LEX:
[legend]

Public Types

typedef Prealloced_array< plugin_ref, INITIAL_LEX_PLUGIN_LIST_SIZEPlugins_array
 
- Public Types inherited from Query_tables_list
enum  { START_SROUTINES_HASH_SIZE = 16 }
 
enum  enum_lock_tables_state { LTS_NOT_LOCKED = 0 , LTS_LOCKED }
 Locking state of tables in this particular statement. More...
 
enum  enum_binlog_stmt_unsafe {
  BINLOG_STMT_UNSAFE_LIMIT = 0 , BINLOG_STMT_UNSAFE_SYSTEM_TABLE , BINLOG_STMT_UNSAFE_AUTOINC_COLUMNS , BINLOG_STMT_UNSAFE_UDF ,
  BINLOG_STMT_UNSAFE_SYSTEM_VARIABLE , BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION , BINLOG_STMT_UNSAFE_NONTRANS_AFTER_TRANS , BINLOG_STMT_UNSAFE_MULTIPLE_ENGINES_AND_SELF_LOGGING_ENGINE ,
  BINLOG_STMT_UNSAFE_MIXED_STATEMENT , BINLOG_STMT_UNSAFE_INSERT_IGNORE_SELECT , BINLOG_STMT_UNSAFE_INSERT_SELECT_UPDATE , BINLOG_STMT_UNSAFE_WRITE_AUTOINC_SELECT ,
  BINLOG_STMT_UNSAFE_REPLACE_SELECT , BINLOG_STMT_UNSAFE_CREATE_IGNORE_SELECT , BINLOG_STMT_UNSAFE_CREATE_REPLACE_SELECT , BINLOG_STMT_UNSAFE_CREATE_SELECT_AUTOINC ,
  BINLOG_STMT_UNSAFE_UPDATE_IGNORE , BINLOG_STMT_UNSAFE_INSERT_TWO_KEYS , BINLOG_STMT_UNSAFE_AUTOINC_NOT_FIRST , BINLOG_STMT_UNSAFE_FULLTEXT_PLUGIN ,
  BINLOG_STMT_UNSAFE_SKIP_LOCKED , BINLOG_STMT_UNSAFE_NOWAIT , BINLOG_STMT_UNSAFE_XA , BINLOG_STMT_UNSAFE_DEFAULT_EXPRESSION_IN_SUBSTATEMENT ,
  BINLOG_STMT_UNSAFE_ACL_TABLE_READ_IN_DML_DDL , BINLOG_STMT_UNSAFE_CREATE_SELECT_WITH_GIPK , BINLOG_STMT_UNSAFE_COUNT
}
 All types of unsafe statements. More...
 
enum  enum_stmt_accessed_table {
  STMT_READS_TRANS_TABLE = 0 , STMT_READS_NON_TRANS_TABLE , STMT_READS_TEMP_TRANS_TABLE , STMT_READS_TEMP_NON_TRANS_TABLE ,
  STMT_WRITES_TRANS_TABLE , STMT_WRITES_NON_TRANS_TABLE , STMT_WRITES_TEMP_TRANS_TABLE , STMT_WRITES_TEMP_NON_TRANS_TABLE ,
  STMT_ACCESS_TABLE_COUNT
}
 

Public Member Functions

Query_blockcurrent_query_block () const
 
void assert_ok_set_current_query_block ()
 
void set_current_query_block (Query_block *select)
 
bool is_explain () const
 
bool using_hypergraph_optimizer () const
 Whether the currently-running statement should be prepared and executed with the hypergraph optimizer. More...
 
void set_using_hypergraph_optimizer (bool use_hypergraph)
 
bool locate_var_assignment (const Name_string &name)
 Locate an assignment to a user variable with a given name, within statement. More...
 
void insert_values_map (Item_field *f1, Field *f2)
 
void destroy_values_map ()
 
void clear_values_map ()
 
bool has_values_map () const
 
std::map< Item_field *, Field * >::iterator begin_values_map ()
 
std::map< Item_field *, Field * >::iterator end_values_map ()
 
bool can_execute_only_in_secondary_engine () const
 
void set_execute_only_in_secondary_engine (const bool execute_only_in_secondary_engine_param, execute_only_in_secondary_reasons reason)
 
const char * get_not_supported_in_primary_reason ()
 
bool can_execute_only_in_hypergraph_optimizer () const
 
void set_execute_only_in_hypergraph_optimizer (bool execute_in_hypergraph_optimizer_param, execute_only_in_hypergraph_reasons reason)
 
const char * get_only_supported_in_hypergraph_reason_str () const
 
execute_only_in_hypergraph_reasons get_only_supported_in_hypergraph_reason () const
 
bool is_ignore () const
 
void set_ignore (bool ignore_param)
 
void set_has_udf ()
 
bool has_udf () const
 
ulonglong statement_options ()
 Gets the options that have been set for this statement. More...
 
void add_statement_options (ulonglong options)
 Add options to values of m_statement_options. More...
 
bool is_broken () const
 
void mark_broken (bool broken=true)
 Certain permanent transformations (like in2exists), if they fail, may leave the LEX in an inconsistent state. More...
 
bool check_preparation_invalid (THD *thd)
 Check whether preparation state for prepared statement is invalid. More...
 
void cleanup (bool full)
 
bool is_exec_started () const
 
void set_exec_started ()
 
void reset_exec_started ()
 
bool is_exec_completed () const
 Check whether the statement has been executed (regardless of completion - successful or in error). More...
 
void set_exec_completed ()
 
sp_pcontextget_sp_current_parsing_ctx ()
 
void set_sp_current_parsing_ctx (sp_pcontext *ctx)
 
bool is_metadata_used () const
 Check if the current statement uses meta-data (uses a table or a stored routine). More...
 
 LEX ()
 
virtual ~LEX ()
 
void destroy ()
 Destroy contained objects, but not the LEX object itself. More...
 
void reset ()
 Reset query context to initial state. More...
 
Query_blocknew_empty_query_block ()
 Create an empty query block within this LEX object. More...
 
Query_blocknew_query (Query_block *curr_query_block)
 Create query expression object that contains one query block. More...
 
Query_blocknew_set_operation_query (Query_block *curr_query_block)
 Create query block and attach it to the current query expression. More...
 
bool new_top_level_query ()
 Create top-level query expression and query block. More...
 
void new_static_query (Query_expression *sel_query_expression, Query_block *select)
 Create query expression and query block in existing memory objects. More...
 
Query_expressioncreate_query_expr_and_block (THD *thd, Query_block *current_query_block, Item *where_clause, Item *having_clause, enum_parsing_context ctx)
 Create query expression under current_query_block and a query block under the new query expression. More...
 
bool is_ps_or_view_context_analysis ()
 
bool is_view_context_analysis ()
 
void clear_execution ()
 Clear execution state for a statement after it has been prepared or executed, and before it is (re-)executed. More...
 
void set_uncacheable (Query_block *curr_query_block, uint8 cause)
 Set the current query as uncacheable. More...
 
void set_trg_event_type_for_tables ()
 Set the initial purpose of this Table_ref object in the list of used tables. More...
 
Table_refunlink_first_table (bool *link_to_local)
 
void link_first_table_back (Table_ref *first, bool link_to_local)
 
void first_lists_tables_same ()
 
void restore_cmd_properties ()
 
void restore_properties_for_insert ()
 
bool save_cmd_properties (THD *thd)
 
bool can_use_merged ()
 check if command can use VIEW with MERGE algorithm (for top VIEWs) More...
 
bool can_not_use_merged ()
 Check if command can't use merged views in any part of command. More...
 
bool need_correct_ident ()
 
bool which_check_option_applicable ()
 
void cleanup_after_one_table_open ()
 
bool push_context (Name_resolution_context *context)
 
void pop_context ()
 
bool copy_db_to (char const **p_db, size_t *p_db_length) const
 This method should be called only during parsing. More...
 
bool copy_db_to (char **p_db, size_t *p_db_length) const
 
Name_resolution_contextcurrent_context ()
 
void reset_n_backup_query_tables_list (Query_tables_list *backup)
 
void restore_backup_query_tables_list (Query_tables_list *backup)
 
bool table_or_sp_used ()
 
bool is_single_level_stmt ()
 check if the statement is a single-level join More...
 
void release_plugins ()
 
bool accept (Select_lex_visitor *visitor)
 
bool set_wild (LEX_STRING)
 
void clear_privileges ()
 
bool make_sql_cmd (Parse_tree_root *parse_tree)
 Uses parse_tree to instantiate an Sql_cmd object and assigns it to the Lex. More...
 
Secondary_engine_execution_contextsecondary_engine_execution_context () const
 Gets the secondary engine execution context for this statement. More...
 
void set_secondary_engine_execution_context (Secondary_engine_execution_context *context)
 Sets the secondary engine execution context for this statement. More...
 
bool validate_use_in_old_optimizer ()
 Validates if a query can run with the old optimizer. More...
 
bool is_replication_deprecated_syntax_used ()
 
void set_replication_deprecated_syntax_used ()
 
bool was_replication_command_executed () const
 
void set_was_replication_command_executed ()
 
bool set_channel_name (LEX_CSTRING name={})
 Set replication channel name. More...
 
void set_rewrite_required ()
 
void reset_rewrite_required ()
 
bool is_rewrite_required ()
 
- Public Member Functions inherited from Query_tables_list
Query_tables_listoperator= (Query_tables_list &&)=default
 
bool is_query_tables_locked () const
 
 Query_tables_list ()=default
 
 ~Query_tables_list ()=default
 
void reset_query_tables_list (bool init)
 
void destroy_query_tables_list ()
 
void set_query_tables_list (Query_tables_list *state)
 
void add_to_query_tables (Table_ref *table)
 
bool requires_prelocking ()
 
void mark_as_requiring_prelocking (Table_ref **tables_own_last)
 
Table_reffirst_not_own_table ()
 
void chop_off_not_own_tables ()
 
bool is_stmt_unsafe () const
 Determine if this statement is marked as unsafe. More...
 
bool is_stmt_unsafe (enum_binlog_stmt_unsafe unsafe)
 
void set_stmt_unsafe (enum_binlog_stmt_unsafe unsafe_type)
 Flag the current (top-level) statement as unsafe. More...
 
void set_stmt_unsafe_flags (uint32 flags)
 Set the bits of binlog_stmt_flags determining the type of unsafeness of the current statement. More...
 
uint32 get_stmt_unsafe_flags () const
 Return a binary combination of all unsafe warnings for the statement. More...
 
bool is_stmt_row_injection () const
 Determine if this statement is a row injection. More...
 
void set_stmt_row_injection ()
 Flag the statement as a row injection. More...
 
void set_stmt_accessed_table (enum_stmt_accessed_table accessed_table)
 Sets the type of table that is about to be accessed while executing a statement. More...
 
bool stmt_accessed_table (enum_stmt_accessed_table accessed_table)
 Checks if a type of table is about to be accessed while executing a statement. More...
 
bool is_mixed_stmt_unsafe (bool in_multi_stmt_transaction_mode, bool binlog_direct, bool trx_cache_is_not_empty, uint tx_isolation)
 
bool uses_stored_routines () const
 true if the parsed tree contains references to stored procedures or functions, false otherwise More...
 
void set_using_match ()
 
bool get_using_match ()
 
void set_stmt_unsafe_with_mixed_mode ()
 
bool is_stmt_unsafe_with_mixed_mode () const
 

Public Attributes

Query_expressionunit
 Outer-most query expression. More...
 
Query_blockquery_block
 First query block. More...
 
Query_blockall_query_blocks_list
 List of all query blocks. More...
 
bool is_explain_analyze = false
 
LEX_STRING name
 
char * help_arg
 
char * to_log
 
const char * x509_subject
 
const char * x509_issuer
 
const char * ssl_cipher
 
Stringwild
 
Query_resultresult
 
LEX_STRING binlog_stmt_arg
 Argument of the BINLOG event statement. More...
 
LEX_STRING ident
 
LEX_USERgrant_user
 
LEX_ALTER alter_password
 
enum_alter_user_attribute alter_user_attribute
 
LEX_STRING alter_user_comment_text
 
LEX_GRANT_AS grant_as
 
THDthd
 
Opt_hints_globalopt_hints_global
 
Plugins_array plugins
 
Table_refinsert_table
 Table being inserted into (may be a view) More...
 
Table_refinsert_table_leaf
 Leaf table being inserted into (always a base table) More...
 
LEX_STRING create_view_query_block
 SELECT of CREATE VIEW statement. More...
 
partition_infopart_info
 
LEX_USERdefiner
 
List< LEX_USERusers_list
 
List< LEX_COLUMNcolumns
 
List< LEX_CSTRINGdynamic_privileges
 
List< LEX_USER > * default_roles
 
ulonglong bulk_insert_row_cnt
 
List< Itempurge_value_list
 
List< Itemkill_value_list
 
List< set_var_basevar_list
 
List< Item_func_set_user_varset_var_list
 
List< Item_paramparam_list
 List of placeholders ('?') for parameters of a prepared statement. More...
 
List< Name_resolution_contextcontext_stack
 
Item_sumin_sum_func
 
udf_func udf
 
HA_CHECK_OPT check_opt
 
HA_CREATE_INFOcreate_info
 
KEY_CREATE_INFO key_create_info
 
LEX_MASTER_INFO mi
 
LEX_SLAVE_CONNECTION slave_connection
 
Server_options server_options
 
USER_RESOURCES mqh
 
LEX_RESET_SLAVE reset_slave_info
 
ulong type
 
nesting_map allow_sum_func
 This field is used as a work field during resolving to validate the use of aggregate functions. More...
 
nesting_map m_deny_window_func
 Windowing functions are not allowed in HAVING - in contrast to group aggregates - then we need to be stricter than allow_sum_func. More...
 
bool m_subquery_to_derived_is_impossible
 If true: during prepare, we did a subquery transformation (IN-to-EXISTS, SOME/ANY) that doesn't currently work for subquery to a derived table transformation. More...
 
Sql_cmdm_sql_cmd
 
bool expr_allows_subselect
 
uint reparse_common_table_expr_at
 If currently re-parsing a CTE's definition, this is the offset in bytes of that definition in the original statement which had the WITH clause. More...
 
bool reparse_derived_table_condition {false}
 If currently re-parsing a condition which is pushed down to a derived table, this will be set to true. More...
 
std::vector< uint > reparse_derived_table_params_at
 If currently re-parsing a condition that is being pushed down to a derived table, this has the positions of all the parameters that are part of that condition in the original statement. More...
 
enum SSL_type ssl_type
 
enum enum_duplicates duplicates
 
enum enum_tx_isolation tx_isolation
 
enum enum_var_type option_type
 
enum_view_create_mode create_view_mode
 
my_thread_id show_profile_query_id
 QUERY ID for SHOW PROFILE. More...
 
uint profile_options
 
uint grant
 
uint grant_tot_col
 
bool grant_privilege
 Set to true when GRANT ... GRANT OPTION ... TO ... is used (vs. More...
 
uint slave_thd_opt
 
uint start_transaction_opt
 
int select_number
 Number of query block (by EXPLAIN) More...
 
uint8 create_view_algorithm
 
uint8 create_view_check
 
uint8 context_analysis_only
 
bool drop_if_exists
 
bool grant_if_exists
 refers to optional IF EXISTS clause in REVOKE sql. More...
 
bool ignore_unknown_user
 refers to optional IGNORE UNKNOWN USER clause in REVOKE sql. More...
 
bool drop_temporary
 
bool autocommit
 
bool verbose
 
bool no_write_to_binlog
 
bool m_extended_show
 
enum enum_yes_no_unknown tx_chain tx_release
 
bool safe_to_cache_query
 Whether this query will return the same answer every time, given unchanged data. More...
 
st_parsing_options parsing_options
 
Alter_infoalter_info
 
LEX_CSTRING prepared_stmt_name
 
LEX_STRING prepared_stmt_code
 
bool prepared_stmt_code_is_varref
 
List< LEX_STRINGprepared_stmt_params
 
sp_headsphead
 
sp_namespname
 
bool sp_lex_in_use
 
bool all_privileges
 
bool contains_plaintext_password
 
enum_keep_diagnostics keep_diagnostics
 
uint32 next_binlog_file_nr
 
st_sp_chistics sp_chistics
 
Event_parse_dataevent_parse_data
 
bool only_view
 
uint8 create_view_suid
 
const char * stmt_definition_begin
 Intended to point to the next word after DEFINER-clause in the following statements: More...
 
const char * stmt_definition_end
 
bool use_only_table_context
 During name resolution search only in the table list given by Name_resolution_context::first_name_resolution_table and Name_resolution_context::last_name_resolution_table (see Item_field::fix_fields()). More...
 
bool is_lex_started
 
bool in_update_value_clause
 Set to true while resolving values in ON DUPLICATE KEY UPDATE clause. More...
 
class Explain_formatexplain_format {nullptr}
 
ulong max_execution_time
 
bool binlog_need_explicit_defaults_ts
 
bool will_contextualize
 Used to inform the parser whether it should contextualize the parse tree. More...
 
dd::info_schema::Table_statistics m_IS_table_stats
 IS schema queries read some dynamic table statistics from SE. More...
 
dd::info_schema::Tablespace_statistics m_IS_tablespace_stats
 
- Public Attributes inherited from Query_tables_list
enum_sql_command sql_command
 SQL command for this statement. More...
 
Table_refquery_tables
 
Table_ref ** query_tables_last
 
Table_ref ** query_tables_own_last
 
std::unique_ptr< malloc_unordered_map< std::string, Sroutine_hash_entry * > > sroutines
 
SQL_I_List< Sroutine_hash_entrysroutines_list
 
Sroutine_hash_entry ** sroutines_list_own_last
 
uint sroutines_list_own_elements
 
enum_lock_tables_state lock_tables_state
 
uint table_count
 Number of tables which were open by open_tables() and to be locked by lock_tables(). More...
 

Private Attributes

Query_blockm_current_query_block
 
bool m_can_execute_only_in_secondary_engine = false
 
execute_only_in_secondary_reasons m_execute_only_in_secondary_engine_reason
 
bool m_can_execute_only_in_hypergraph_optimizer = false
 
execute_only_in_hypergraph_reasons m_execute_only_in_hypergraph_reason
 
bool m_using_hypergraph_optimizer {false}
 
std::map< Item_field *, Field * > * insert_update_values_map
 
bool m_has_udf {false}
 True if statement references UDF functions. More...
 
bool ignore
 
bool m_broken
 see mark_broken() More...
 
bool m_exec_started
 Set to true when execution has started (after parsing, tables opened and query preparation is complete. More...
 
bool m_exec_completed
 Set to true when execution is completed, ie optimization has been done and execution is successful or ended in error. More...
 
sp_pcontextsp_current_parsing_ctx
 Current SP parsing context. More...
 
ulonglong m_statement_options {0}
 Statement context for Query_block::make_active_options. More...
 
Secondary_engine_execution_contextm_secondary_engine_context {nullptr}
 Context object used by secondary storage engines to store query state during optimization and execution. More...
 
bool m_is_replication_deprecated_syntax_used {false}
 
bool m_was_replication_command_executed {false}
 
bool rewrite_required {false}
 

Friends

bool lex_start (THD *thd)
 Call lex_start() before every query that is to be prepared and executed. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Query_tables_list
static const char * stmt_accessed_table_string (enum_stmt_accessed_table accessed_table)
 
- Static Public Attributes inherited from Query_tables_list
static const int BINLOG_STMT_UNSAFE_ALL_FLAGS
 This has all flags from 0 (inclusive) to BINLOG_STMT_FLAG_COUNT (exclusive) set. More...
 
static const int binlog_stmt_unsafe_errcode [BINLOG_STMT_UNSAFE_COUNT]
 Maps elements of enum_binlog_stmt_unsafe to error codes. More...
 

Detailed Description

The LEX object currently serves three different purposes:

  • It contains some universal properties of an SQL command, such as sql_command, presence of IGNORE in data change statement syntax, and list of tables (query_tables).
  • It contains some execution state variables, like m_exec_started (set to true when execution is started), plugins (list of plugins used by statement), insert_update_values_map (a map of objects used by certain INSERT statements), etc.
  • It contains a number of members that should be local to subclasses of Sql_cmd, like purge_value_list (for the PURGE command), kill_value_list (for the KILL command).

The LEX object is strictly a part of class Sql_cmd, for those SQL commands that are represented by an Sql_cmd class. For the remaining SQL commands, it is a standalone object linked to the current THD.

The lifecycle of a LEX object is as follows:

  • The LEX object is constructed either on the execution mem_root (for regular statements), on a Prepared_statement mem_root (for prepared statements), on an SP mem_root (for stored procedure instructions), or created on the current mem_root for short-lived uses.
  • Call lex_start() to initialize a LEX object before use. This initializes the execution state part of the object. It also calls LEX::reset() to ensure that all members are properly inited.
  • Parse and resolve the statement, using the LEX as a work area.
  • Execute an SQL command: call set_exec_started() when starting to execute (actually when starting to optimize). Typically call is_exec_started() to distinguish between preparation and optimization/execution stages of SQL command execution.
  • Call clear_execution() when execution is finished. This will clear all execution state associated with the SQL command, it also includes calling LEX::reset_exec_started().

Member Typedef Documentation

◆ Plugins_array

Constructor & Destructor Documentation

◆ LEX()

LEX::LEX ( )

◆ ~LEX()

LEX::~LEX ( )
virtual

Member Function Documentation

◆ accept()

bool LEX::accept ( Select_lex_visitor visitor)

◆ add_statement_options()

void LEX::add_statement_options ( ulonglong  options)
inline

Add options to values of m_statement_options.

options is an ORed bit set of options defined in query_options.h

Parameters
optionsAdd this set of options to the set already in m_statement_options

◆ assert_ok_set_current_query_block()

void LEX::assert_ok_set_current_query_block ( )

◆ begin_values_map()

std::map< Item_field *, Field * >::iterator LEX::begin_values_map ( )
inline

◆ can_execute_only_in_hypergraph_optimizer()

bool LEX::can_execute_only_in_hypergraph_optimizer ( ) const
inline

◆ can_execute_only_in_secondary_engine()

bool LEX::can_execute_only_in_secondary_engine ( ) const
inline

◆ can_not_use_merged()

bool LEX::can_not_use_merged ( )

Check if command can't use merged views in any part of command.

Temporary table algorithm will be used on all SELECT levels for queries listed here (see also LEX::can_use_merged()).

Returns
true if command cannot use merged view, false otherwise

◆ can_use_merged()

bool LEX::can_use_merged ( )

check if command can use VIEW with MERGE algorithm (for top VIEWs)

Only listed here commands can use merge algorithm in top level Query_block (for subqueries will be used merge algorithm if LEX::can_not_use_merged() is not true).

Returns
true if command can use merged VIEWs, false otherwise

◆ check_preparation_invalid()

bool LEX::check_preparation_invalid ( THD thd_arg)

Check whether preparation state for prepared statement is invalid.

Preparation state amy become invalid if a repreparation is forced, e.g because of invalid metadata, and that repreparation fails.

Returns
true if preparation state is invalid, false otherwise.

◆ cleanup()

void LEX::cleanup ( bool  full)
inline

◆ cleanup_after_one_table_open()

void LEX::cleanup_after_one_table_open ( )

◆ clear_execution()

void LEX::clear_execution ( )

Clear execution state for a statement after it has been prepared or executed, and before it is (re-)executed.

◆ clear_privileges()

void LEX::clear_privileges ( )

◆ clear_values_map()

void LEX::clear_values_map ( )
inline

◆ copy_db_to() [1/2]

bool LEX::copy_db_to ( char **  p_db,
size_t *  p_db_length 
) const
inline

◆ copy_db_to() [2/2]

bool LEX::copy_db_to ( char const **  p_db,
size_t *  p_db_length 
) const

This method should be called only during parsing.

It is aware of compound statements (stored routine bodies) and will initialize the destination with the default database of the stored routine, rather than the default database of the connection it is parsed in. E.g. if one has no current database selected, or current database set to 'bar' and then issues:

CREATE PROCEDURE foo.p1() BEGIN SELECT * FROM t1 END//

t1 is meant to refer to foo.t1, not to bar.t1.

This method is needed to support this rule.

Returns
true in case of error (parsing should be aborted, false in case of success

◆ create_query_expr_and_block()

Query_expression * LEX::create_query_expr_and_block ( THD thd,
Query_block current_query_block,
Item where_clause,
Item having_clause,
enum_parsing_context  ctx 
)

Create query expression under current_query_block and a query block under the new query expression.

The new query expression is linked in under current_query_block. The new query block is linked in under the new query expression.

Parameters
thdcurrent session context
current_query_blockthe root under which we create the new expression and block
where_clauseany where clause for the block
having_clauseany having clause for the block
ctxthe parsing context
Returns
the new query expression, or nullptr on error.

◆ current_context()

Name_resolution_context * LEX::current_context ( )
inline

◆ current_query_block()

Query_block * LEX::current_query_block ( ) const
inline

◆ destroy()

void LEX::destroy ( )
inline

Destroy contained objects, but not the LEX object itself.

◆ destroy_values_map()

void LEX::destroy_values_map ( )
inline

◆ end_values_map()

std::map< Item_field *, Field * >::iterator LEX::end_values_map ( )
inline

◆ first_lists_tables_same()

void LEX::first_lists_tables_same ( )

◆ get_not_supported_in_primary_reason()

const char * LEX::get_not_supported_in_primary_reason ( )
inline

◆ get_only_supported_in_hypergraph_reason()

execute_only_in_hypergraph_reasons LEX::get_only_supported_in_hypergraph_reason ( ) const
inline

◆ get_only_supported_in_hypergraph_reason_str()

const char * LEX::get_only_supported_in_hypergraph_reason_str ( ) const
inline

◆ get_sp_current_parsing_ctx()

sp_pcontext * LEX::get_sp_current_parsing_ctx ( )
inline

◆ has_udf()

bool LEX::has_udf ( ) const
inline

◆ has_values_map()

bool LEX::has_values_map ( ) const
inline

◆ insert_values_map()

void LEX::insert_values_map ( Item_field f1,
Field f2 
)
inline

◆ is_broken()

bool LEX::is_broken ( ) const
inline

◆ is_exec_completed()

bool LEX::is_exec_completed ( ) const
inline

Check whether the statement has been executed (regardless of completion - successful or in error).

Check this instead of Query_expression::is_executed() to determine the state of a complete statement.

◆ is_exec_started()

bool LEX::is_exec_started ( ) const
inline

◆ is_explain()

bool LEX::is_explain ( ) const
inline
Returns
true if this is an EXPLAIN statement

◆ is_ignore()

bool LEX::is_ignore ( ) const
inline

◆ is_metadata_used()

bool LEX::is_metadata_used ( ) const
inline

Check if the current statement uses meta-data (uses a table or a stored routine).

◆ is_ps_or_view_context_analysis()

bool LEX::is_ps_or_view_context_analysis ( )
inline

◆ is_replication_deprecated_syntax_used()

bool LEX::is_replication_deprecated_syntax_used ( )
inline

◆ is_rewrite_required()

bool LEX::is_rewrite_required ( )
inline

◆ is_single_level_stmt()

bool LEX::is_single_level_stmt ( )
inline

check if the statement is a single-level join

Returns
result of the check
Return values
trueThe statement doesn't contain subqueries, unions and stored procedure calls.
falseThere are subqueries, UNIONs or stored procedure calls.

◆ is_view_context_analysis()

bool LEX::is_view_context_analysis ( )
inline

◆ link_first_table_back()

void LEX::link_first_table_back ( Table_ref first,
bool  link_to_local 
)

◆ locate_var_assignment()

bool LEX::locate_var_assignment ( const Name_string name)

Locate an assignment to a user variable with a given name, within statement.

Parameters
nameName of variable to search for
Returns
true if variable is assigned to, false otherwise.

◆ make_sql_cmd()

bool LEX::make_sql_cmd ( Parse_tree_root parse_tree)

Uses parse_tree to instantiate an Sql_cmd object and assigns it to the Lex.

Parameters
parse_treeThe parse tree.
Returns
false on success, true on error.

◆ mark_broken()

void LEX::mark_broken ( bool  broken = true)
inline

Certain permanent transformations (like in2exists), if they fail, may leave the LEX in an inconsistent state.

They should call the following function, so that this LEX is not reused by another execution.

◆ need_correct_ident()

bool LEX::need_correct_ident ( )

◆ new_empty_query_block()

Query_block * LEX::new_empty_query_block ( )

Create an empty query block within this LEX object.

◆ new_query()

Query_block * LEX::new_query ( Query_block curr_query_block)

Create query expression object that contains one query block.

Create new query_block_query_expression and query_block objects for a query block, which can be either a top-level query or a subquery.

For the second and subsequent query block of a UNION query, use LEX::new_set_operation_query() instead. Set the new query_block as the current query_block of the LEX object.

Parameters
curr_query_blockcurrent query block, NULL if an outer-most query block should be created.
Returns
new query specification if successful, NULL if error

◆ new_set_operation_query()

Query_block * LEX::new_set_operation_query ( Query_block curr_query_block)

Create query block and attach it to the current query expression.

Create new query_block object for all branches of a UNION, EXCEPT or INTERSECT except the left-most one.

Set the new query_block as the current query_block of the LEX object.

Parameters
curr_query_blockcurrent query specification
Returns
new query specification if successful, NULL if an error occurred.

◆ new_static_query()

void LEX::new_static_query ( Query_expression sel_query_expression,
Query_block select 
)

Create query expression and query block in existing memory objects.

Initialize a LEX object, a query expression object (query_block_query_expression) and a query block object (query_block).

All objects are passed as pointers so they can be stack-allocated. The purpose of this structure is for short-lived procedures that need a LEX and a query block object.

Do not extend the struct with more query objects after creation.

The struct can be abandoned after use, no cleanup is needed.

Parameters
sel_query_expressionPointer to the query expression object
selectPointer to the query block object

◆ new_top_level_query()

bool LEX::new_top_level_query ( )

Create top-level query expression and query block.

Given a LEX object, create a query expression object (query_block_query_expression) and a query block object (query_block).

Returns
false if successful, true if error

◆ pop_context()

void LEX::pop_context ( )
inline

◆ push_context()

bool LEX::push_context ( Name_resolution_context context)
inline

◆ release_plugins()

void LEX::release_plugins ( )

◆ reset()

void LEX::reset ( void  )

Reset query context to initial state.

Reset a LEX object so that it is ready for a new query preparation and execution.

Pointers to query expression and query block objects are set to NULL. This is correct, as they point into a mem_root that has been recycled.

◆ reset_exec_started()

void LEX::reset_exec_started ( )
inline

◆ reset_n_backup_query_tables_list()

void LEX::reset_n_backup_query_tables_list ( Query_tables_list backup)

◆ reset_rewrite_required()

void LEX::reset_rewrite_required ( )
inline

◆ restore_backup_query_tables_list()

void LEX::restore_backup_query_tables_list ( Query_tables_list backup)

◆ restore_cmd_properties()

void LEX::restore_cmd_properties ( )
inline

◆ restore_properties_for_insert()

void LEX::restore_properties_for_insert ( )
inline

◆ save_cmd_properties()

bool LEX::save_cmd_properties ( THD thd)
inline

◆ secondary_engine_execution_context()

Secondary_engine_execution_context * LEX::secondary_engine_execution_context ( ) const
inline

Gets the secondary engine execution context for this statement.

◆ set_channel_name()

bool LEX::set_channel_name ( LEX_CSTRING  name = {})

Set replication channel name.

Parameters
nameIf name is null string then reset channel name to default. Otherwise set it to name.
Returns
false if success, true if error (OOM).

◆ set_current_query_block()

void LEX::set_current_query_block ( Query_block select)
inline

◆ set_exec_completed()

void LEX::set_exec_completed ( )
inline

◆ set_exec_started()

void LEX::set_exec_started ( )
inline

◆ set_execute_only_in_hypergraph_optimizer()

void LEX::set_execute_only_in_hypergraph_optimizer ( bool  execute_in_hypergraph_optimizer_param,
execute_only_in_hypergraph_reasons  reason 
)
inline

◆ set_execute_only_in_secondary_engine()

void LEX::set_execute_only_in_secondary_engine ( const bool  execute_only_in_secondary_engine_param,
execute_only_in_secondary_reasons  reason 
)
inline

◆ set_has_udf()

void LEX::set_has_udf ( )
inline

◆ set_ignore()

void LEX::set_ignore ( bool  ignore_param)
inline

◆ set_replication_deprecated_syntax_used()

void LEX::set_replication_deprecated_syntax_used ( )
inline

◆ set_rewrite_required()

void LEX::set_rewrite_required ( )
inline

◆ set_secondary_engine_execution_context()

void LEX::set_secondary_engine_execution_context ( Secondary_engine_execution_context context)

Sets the secondary engine execution context for this statement.

The old context object is destroyed, if there is one. Can be set to nullptr to destroy the old context object and clear the pointer.

The supplied context object should be allocated on the execution MEM_ROOT, so that its memory doesn't have to be manually freed after query execution.

◆ set_sp_current_parsing_ctx()

void LEX::set_sp_current_parsing_ctx ( sp_pcontext ctx)
inline

◆ set_trg_event_type_for_tables()

void LEX::set_trg_event_type_for_tables ( )

Set the initial purpose of this Table_ref object in the list of used tables.

We need to track this information on table-by-table basis, since when this table becomes an element of the pre-locked list, it's impossible to identify which SQL sub-statement it has been originally used in.

E.g.:

User request: SELECT * FROM t1 WHERE f1(); FUNCTION f1(): DELETE FROM t2; RETURN 1; BEFORE DELETE trigger on t2: INSERT INTO t3 VALUES (old.a);

For this user request, the pre-locked list will contain t1, t2, t3 table elements, each needed for different DML.

The trigger event map is updated to reflect INSERT, UPDATE, DELETE, REPLACE, LOAD DATA, CREATE TABLE .. SELECT, CREATE TABLE .. REPLACE SELECT statements, and additionally ON DUPLICATE KEY UPDATE clause.

◆ set_uncacheable()

void LEX::set_uncacheable ( Query_block curr_query_block,
uint8  cause 
)
inline

Set the current query as uncacheable.

Parameters
curr_query_blockCurrent select query block
causeWhy this query is uncacheable.

All query blocks representing subqueries, from the current one up to the outer-most one, but excluding the main query block, are also set as uncacheable.

◆ set_using_hypergraph_optimizer()

void LEX::set_using_hypergraph_optimizer ( bool  use_hypergraph)
inline

◆ set_was_replication_command_executed()

void LEX::set_was_replication_command_executed ( )
inline

◆ set_wild()

bool LEX::set_wild ( LEX_STRING  w)

◆ statement_options()

ulonglong LEX::statement_options ( )
inline

Gets the options that have been set for this statement.

The options are propagated to the Query_block objects and should usually be read with Query_block::active_options().

Returns
a bit set of options set for this statement

◆ table_or_sp_used()

bool LEX::table_or_sp_used ( )

◆ unlink_first_table()

Table_ref * LEX::unlink_first_table ( bool *  link_to_local)

◆ using_hypergraph_optimizer()

bool LEX::using_hypergraph_optimizer ( ) const
inline

Whether the currently-running statement should be prepared and executed with the hypergraph optimizer.

This will not change after the statement is prepared, so you can use it in any optimization phase to e.g. figure out whether to inhibit some transformation that the hypergraph optimizer does not properly understand yet. If a different optimizer is requested, the statement must be re-prepared with the proper optimizer settings.

◆ validate_use_in_old_optimizer()

bool LEX::validate_use_in_old_optimizer ( )

Validates if a query can run with the old optimizer.

Returns
True if the query cannot be run with old optimizer, false otherwise.

◆ was_replication_command_executed()

bool LEX::was_replication_command_executed ( ) const
inline

◆ which_check_option_applicable()

bool LEX::which_check_option_applicable ( )
inline

Friends And Related Function Documentation

◆ lex_start

bool lex_start ( THD thd)
friend

Call lex_start() before every query that is to be prepared and executed.

Because of this, it's critical not to do too many things here. (We already do too much)

The function creates a query_block and a query_block_query_expression object. These objects should rather be created by the parser bottom-up.

Member Data Documentation

◆ all_privileges

bool LEX::all_privileges

◆ all_query_blocks_list

Query_block* LEX::all_query_blocks_list

List of all query blocks.

◆ allow_sum_func

nesting_map LEX::allow_sum_func

This field is used as a work field during resolving to validate the use of aggregate functions.

For example in a query SELECT ... FROM ...WHERE MIN(i) == 1 GROUP BY ... HAVING MIN(i) > 2 MIN(i) in the WHERE clause is not allowed since only non-aggregated data is present, whereas MIN(i) in the HAVING clause is allowed because HAVING operates on the output of a grouping operation. Each query block is assigned a nesting level. This field is a bit field that contains the value one in the position of that nesting level if aggregate functions are allowed for that query block.

◆ alter_info

Alter_info* LEX::alter_info

◆ alter_password

LEX_ALTER LEX::alter_password

◆ alter_user_attribute

enum_alter_user_attribute LEX::alter_user_attribute

◆ alter_user_comment_text

LEX_STRING LEX::alter_user_comment_text

◆ autocommit

bool LEX::autocommit

◆ binlog_need_explicit_defaults_ts

bool LEX::binlog_need_explicit_defaults_ts

◆ binlog_stmt_arg

LEX_STRING LEX::binlog_stmt_arg
Initial value:
= {
nullptr, 0}

Argument of the BINLOG event statement.

◆ bulk_insert_row_cnt

ulonglong LEX::bulk_insert_row_cnt

◆ check_opt

HA_CHECK_OPT LEX::check_opt

◆ columns

List<LEX_COLUMN> LEX::columns

◆ contains_plaintext_password

bool LEX::contains_plaintext_password

◆ context_analysis_only

uint8 LEX::context_analysis_only

◆ context_stack

List<Name_resolution_context> LEX::context_stack

◆ create_info

HA_CREATE_INFO* LEX::create_info

◆ create_view_algorithm

uint8 LEX::create_view_algorithm

◆ create_view_check

uint8 LEX::create_view_check

◆ create_view_mode

enum_view_create_mode LEX::create_view_mode

◆ create_view_query_block

LEX_STRING LEX::create_view_query_block

SELECT of CREATE VIEW statement.

◆ create_view_suid

uint8 LEX::create_view_suid

◆ default_roles

List<LEX_USER>* LEX::default_roles

◆ definer

LEX_USER* LEX::definer

◆ drop_if_exists

bool LEX::drop_if_exists

◆ drop_temporary

bool LEX::drop_temporary

◆ duplicates

enum enum_duplicates LEX::duplicates

◆ dynamic_privileges

List<LEX_CSTRING> LEX::dynamic_privileges

◆ event_parse_data

Event_parse_data* LEX::event_parse_data

◆ explain_format

class Explain_format* LEX::explain_format {nullptr}

◆ expr_allows_subselect

bool LEX::expr_allows_subselect

◆ grant

uint LEX::grant

◆ grant_as

LEX_GRANT_AS LEX::grant_as

◆ grant_if_exists

bool LEX::grant_if_exists

refers to optional IF EXISTS clause in REVOKE sql.

This flag when set to true will report warnings in case privilege being granted is not granted to given user/role. When set to false error is reported.

◆ grant_privilege

bool LEX::grant_privilege

Set to true when GRANT ... GRANT OPTION ... TO ... is used (vs.

GRANT ... WITH GRANT OPTION). The flag is used by mysql_grant to grant GRANT OPTION (GRANT_ACL) to all dynamic privileges.

◆ grant_tot_col

uint LEX::grant_tot_col

◆ grant_user

LEX_USER* LEX::grant_user

◆ help_arg

char* LEX::help_arg

◆ ident

LEX_STRING LEX::ident

◆ ignore

bool LEX::ignore
private

◆ ignore_unknown_user

bool LEX::ignore_unknown_user

refers to optional IGNORE UNKNOWN USER clause in REVOKE sql.

This flag when set to true will report warnings in case target user/role for which privilege being granted does not exists. When set to false error is reported.

◆ in_sum_func

Item_sum* LEX::in_sum_func

◆ in_update_value_clause

bool LEX::in_update_value_clause

Set to true while resolving values in ON DUPLICATE KEY UPDATE clause.

◆ insert_table

Table_ref* LEX::insert_table

Table being inserted into (may be a view)

◆ insert_table_leaf

Table_ref* LEX::insert_table_leaf

Leaf table being inserted into (always a base table)

◆ insert_update_values_map

std::map<Item_field *, Field *>* LEX::insert_update_values_map
private

◆ is_explain_analyze

bool LEX::is_explain_analyze = false

◆ is_lex_started

bool LEX::is_lex_started

◆ keep_diagnostics

enum_keep_diagnostics LEX::keep_diagnostics

◆ key_create_info

KEY_CREATE_INFO LEX::key_create_info

◆ kill_value_list

List<Item> LEX::kill_value_list

◆ m_broken

bool LEX::m_broken
private

see mark_broken()

◆ m_can_execute_only_in_hypergraph_optimizer

bool LEX::m_can_execute_only_in_hypergraph_optimizer = false
private

◆ m_can_execute_only_in_secondary_engine

bool LEX::m_can_execute_only_in_secondary_engine = false
private

◆ m_current_query_block

Query_block* LEX::m_current_query_block
private

◆ m_deny_window_func

nesting_map LEX::m_deny_window_func

Windowing functions are not allowed in HAVING - in contrast to group aggregates - then we need to be stricter than allow_sum_func.

One bit per query block, as allow_sum_func.

◆ m_exec_completed

bool LEX::m_exec_completed
private

Set to true when execution is completed, ie optimization has been done and execution is successful or ended in error.

◆ m_exec_started

bool LEX::m_exec_started
private

Set to true when execution has started (after parsing, tables opened and query preparation is complete.

Used to track arena state for SPs).

◆ m_execute_only_in_hypergraph_reason

execute_only_in_hypergraph_reasons LEX::m_execute_only_in_hypergraph_reason
private
Initial value:
=
@ SUPPORTED_IN_BOTH_OPTIMIZERS
Definition: sql_lex.h:3731

◆ m_execute_only_in_secondary_engine_reason

execute_only_in_secondary_reasons LEX::m_execute_only_in_secondary_engine_reason
private
Initial value:
{
@ SUPPORTED_IN_PRIMARY
Definition: sql_lex.h:3724

◆ m_extended_show

bool LEX::m_extended_show

◆ m_has_udf

bool LEX::m_has_udf {false}
private

True if statement references UDF functions.

◆ m_is_replication_deprecated_syntax_used

bool LEX::m_is_replication_deprecated_syntax_used {false}
private

◆ m_IS_table_stats

dd::info_schema::Table_statistics LEX::m_IS_table_stats

IS schema queries read some dynamic table statistics from SE.

These statistics are cached, to avoid opening of table more than once while preparing a single output record buffer.

◆ m_IS_tablespace_stats

dd::info_schema::Tablespace_statistics LEX::m_IS_tablespace_stats

◆ m_secondary_engine_context

Secondary_engine_execution_context* LEX::m_secondary_engine_context {nullptr}
private

Context object used by secondary storage engines to store query state during optimization and execution.

◆ m_sql_cmd

Sql_cmd* LEX::m_sql_cmd

◆ m_statement_options

ulonglong LEX::m_statement_options {0}
private

Statement context for Query_block::make_active_options.

◆ m_subquery_to_derived_is_impossible

bool LEX::m_subquery_to_derived_is_impossible

If true: during prepare, we did a subquery transformation (IN-to-EXISTS, SOME/ANY) that doesn't currently work for subquery to a derived table transformation.

◆ m_using_hypergraph_optimizer

bool LEX::m_using_hypergraph_optimizer {false}
private

◆ m_was_replication_command_executed

bool LEX::m_was_replication_command_executed {false}
private

◆ max_execution_time

ulong LEX::max_execution_time

◆ mi

LEX_MASTER_INFO LEX::mi

◆ mqh

USER_RESOURCES LEX::mqh

◆ name

LEX_STRING LEX::name

◆ next_binlog_file_nr

uint32 LEX::next_binlog_file_nr

◆ no_write_to_binlog

bool LEX::no_write_to_binlog

◆ only_view

bool LEX::only_view

◆ opt_hints_global

Opt_hints_global* LEX::opt_hints_global

◆ option_type

enum enum_var_type LEX::option_type

◆ param_list

List<Item_param> LEX::param_list

List of placeholders ('?') for parameters of a prepared statement.

Because we append to this list during parsing, it is naturally sorted by position of the '?' in the query string. The code which fills placeholders with user-supplied values, and the code which writes a query for statement-based logging, rely on this order. This list contains only real placeholders, not the clones which originate in a re-parsed CTE definition.

◆ parsing_options

st_parsing_options LEX::parsing_options

◆ part_info

partition_info* LEX::part_info

◆ plugins

Plugins_array LEX::plugins

◆ prepared_stmt_code

LEX_STRING LEX::prepared_stmt_code

◆ prepared_stmt_code_is_varref

bool LEX::prepared_stmt_code_is_varref

◆ prepared_stmt_name

LEX_CSTRING LEX::prepared_stmt_name

◆ prepared_stmt_params

List<LEX_STRING> LEX::prepared_stmt_params

◆ profile_options

uint LEX::profile_options

◆ purge_value_list

List<Item> LEX::purge_value_list

◆ query_block

Query_block* LEX::query_block

First query block.

◆ reparse_common_table_expr_at

uint LEX::reparse_common_table_expr_at

If currently re-parsing a CTE's definition, this is the offset in bytes of that definition in the original statement which had the WITH clause.

Otherwise this is 0.

◆ reparse_derived_table_condition

bool LEX::reparse_derived_table_condition {false}

If currently re-parsing a condition which is pushed down to a derived table, this will be set to true.

◆ reparse_derived_table_params_at

std::vector<uint> LEX::reparse_derived_table_params_at

If currently re-parsing a condition that is being pushed down to a derived table, this has the positions of all the parameters that are part of that condition in the original statement.

Otherwise it is empty.

◆ reset_slave_info

LEX_RESET_SLAVE LEX::reset_slave_info

◆ result

Query_result* LEX::result

◆ rewrite_required

bool LEX::rewrite_required {false}
private

◆ safe_to_cache_query

bool LEX::safe_to_cache_query

Whether this query will return the same answer every time, given unchanged data.

Used to be for the query cache, but is now used to find out if an expression is usable for partitioning.

◆ select_number

int LEX::select_number

Number of query block (by EXPLAIN)

◆ server_options

Server_options LEX::server_options

◆ set_var_list

List<Item_func_set_user_var> LEX::set_var_list

◆ show_profile_query_id

my_thread_id LEX::show_profile_query_id

QUERY ID for SHOW PROFILE.

◆ slave_connection

LEX_SLAVE_CONNECTION LEX::slave_connection

◆ slave_thd_opt

uint LEX::slave_thd_opt

◆ sp_chistics

st_sp_chistics LEX::sp_chistics

◆ sp_current_parsing_ctx

sp_pcontext* LEX::sp_current_parsing_ctx
private

Current SP parsing context.

See also
also sp_head::m_root_parsing_ctx.

◆ sp_lex_in_use

bool LEX::sp_lex_in_use

◆ sphead

sp_head* LEX::sphead

◆ spname

sp_name* LEX::spname

◆ ssl_cipher

const char * LEX::ssl_cipher

◆ ssl_type

enum SSL_type LEX::ssl_type

◆ start_transaction_opt

uint LEX::start_transaction_opt

◆ stmt_definition_begin

const char* LEX::stmt_definition_begin

Intended to point to the next word after DEFINER-clause in the following statements:

  • CREATE TRIGGER (points to "TRIGGER");
  • CREATE PROCEDURE (points to "PROCEDURE");
  • CREATE FUNCTION (points to "FUNCTION" or "AGGREGATE");
  • CREATE EVENT (points to "EVENT")

This pointer is required to add possibly omitted DEFINER-clause to the DDL-statement before dumping it to the binlog.

◆ stmt_definition_end

const char* LEX::stmt_definition_end

◆ thd

THD* LEX::thd

◆ to_log

char* LEX::to_log

◆ tx_isolation

enum enum_tx_isolation LEX::tx_isolation

◆ tx_release

enum enum_yes_no_unknown tx_chain LEX::tx_release

◆ type

ulong LEX::type

◆ udf

udf_func LEX::udf

◆ unit

Query_expression* LEX::unit

Outer-most query expression.

◆ use_only_table_context

bool LEX::use_only_table_context

During name resolution search only in the table list given by Name_resolution_context::first_name_resolution_table and Name_resolution_context::last_name_resolution_table (see Item_field::fix_fields()).

◆ users_list

List<LEX_USER> LEX::users_list

◆ var_list

List<set_var_base> LEX::var_list

◆ verbose

bool LEX::verbose

◆ wild

String* LEX::wild

◆ will_contextualize

bool LEX::will_contextualize

Used to inform the parser whether it should contextualize the parse tree.

When we get a pure parser this will not be needed.

◆ x509_issuer

const char * LEX::x509_issuer

◆ x509_subject

const char* LEX::x509_subject

The documentation for this struct was generated from the following files: