MySQL 9.1.0
Source Code Documentation
sp_lex_instr Class Referenceabstract

sp_lex_instr is a class providing the interface and base implementation for SP-instructions, whose execution is based on expression evaluation. More...

#include <sp_instr.h>

Inheritance diagram for sp_lex_instr:
[legend]

Public Member Functions

 sp_lex_instr (uint ip, sp_pcontext *ctx, LEX *lex, bool is_lex_owner)
 
 ~sp_lex_instr () override
 
bool validate_lex_and_execute_core (THD *thd, uint *nextp, bool open_tables)
 Make a few attempts to execute the instruction. More...
 
SQL_I_List< Item_trigger_field > * get_instr_trig_field_list () override
 
bool execute (THD *thd, uint *nextp) override
 Execute this instruction. More...
 
- Public Member Functions inherited from sp_instr
 sp_instr (uint ip, sp_pcontext *ctx)
 
 ~sp_instr () override
 
virtual PSI_statement_infoget_psi_info ()=0
 
uint get_ip () const
 
virtual uint get_cont_dest () const
 Get the continuation destination (instruction pointer for the CONTINUE HANDLER) of this instruction. More...
 
sp_pcontextget_parsing_ctx () const
 
virtual uint opt_mark (sp_head *, List< sp_instr > *leads)
 Mark this instruction as reachable during optimization and return the index to the next instruction. More...
 
virtual uint opt_shortcut_jump (sp_head *, sp_instr *start)
 Short-cut jumps to jumps during optimization. More...
 
virtual void opt_move (uint dst, List< sp_branch_instr > *ibp)
 Inform the instruction that it has been moved during optimization. More...
 
bool opt_is_marked () const
 
- Public Member Functions inherited from sp_printable
virtual void print (const THD *thd, String *str)=0
 
virtual ~sp_printable ()=default
 

Protected Member Functions

