MySQL 9.5.0
Source Code Documentation
sp_inl::sp_inline_instr_stmt Class Reference

The sp_inline_instr_stmt class provides the base implementation for inlining statement instructions (sp_instr_stmt) within stored functions. More...

Inheritance diagram for sp_inl::sp_inline_instr_stmt:
[legend]

Public Member Functions

 sp_inline_instr_stmt (sp_instr *sp_instr)
 
bool validate (std::string &err_reason) override
 Checks if this stored function instruction can be inlined. More...
 
bool compute_is_redundant_and_collect_functions (THD *thd, std::unordered_set< uint > &offsets_live_variables, std::unordered_set< sp_head * > &used_sp_functions, std::string &err_reason) override
 Determines whether the current stored function instruction is redundant based on the provided set of live variables. More...
 
bool process (THD *thd, std::unordered_map< uint, Item * > &map_var_offset_to_value, Item **sp_args, uint sp_arg_count, sp_head *sp_head, Name_resolution_context *sp_name_resolution_ctx, Item **result_item) override
 Processes an sp_inline_instr that is validated and non-redundant. More...
 
bool check_redundant_instr_for_errors (THD *thd, std::string &err_reason) override
 Checks for any errors that may occur during the preparation phase of a redundant instruction. More...
 
- Public Member Functions inherited from sp_inl::sp_inline_instr
 sp_inline_instr (sp_instr *sp_instr)
 
virtual ~sp_inline_instr ()
 
void set_is_validated_instr ()
 Sets m_is_validated_instr to true, indicating that the instruction has successfully passed the checks performed by validate(). More...
 
bool is_validated_instr ()
 Gets the value of m_is_validated_instr. More...
 
void set_is_redundant_instr ()
 Sets m_is_redundant_instr to true, indicating that the instruction is not required for computing the return result of a stored function. More...
 
bool is_redundant_instr ()
 Gets the value of m_is_redundant_instr. More...
 
uint get_ip ()
 Retrieves the instruction pointer (IP) for this instruction. More...
 

Private Member Functions

bool get_stmt_result_variable (uint *var_offset, std::string &err_reason)
 Retrieves the variable offset for the result variable of the current statement (i.e., the variable being selected into). More...
 

Additional Inherited Members

- Static Public Member Functions inherited from sp_inl::sp_inline_instr
static void record_instruction_inlining_error (std::string &err_reason, uint ip)
 
- Protected Member Functions inherited from sp_inl::sp_inline_instr
bool walk_and_collect_functions_and_variables (THD *thd, Item *item, std::unordered_set< uint > &var_offsets, std::unordered_set< sp_head * > &used_sp_functions, std::string &err_reason)
 Traverses the item tree and collects variable offsets for any encountered Item::ROUTINE_FIELD_ITEM instances. More...
 
bool collect_functions_and_variables_from_query_block (THD *thd, Query_block *qb, std::unordered_set< uint > &variable_offsets, std::unordered_set< sp_head * > &used_sp_functions, std::string &err_reason)
 Collects variable offsets for all encountered Item::ROUTINE_FIELD_ITEM instances across the various components of the query block. More...
 
Itemparse_and_inline_expression (THD *thd, Item *expr_item, std::unordered_map< uint, Item * > &map_var_offset_to_value, Item **sp_args, uint sp_arg_count)
 Creates a deep copy of the input expression and then in-place replaces the references to local variables with their values. More...
 
Item_singlerow_subselectcreate_and_inline_subquery (THD *thd, std::unordered_map< uint, Item * > &map_var_offset_to_value, Item **sp_args, uint sp_arg_count, sp_head *sp_head, Name_resolution_context *sp_name_resolution_ctx)
 Transform sp_inline_instr into a subquery with inlined references to local variables. More...
 
- Protected Attributes inherited from sp_inl::sp_inline_instr
sp_instrm_sp_instr
 The original sp_instr which this class is meant to inline. More...
 

Detailed Description

The sp_inline_instr_stmt class provides the base implementation for inlining statement instructions (sp_instr_stmt) within stored functions.

Currently, inlining is supported for SELECT INTO statements that insert into a single local variable. For further details about statement instructions, refer to the sp_instr_stmt class.

Constructor & Destructor Documentation

◆ sp_inline_instr_stmt()

sp_inl::sp_inline_instr_stmt::sp_inline_instr_stmt ( sp_instr sp_instr)
inline

Member Function Documentation

◆ check_redundant_instr_for_errors()

bool sp_inl::sp_inline_instr_stmt::check_redundant_instr_for_errors ( THD thd,
std::string &  err_reason 
)
inlineoverridevirtual

Checks for any errors that may occur during the preparation phase of a redundant instruction.

Parameters
thdthread context
[out]err_reasonerror reason if it occurs
Returns
false if success, true if error

Reimplemented from sp_inl::sp_inline_instr.

◆ compute_is_redundant_and_collect_functions()

bool sp_inl::sp_inline_instr_stmt::compute_is_redundant_and_collect_functions ( THD thd,
std::unordered_set< uint > &  offsets_live_variables,
std::unordered_set< sp_head * > &  used_sp_functions,
std::string &  err_reason 
)
inlineoverridevirtual

Determines whether the current stored function instruction is redundant based on the provided set of live variables.

A live variable is one that is required to compute the final result of the stored function. An instruction is considered redundant if it does not contribute to this result. If the instruction is determined to be non-redundant, this function updates the set of live variables with those used by the instruction. Additionally, the function collects instances of stored functions referenced in this instruction in order to use them later for recursion detection.

Parameters
[in]thdThread context.
[in,out]offsets_live_variablesCurrent set of live variable offsets.
[out]used_sp_functionsSet of stored function instances used in this instruction.
[out]err_reasonPopulated with the error reason if an error occurs.
Returns
false if the computation is successful; true otherwise.

Implements sp_inl::sp_inline_instr.

◆ get_stmt_result_variable()

bool sp_inl::sp_inline_instr_stmt::get_stmt_result_variable ( uint *  var_offset,
std::string &  err_reason 
)
inlineprivate

Retrieves the variable offset for the result variable of the current statement (i.e., the variable being selected into).

Parameters
[out]var_offsetOffset of the result variable
[out]err_reasonPopulated with the error reason if an error occurs
Returns
false if success, true if error

◆ process()

bool sp_inl::sp_inline_instr_stmt::process ( THD thd,
std::unordered_map< uint, Item * > &  map_var_offset_to_value,
Item **  sp_args,
uint  sp_arg_count,
sp_head sp_head,
Name_resolution_context sp_name_resolution_ctx,
Item **  result_item 
)
inlineoverridevirtual

Processes an sp_inline_instr that is validated and non-redundant.

This method either updates the current mapping of local variables to their values or returns the final result through the result argument.

Parameters
[in]thdThread context.
[in,out]map_var_offset_to_valueCurrent mapping of local variables to their values.
[in]sp_argsInput arguments of the stored function.
[in]sp_arg_countNumber of arguments for the stored function.
[in]sp_headStored function instance.
[in]sp_name_resolution_ctxName resolution context for the stored function.
[out]result_itemResult of a processed return instruction, or nullptr if not applicable.
Returns
false if success, true if error

Implements sp_inl::sp_inline_instr.

◆ validate()

bool sp_inl::sp_inline_instr_stmt::validate ( std::string &  err_reason)
inlineoverridevirtual

Checks if this stored function instruction can be inlined.

Parameters
[out]err_reasonif the function cannot be inlined err_reason returns the error reason
Returns
"false" if validation successful, "true" otherwise

Implements sp_inl::sp_inline_instr.


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