MySQL 9.5.0
Source Code Documentation
sp_instr_inline.h
Go to the documentation of this file.
1/* Copyright (c) 2025, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SP_INSTR_INLINE_INCLUDED
25#define SP_INSTR_INLINE_INCLUDED
26
27#include <string>
28#include <unordered_set>
29#include "my_inttypes.h"
30
31class THD;
32class sp_head;
33class Item;
35class sp_instr;
36class sp_pcontext;
37template <class T>
38class Mem_root_array;
39
40namespace sp_inl {
41
42class sp_inline_instr;
43
44///////////////////////////////////////////////////////////////////////////
45
46/**
47 Checks if stored function inlining is required.
48 Currently we attempt stored function inlining only for the secondary engine.
49 In certain cases (such as PFS creation) m_sql_cmd could be nullptr.
50
51 @param[in] thd Thread context
52 @return "true" if inlining is required, "false" otherwise
53*/
55
56/**
57 Checks if general stored function properties are eligible for inlining.
58
59 @param[in] thd Thread context
60 @param[in] sp Stored program (function) instance
61 @param[in] sp_arg_count Number of arguments of the stored function
62 @return "true" if the function can potentially be inlined, "false"
63 otherwise.
64*/
65bool can_inline_stored_function(THD *thd, sp_head *sp, uint sp_arg_count);
66
67/**
68 Creates the list of prepared instructions. A prepared instruction is an
69 instruction eligible for inlining according to its method validate(). This
70 function also computes and marks the redundant instructions so they can be
71 later recognized using the method is_redundant_instr(). A redundant
72 instruction is an instruction not needed for computing the returned result
73 of the stored function.
74
75 @param[in] thd Thread context
76 @param[in] sp Stored program (stored function) instance
77 @param[out] used_sp_functions Set of stored function instances called from
78 sp
79
80 @return nullptr if an error occurs. List of prepared instructions otherwise.
81 The list may contain both redundant and not redundant instruction.
82*/
84 THD *thd, sp_head *sp, std::unordered_set<sp_head *> &used_sp_functions);
85
86/**
87 Inlines the given stored function instructions into a single Item
88
89 @param[in] thd Thread context
90 @param[in] prepared_instructions Instructions to inline
91 @param[in] sp_args Input arguments of the stored function
92 @param[in] sp_arg_count Number of arguments of the stored function
93 @param[in] sp_head Stored function instance
94 @param[in] sp_name_resolution_ctx Name resolution context of the stored
95 function
96
97 @return "nullptr" if an error occurs, inlined Item otherwise
98*/
100 THD *thd, Mem_root_array<sp_inline_instr *> *prepared_instructions,
101 Item **sp_args, uint sp_arg_count, sp_head *sp_head,
102 Name_resolution_context *sp_name_resolution_ctx);
103
104/**
105 Finalizes the error message for stored function inlining and reports the
106 error.
107
108 @param[in] thd Thread context
109 @param[in] func_name Stored function name
110 @param[in] err_reason Failure reason
111*/
112void report_stored_function_inlining_error(THD *thd, const char *func_name,
113 std::string &err_reason);
114
115} // namespace sp_inl
116
117#endif /* SP_INSTR_INLINE_INCLUDED */
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:928
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:432
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
sp_head represents one instance of a stored program.
Definition: sp_head.h:389
Base class for every SP-instruction.
Definition: sp_instr.h:105
The class represents parse-time context, which keeps track of declared variables/parameters,...
Definition: sp_pcontext.h:252
Some integer typedefs for easier portability.
Definition: sp_instr_inline.cc:42
void report_stored_function_inlining_error(THD *thd, const char *func_name, std::string &err_reason)
Finalizes the error message for stored function inlining and reports the error.
Definition: sp_instr_inline.cc:1283
Mem_root_array< sp_inline_instr * > * prepare(THD *thd, sp_head *sp, std::unordered_set< sp_head * > &used_sp_functions)
Creates the list of prepared instructions.
Definition: sp_instr_inline.cc:1434
Item * inline_stored_function(THD *thd, Mem_root_array< sp_inline_instr * > *prepared_instructions, Item **sp_args, uint sp_arg_count, sp_head *sp_head, Name_resolution_context *sp_name_resolution_ctx)
Inlines the given stored function instructions into a single Item.
Definition: sp_instr_inline.cc:1508
bool needs_stored_function_inlining(THD *thd)
Main functions for stored function inlining.
Definition: sp_instr_inline.cc:1303
bool can_inline_stored_function(THD *thd, sp_head *sp, uint sp_arg_count)
Checks if general stored function properties are eligible for inlining.
Definition: sp_instr_inline.cc:1308
Instances of Name_resolution_context store the information necessary for name resolution of Items and...
Definition: item.h:413