virtual bool exec_core (THD *thd, uint *nextp)=0
 Execute core function of instruction after all preparations (e.g. More...
 
virtual bool is_invalid () const =0
 
virtual void invalidate ()=0
 Invalidate the object. More...
 
virtual void get_query (String *sql_query) const
 Return the query string, which can be passed to the parser. More...
 
virtual void adjust_sql_command (LEX *)
 Some expressions may be re-parsed as SELECT statements, but need to be adjusted to another SQL command. More...
 
virtual LEX_CSTRING get_expr_query () const
 
virtual bool on_after_expr_parsing (THD *thd)
 Callback function which is called after the statement query string is successfully parsed, and the thread context has not been switched to the outer context. More...
 
virtual void cleanup_before_parsing (THD *thd)
 Destroy items in the free list before re-parsing the statement query string (and thus, creating new items). More...
 
- Protected Member Functions inherited from sp_instr
void clear_da (THD *thd) const
 Clear diagnostics area. More...
 

Protected Attributes

LEXm_lex
 LEX-object. More...
 
- Protected Attributes inherited from sp_instr
bool m_marked
 Show if this instruction is reachable within the SP (used by SP-optimizer). More...
 
uint m_ip
 Instruction pointer. More...
 
sp_pcontextm_parsing_ctx
 Instruction parsing context. More...
 

Private Member Functions

bool reset_lex_and_exec_core (THD *thd, uint *nextp, bool open_tables)
 Prepare LEX and thread for execution of instruction, if requested open and lock LEX's tables, execute instruction's core function, perform cleanup afterwards. More...
 
bool execute_expression (THD *thd, uint *nextp)
 Execute an expression (e.g an IF) that is not a complete SQL statement. More...
 
LEXparse_statement (THD *thd, sp_head *sp)
 Parse statement corresponding to this instruction and return a new LEX. More...
 
void set_lex (LEX *lex, bool is_lex_owner)
 Set LEX-object. More...
 
void free_lex ()
 Cleanup and destroy assigned LEX-object if needed. More...
 

Private Attributes

MEM_ROOT m_lex_mem_root {PSI_NOT_INSTRUMENTED, MEM_ROOT_BLOCK_SIZE}
 Mem-root for storing the LEX-tree during reparse. More...
 
bool m_is_lex_owner
 Indicates whether this sp_lex_instr instance is responsible for LEX-object deletion. More...
 
bool m_first_execution
 Indicates whether exec_core() has not been already called on the current LEX-object. More...
 
Table_refm_prelocking_tables
 List of additional tables this statement needs to lock when it enters/leaves prelocked mode on its own. More...
 
Table_ref ** m_lex_query_tables_own_last
 The value m_lex->query_tables_own_last should be set to this when the statement enters/leaves prelocked mode on its own. More...
 
SQL_I_List< Item_trigger_fieldm_trig_field_list
 List of all the Item_trigger_field's of instruction. More...
 

Additional Inherited Members

- Public Attributes inherited from sp_instr
Query_arena m_arena
 

Detailed Description

sp_lex_instr is a class providing the interface and base implementation for SP-instructions, whose execution is based on expression evaluation.

sp_lex_instr keeps LEX-object to be able to evaluate the expression.

sp_lex_instr also provides possibility to re-parse the original query string if for some reason the LEX-object is not valid any longer.

Constructor & Destructor Documentation

◆ sp_lex_instr()

sp_lex_instr::sp_lex_instr ( uint  ip,
sp_pcontext ctx,
LEX lex,
bool  is_lex_owner 
)
inline

◆ ~sp_lex_instr()

sp_lex_instr::~sp_lex_instr ( )
inlineoverride

Member Function Documentation

◆ adjust_sql_command()

virtual void sp_lex_instr::adjust_sql_command ( LEX )
inlineprotectedvirtual

Some expressions may be re-parsed as SELECT statements, but need to be adjusted to another SQL command.

This function facilitates that change.

Reimplemented in sp_instr_set, sp_instr_freturn, and sp_lex_branch_instr.

◆ cleanup_before_parsing()

void sp_lex_instr::cleanup_before_parsing ( THD thd)
protectedvirtual

Destroy items in the free list before re-parsing the statement query string (and thus, creating new items).

Parameters
thdThread context.

Reimplemented in sp_instr_set_trigger_field.

◆ exec_core()

virtual bool sp_lex_instr::exec_core ( THD thd,
uint *  nextp 
)
protectedpure virtual

Execute core function of instruction after all preparations (e.g.

setting of proper LEX, saving part of the thread context).

Parameters
thdThread context.
[out]nextpnext instruction pointer
Returns
Error flag.

Implemented in sp_instr_stmt, sp_instr_set, sp_instr_set_trigger_field, sp_instr_freturn, sp_instr_jump_if_not, sp_instr_set_case_expr, sp_instr_jump_case_when, and sp_instr_cpush.

◆ execute()

bool sp_lex_instr::execute ( THD thd,
uint *  nextp 
)
inlineoverridevirtual

Execute this instruction.

Parameters
thdThread context
[out]nextpindex of the next instruction to execute. (For most instructions this will be the instruction following this one). Note that this parameter is undefined in case of errors, use get_cont_dest() to find the continuation instruction for CONTINUE error handlers.
Returns
Error status.

Implements sp_instr.

Reimplemented in sp_instr_stmt, and sp_instr_cpush.

◆ execute_expression()

bool sp_lex_instr::execute_expression ( THD thd,
uint *  nextp 
)
private

Execute an expression (e.g an IF) that is not a complete SQL statement.

Expressions that may be executed in this function: IF, CASE, DECLARE, SET, RETURN

Parameters
thdthread context
[out]nextpnext instruction pointer
Returns
false if success, true if error

◆ free_lex()

void sp_lex_instr::free_lex ( )
private

Cleanup and destroy assigned LEX-object if needed.

◆ get_expr_query()

virtual LEX_CSTRING sp_lex_instr::get_expr_query ( ) const
inlineprotectedvirtual
Returns
the expression query string. This string can not be passed directly to the parser as it is most likely not a valid SQL-statement.
Note
as it can be seen in the get_query() implementation, get_expr_query() might return EMPTY_CSTR. EMPTY_CSTR means that no query-expression is available. That happens when class provides different implementation of get_query(). Strictly speaking, this is a drawback of the current class hierarchy.

Reimplemented in sp_instr_set, sp_instr_set_trigger_field, sp_instr_freturn, and sp_lex_branch_instr.

◆ get_instr_trig_field_list()

SQL_I_List< Item_trigger_field > * sp_lex_instr::get_instr_trig_field_list ( )
inlineoverridevirtual

Reimplemented from sp_instr.

◆ get_query()

void sp_lex_instr::get_query ( String sql_query) const
protectedvirtual

Return the query string, which can be passed to the parser.

I.e. the operation should return a valid SQL-statement query string.

Parameters
[out]sql_querySQL-statement query string.

Reimplemented in sp_instr_stmt, and sp_instr_cpush.

◆ invalidate()

virtual void sp_lex_instr::invalidate ( )
protectedpure virtual

◆ is_invalid()

virtual bool sp_lex_instr::is_invalid ( ) const
protectedpure virtual
Return values
falseif the object (i.e. LEX-object) is valid and exec_core() can be just called.
trueif the object is not valid any longer, exec_core() can not be called. The original query string should be re-parsed and a new LEX-object should be used.

Implemented in sp_instr_stmt, sp_instr_set, sp_instr_set_trigger_field, sp_instr_freturn, sp_lex_branch_instr, and sp_instr_cpush.

◆ on_after_expr_parsing()

virtual bool sp_lex_instr::on_after_expr_parsing ( THD thd)
inlineprotectedvirtual

Callback function which is called after the statement query string is successfully parsed, and the thread context has not been switched to the outer context.

The thread context contains new LEX-object corresponding to the parsed query string.

Parameters
thdThread context.
Returns
Error flag.

Reimplemented in sp_instr_stmt, sp_instr_cpush, sp_instr_set, sp_instr_set_trigger_field, sp_instr_freturn, sp_instr_jump_if_not, sp_instr_set_case_expr, and sp_instr_jump_case_when.

◆ parse_statement()

LEX * sp_lex_instr::parse_statement ( THD thd,
sp_head sp 
)
private

Parse statement corresponding to this instruction and return a new LEX.

Parameters
thdThread context.
spThe stored program.
Returns
new LEX-object or NULL in case of failure.

Move Item_trigger_field's list to instruction's Item_trigger_field list.

◆ reset_lex_and_exec_core()

bool sp_lex_instr::reset_lex_and_exec_core ( THD thd,
uint *  nextp,
bool  open_tables 
)
private

Prepare LEX and thread for execution of instruction, if requested open and lock LEX's tables, execute instruction's core function, perform cleanup afterwards.

Parameters
thdthread context
[out]nextpnext instruction pointer
open_tablesif true then check read access to tables in LEX's table list and open and lock them (used in instructions which need to calculate some expression and don't execute complete statement).
Note
We are not saving/restoring some parts of THD which may need this because we do this once for whole routine execution in sp_head::execute().
Returns
Error status.

