![]() |
MySQL 9.5.0
Source Code Documentation
|
Base class for instructions within stored programs (currently limited to stored functions) that are eligible for inlining. More...
Public Member Functions | |
| 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... | |
| virtual bool | check_redundant_instr_for_errors (THD *thd, std::string &err_reason) |
| Checks for any errors that may occur during the preparation phase of a redundant instruction. More... | |
| virtual bool | validate (std::string &err_reason)=0 |
| Checks if this stored function instruction can be inlined. More... | |
| virtual 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)=0 |
| Determines whether the current stored function instruction is redundant based on the provided set of live variables. More... | |
| virtual 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)=0 |
| Processes an sp_inline_instr that is validated and non-redundant. More... | |
Static Public Member Functions | |
| static void | record_instruction_inlining_error (std::string &err_reason, uint ip) |
Protected Member Functions | |
| 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... | |
| Item * | parse_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_subselect * | create_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 | |
| sp_instr * | m_sp_instr |
| The original sp_instr which this class is meant to inline. More... | |
Private Member Functions | |
| void | inline_local_variables (Item **item, std::unordered_map< uint, Item * > &map_var_offset_to_value, Item **sp_args, uint sp_arg_count, Name_resolution_context *context) |
| Transforms the input item by replacing the references to local variables with their values. More... | |
| void | inline_select_list (Query_block *qb, std::unordered_map< uint, Item * > &map_var_offset_to_value, Item **sp_args, uint sp_arg_count, Name_resolution_context *context) |
| Inline local variables used in the select list of the query block. More... | |
| bool | inline_join_conditions (Query_block *qb, std::unordered_map< uint, Item * > &map_var_offset_to_value, Item **sp_args, uint sp_arg_count, Name_resolution_context *context) |
| Inline local variables used in the join conditions of the query block. More... | |
| void | inline_where_cond (Query_block *qb, std::unordered_map< uint, Item * > &map_var_offset_to_value, Item **sp_args, uint sp_arg_count, Name_resolution_context *context) |
| Inline local variables used in the where condition of the query block. More... | |
| void | inline_group_by (Query_block *qb, std::unordered_map< uint, Item * > &map_var_offset_to_value, Item **sp_args, uint sp_arg_count, Name_resolution_context *context) |
| Inline local variables used in the group by clause of the query block. More... | |
| void | inline_window_functions (Query_block *qb, std::unordered_map< uint, Item * > &map_var_offset_to_value, Item **sp_args, uint sp_arg_count, Name_resolution_context *context) |
| Inline local variables used in window functions of the query block. More... | |
| void | inline_order_by (Query_block *qb, std::unordered_map< uint, Item * > &map_var_offset_to_value, Item **sp_args, uint sp_arg_count, Name_resolution_context *context) |
| Inline local variables used in the order by clause of the query block. More... | |
| void | inline_limit_offset (Query_block *qb, std::unordered_map< uint, Item * > &map_var_offset_to_value, Item **sp_args, uint sp_arg_count) |
| Inline local variables used in limit and offset of the query block. More... | |
Private Attributes | |
| bool | m_is_redundant_instr |
| Indicates whether this sp_inline_instr instance is required to compute the RETURN result of the stored function. More... | |
| bool | m_is_validated_instr |
| Indicates whether this sp_inline_instr instance has passed the checks in validate. More... | |
Base class for instructions within stored programs (currently limited to stored functions) that are eligible for inlining.
The sp_inline_instr class defines the interface and provides the foundational implementation for inlining stored function instructions.
|
inline |
|
inlinevirtual |
|
inlinevirtual |
Checks for any errors that may occur during the preparation phase of a redundant instruction.
| thd | thread context | |
| [out] | err_reason | error reason if it occurs |
Reimplemented in sp_inl::sp_inline_instr_stmt.
|
protected |
Collects variable offsets for all encountered Item::ROUTINE_FIELD_ITEM instances across the various components of the query block.
Also gathers the set of stored functions invoked directly within this query block.
| [in] | thd | Thread context |
| [in] | qb | Query block |
| [out] | variable_offsets | Set of variable offsets used in the query block |
| [out] | used_sp_functions | Set of stored functions called directly within this query block |
| [out] | err_reason | Populated with the error reason if an error occurs |
|
pure virtual |
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.
| [in] | thd | Thread context. |
| [in,out] | offsets_live_variables | Current set of live variable offsets. |
| [out] | used_sp_functions | Set of stored function instances used in this instruction. |
| [out] | err_reason | Populated with the error reason if an error occurs. |
Implemented in sp_inl::sp_inline_instr_set, sp_inl::sp_inline_instr_stmt, and sp_inl::sp_inline_instr_freturn.
|
protected |
Transform sp_inline_instr into a subquery with inlined references to local variables.
| [in] | thd | Thread context |
| [in] | map_var_offset_to_value | Map of variable offsets to their current values |
| [in] | sp_args | Input arguments of the stored function |
| [in] | sp_arg_count | Number of arguments of the stored function |
| [in] | sp_head | Instance of the stored function |
| [in] | sp_name_resolution_ctx | Name resolution context of the stored function |
|
inline |
Retrieves the instruction pointer (IP) for this instruction.
The IP represents the order number of the instruction within the stored function.
|
private |
Inline local variables used in the group by clause of the query block.
| [in,out] | qb | Query block |
| [in] | map_var_offset_to_value | Map of variable offsets to their current values |
| [in] | sp_args | Input arguments of the stored function |
| [in] | sp_arg_count | Number of arguments of the stored function |
| [in] | context | Name resolution context of the stored function |
|
private |
Inline local variables used in the join conditions of the query block.
| [in,out] | qb | Query block |
| [in] | map_var_offset_to_value | Map of variable offsets to their current values |
| [in] | sp_args | Input arguments of the stored function |
| [in] | sp_arg_count | Number of arguments of the stored function |
| [in] | context | Name resolution context of the stored function |
|
private |
Inline local variables used in limit and offset of the query block.
| [in,out] | qb | Query block |
| [in] | map_var_offset_to_value | Map of variable offsets to their current values |
| [in] | sp_args | Input arguments of the stored function |
| [in] | sp_arg_count | Number of arguments of the stored function |
|
private |
Transforms the input item by replacing the references to local variables with their values.
If the value is a FIELD_ITEM, m_was_sp_local_variable is set to true.
| [in,out] | item | Item to transform |
| [in] | map_var_offset_to_value | Map of variable offsets to their current values |
| [in] | sp_args | Input arguments of the stored function |
| [in] | sp_arg_count | Number of arguments of the stored function |
| [in] | context | Name resolution context of the stored function |
|
private |
Inline local variables used in the order by clause of the query block.
| [in,out] | qb | Query block |
| [in] | map_var_offset_to_value | Map of variable offsets to their current values |
| [in] | sp_args | Input arguments of the stored function |
| [in] | sp_arg_count | Number of arguments of the stored function |
| [in] | context | Name resolution context of the stored function |
|
private |
Inline local variables used in the select list of the query block.
| [in,out] | qb | Query block |
| [in] | map_var_offset_to_value | Map of variable offsets to their current values |
| [in] | sp_args | Input arguments of the stored function |
| [in] | sp_arg_count | Number of arguments of the stored function |
| [in] | context | Name resolution context of the stored function |
|
private |
Inline local variables used in the where condition of the query block.
| [in,out] | qb | Query block |
| [in] | map_var_offset_to_value | Map of variable offsets to their current values |
| [in] | sp_args | Input arguments of the stored function |
| [in] | sp_arg_count | Number of arguments of the stored function |
| [in] | context | Name resolution context of the stored function |
|
private |
Inline local variables used in window functions of the query block.
| [in,out] | qb | Query block |
| [in] | map_var_offset_to_value | Map of variable offsets to their current values |
| [in] | sp_args | Input arguments of the stored function |
| [in] | sp_arg_count | Number of arguments of the stored function |
| [in] | context | Name resolution context of the stored function |
|
inline |
Gets the value of m_is_redundant_instr.
|
inline |
Gets the value of m_is_validated_instr.
|
protected |
Creates a deep copy of the input expression and then in-place replaces the references to local variables with their values.
| [in] | thd | Thread context |
| [in] | expr_item | The original item tree |
| [in] | map_var_offset_to_value | Map of variable offsets to their current values |
| [in] | sp_args | Input arguments of the stored function |
| [in] | sp_arg_count | Number of arguments of the stored function |
|
pure virtual |
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.
| [in] | thd | Thread context. |
| [in,out] | map_var_offset_to_value | Current mapping of local variables to their values. |
| [in] | sp_args | Input arguments of the stored function. |
| [in] | sp_arg_count | Number of arguments for the stored function. |
| [in] | sp_head | Stored function instance. |
| [in] | sp_name_resolution_ctx | Name resolution context for the stored function. |
| [out] | result_item | Result of a processed return instruction, or nullptr if not applicable. |
Implemented in sp_inl::sp_inline_instr_set, sp_inl::sp_inline_instr_stmt, and sp_inl::sp_inline_instr_freturn.
|
inlinestatic |
|
inline |
Sets m_is_redundant_instr to true, indicating that the instruction is not required for computing the return result of a stored function.
|
inline |
Sets m_is_validated_instr to true, indicating that the instruction has successfully passed the checks performed by validate().
|
pure virtual |
Checks if this stored function instruction can be inlined.
| [out] | err_reason | if the function cannot be inlined err_reason returns the error reason |
Implemented in sp_inl::sp_inline_instr_set, sp_inl::sp_inline_instr_stmt, and sp_inl::sp_inline_instr_freturn.
|
protected |
Traverses the item tree and collects variable offsets for any encountered Item::ROUTINE_FIELD_ITEM instances.
Additionally, collects instances of stored functions identified during the traversal.
| [in] | thd | Thread context |
| [in] | item | Item to traverse |
| [out] | var_offsets | Set of variable offsets found within the item |
| [out] | used_sp_functions | Set of stored function instances found in the item |
| [out] | err_reason | Populated with the error reason if an error occurs |
|
private |
Indicates whether this sp_inline_instr instance is required to compute the RETURN result of the stored function.
Computed during compute_is_redundant_and_collect_functions.
|
private |
Indicates whether this sp_inline_instr instance has passed the checks in validate.
|
protected |
The original sp_instr which this class is meant to inline.