◆ set_lex()

void sp_lex_instr::set_lex ( LEX lex,
bool  is_lex_owner 
)
private

Set LEX-object.

Previously assigned LEX-object (if any) will be properly cleaned up and destroyed.

Parameters
lexLEX-object to be used by this instance of sp_lex_instr.
is_lex_ownerthe flag specifying if this instance sp_lex_instr owns (and thus deletes when needed) passed LEX-object.

◆ validate_lex_and_execute_core()

bool sp_lex_instr::validate_lex_and_execute_core ( THD thd,
uint *  nextp,
bool  open_tables 
)

Make a few attempts to execute the instruction.

Basically, this operation does the following things:

  • install Reprepare_observer to catch metadata changes (if any);
  • calls reset_lex_and_exec_core() to execute the instruction;
  • if the execution fails due to a change in metadata, re-parse the instruction's SQL-statement and repeat execution.
Parameters
thdThread context.
[out]nextpNext instruction pointer
open_tablesFlag to specify if the function should check read access to tables in LEX's table list and open and lock them (used in instructions which need to calculate some expression and don't execute complete statement).
Returns
Error status.

Member Data Documentation

◆ m_first_execution

bool sp_lex_instr::m_first_execution
private

Indicates whether exec_core() has not been already called on the current LEX-object.

◆ m_is_lex_owner

bool sp_lex_instr::m_is_lex_owner
private

Indicates whether this sp_lex_instr instance is responsible for LEX-object deletion.

◆ m_lex

LEX* sp_lex_instr::m_lex
protected

LEX-object.

◆ m_lex_mem_root

MEM_ROOT sp_lex_instr::m_lex_mem_root {PSI_NOT_INSTRUMENTED, MEM_ROOT_BLOCK_SIZE}
private

Mem-root for storing the LEX-tree during reparse.

This mem-root is freed when a reparse is triggered or the stored routine is dropped.

◆ m_lex_query_tables_own_last

Table_ref** sp_lex_instr::m_lex_query_tables_own_last
private

The value m_lex->query_tables_own_last should be set to this when the statement enters/leaves prelocked mode on its own.

◆ m_prelocking_tables

Table_ref* sp_lex_instr::m_prelocking_tables
private

List of additional tables this statement needs to lock when it enters/leaves prelocked mode on its own.

◆ m_trig_field_list

SQL_I_List<Item_trigger_field> sp_lex_instr::m_trig_field_list
private

List of all the Item_trigger_field's of instruction.


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