MySQL 9.4.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
item_create.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 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/* Functions to create an item. Used by sql/sql_yacc.yy */
25
26#ifndef ITEM_CREATE_H
27#define ITEM_CREATE_H
28
29/**
30 @file sql/item_create.h
31 Builder for SQL functions.
32*/
33
34#include <cstddef>
35
36#include "field_types.h"
37#include "lex_string.h"
38#include "my_inttypes.h" // uint
39#include "sql/parse_location.h" // POS
40
41/**
42 @addtogroup GROUP_PARSER
43 @{
44*/
45
46class Item;
47class PT_item_list;
48class THD;
49struct Cast_type;
50struct CHARSET_INFO;
51struct udf_func;
52enum class Json_on_response_type : uint16;
53
54/* For type casts */
55
56enum Cast_target : unsigned char {
75};
76
77/**
78 Public function builder interface.
79 The parser (sql/sql_yacc.yy) uses a factory / builder pattern to
80 construct an <code>Item</code> object for each function call.
81 All the concrete function builders implements this interface,
82 either directly or indirectly with some adapter helpers.
83 Keeping the function creation separated from the bison grammar allows
84 to simplify the parser, and avoid the need to introduce a new token
85 for each function, which has undesirable side effects in the grammar.
86*/
87
89 public:
90 /**
91 The builder create method.
92 Given the function name and list or arguments, this method creates
93 an <code>Item</code> that represents the function call.
94 In case or errors, a NULL item is returned, and an error is reported.
95 Note that the <code>thd</code> object may be modified by the builder.
96 In particular, the following members/methods can be set/called,
97 depending on the function called and the function possible side effects.
98 <ul>
99 <li><code>thd->lex->binlog_row_based_if_mixed</code></li>
100 <li><code>thd->lex->current_context()</code></li>
101 <li><code>thd->lex->safe_to_cache_query</code></li>
102 <li><code>thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT)</code></li>
103 <li><code>thd->lex->uncacheable(UNCACHEABLE_RAND)</code></li>
104 <li><code>thd->lex->add_time_zone_tables_to_query_tables(thd)</code></li>
105 </ul>
106 @param thd The current thread
107 @param pos The parser position
108 @param name The function name
109 @param item_list The list of arguments to the function, can be NULL
110 @return An item representing the parsed function call, or NULL
111 */
112 virtual Item *create_func(THD *thd, const POS &pos, LEX_STRING name,
113 PT_item_list *item_list) = 0;
114
115 protected:
116 Create_func() = default;
117 virtual ~Create_func() = default;
118};
119
120/**
121 Function builder for qualified functions.
122 This builder is used with functions call using a qualified function name
123 syntax, as in <code>db.func(expr, expr, ...)</code>.
124*/
125
126class Create_qfunc : public Create_func {
127 public:
128 /**
129 The builder create method, for unqualified functions.
130 This builder will use the current database for the database name.
131 @param thd The current thread
132 @param pos The parser position
133 @param name The function name
134 @param item_list The list of arguments to the function, can be NULL
135 @return An item representing the parsed function call
136 */
137 Item *create_func(THD *thd, const POS &pos, LEX_STRING name,
138 PT_item_list *item_list) override;
139
140 /**
141 The builder create method, for qualified functions.
142 @param thd The current thread
143 @param pos The parser position
144 @param db The database name or NULL_STR to use the default db name
145 @param name The function name
146 @param use_explicit_name Should the function be represented as 'db.name'?
147 @param item_list The list of arguments to the function, can be NULL
148 @return An item representing the parsed function call
149 */
150 virtual Item *create(THD *thd, const POS &pos, LEX_STRING db, LEX_STRING name,
151 bool use_explicit_name, PT_item_list *item_list) = 0;
152
153 protected:
154 /** Constructor. */
155 Create_qfunc() = default;
156 /** Destructor. */
157 ~Create_qfunc() override = default;
158};
159
160/**
161 Find the native function builder associated with a given function name.
162
163 @param name The native function name
164 @return The native function builder associated with the name, or NULL
165*/
167
168/**
169 Find the function builder for qualified functions.
170 @param thd The current thread
171 @return A function builder for qualified functions
172*/
174
175/**
176 Function builder for User Defined Functions.
177*/
178
180 public:
181 Item *create_func(THD *thd, const POS &pos, LEX_STRING name,
182 PT_item_list *item_list) override;
183
184 /**
185 The builder create method, for User Defined Functions.
186 @param thd The current thread
187 @param pos The parser position
188 @param fct The User Defined Function metadata
189 @param item_list The list of arguments to the function, can be NULL
190 @return An item representing the parsed function call
191 */
192 Item *create(THD *thd, const POS &pos, udf_func *fct,
193 PT_item_list *item_list);
194
195 /** Singleton. */
197
198 protected:
199 /** Constructor. */
200 Create_udf_func() = default;
201 /** Destructor. */
202 ~Create_udf_func() override = default;
203};
204
205/**
206 Builder for cast expressions.
207 @param thd The current thread
208 @param pos Location of casting expression
209 @param arg The item to cast
210 @param type the type casted into
211 @param as_array Cast to array
212*/
213Item *create_func_cast(THD *thd, const POS &pos, Item *arg,
214 const Cast_type &type, bool as_array);
215
216Item *create_func_cast(THD *thd, const POS &pos, Item *a,
217 Cast_target cast_target, const CHARSET_INFO *cs_arg);
218
219/**
220 Creates an Item that represents a JSON_VALUE expression.
221
222 @param thd thread handler
223 @param pos the location of the expression
224 @param arg the JSON input argument to the JSON_VALUE expression
225 @param path the path to extract from the JSON document
226 @param type the target type of the JSON_VALUE expression
227 @param on_empty_type the type of the ON EMPTY clause
228 @param on_empty_default the default value specified in ON EMPTY, if any
229 @param on_error_type the type of the ON ERROR clause
230 @param on_error_default the default value specified in ON ERROR, if any
231 @return an Item on success, or nullptr on error
232*/
233Item *create_func_json_value(THD *thd, const POS &pos, Item *arg, Item *path,
234 const Cast_type &type,
235 Json_on_response_type on_empty_type,
236 Item *on_empty_default,
237 Json_on_response_type on_error_type,
238 Item *on_error_default);
239
240Item *create_temporal_literal(THD *thd, const char *str, size_t length,
242 bool send_error);
243
244/**
245 Load the hash table for native functions.
246 Note: this code is not thread safe, and is intended to be used at server
247 startup only (before going multi-threaded)
248
249 @retval false OK.
250 @retval true An exception was caught.
251*/
252bool item_create_init();
253
254/**
255 Empty the hash table for native functions.
256 Note: this code is not thread safe, and is intended to be used at server
257 shutdown only (after thread requests have been executed).
258*/
260
261/**
262 @} (end of group GROUP_PARSER)
263*/
264
265#endif
Public function builder interface.
Definition: item_create.h:88
Create_func()=default
virtual ~Create_func()=default
virtual Item * create_func(THD *thd, const POS &pos, LEX_STRING name, PT_item_list *item_list)=0
The builder create method.
Function builder for qualified functions.
Definition: item_create.h:126
Create_qfunc()=default
Constructor.
virtual Item * create(THD *thd, const POS &pos, LEX_STRING db, LEX_STRING name, bool use_explicit_name, PT_item_list *item_list)=0
The builder create method, for qualified functions.
~Create_qfunc() override=default
Destructor.
Function builder for User Defined Functions.
Definition: item_create.h:179
Create_udf_func()=default
Constructor.
~Create_udf_func() override=default
Destructor.
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:927
Wrapper class for an Item list head, used to allocate Item lists in the parser in a context-independe...
Definition: parse_tree_helpers.h:105
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
This file contains the field type.
enum_field_types
Column types for MySQL Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:55
Create_func * find_native_function_builder(const LEX_STRING &lex_name)
Find the native function builder associated with a given function name.
Definition: item_create.cc:1807
bool item_create_init()
Load the hash table for native functions.
Definition: item_create.cc:1794
Item * create_func(THD *thd, const POS &pos, LEX_STRING name, PT_item_list *item_list) override
The builder create method, for unqualified functions.
Definition: item_create.cc:1153
Item * create_func(THD *thd, const POS &pos, LEX_STRING name, PT_item_list *item_list) override
The builder create method.
Definition: item_create.cc:1160
Cast_target
Definition: item_create.h:56
Item * create_func_cast(THD *thd, const POS &pos, Item *a, Cast_target cast_target, const CHARSET_INFO *cs)
Definition: item_create.cc:1825
Item * create_func_json_value(THD *thd, const POS &pos, Item *arg, Item *path, const Cast_type &cast_type, Json_on_response_type on_empty_type, Item *on_empty_default, Json_on_response_type on_error_type, Item *on_error_default)
Creates an Item that represents a JSON_VALUE expression.
Definition: item_create.cc:2144
Create_qfunc * find_qualified_function_builder(THD *)
Find the function builder for qualified functions.
Definition: item_create.cc:1821
void item_create_cleanup()
Empty the hash table for native functions.
Definition: item_create.cc:1805
static Create_udf_func s_singleton
Singleton.
Definition: item_create.h:196
Item * create_temporal_literal(THD *thd, const char *str, size_t length, const CHARSET_INFO *cs, enum_field_types type, bool send_error)
Builder for datetime literals: TIME'00:00:00', DATE'2001-01-01', TIMESTAMP'2001-01-01 00:00:00'.
Definition: item_create.cc:2178
Item * create(THD *thd, const POS &pos, udf_func *fct, PT_item_list *item_list)
The builder create method, for User Defined Functions.
Definition: item_create.cc:1167
@ ITEM_CAST_SIGNED_INT
@ ITEM_CAST_MULTIPOINT
@ ITEM_CAST_GEOMETRYCOLLECTION
@ ITEM_CAST_MULTIPOLYGON
@ ITEM_CAST_LINESTRING
@ ITEM_CAST_UNSIGNED_INT
@ ITEM_CAST_MULTILINESTRING
Some integer typedefs for easier portability.
uint16_t uint16
Definition: my_inttypes.h:65
static char * path
Definition: mysqldump.cc:150
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1084
Definition: commit_order_queue.h:34
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
std::vector< uint8_t > as_array(const std::string &s)
Definition: jwt.cc:47
required string type
Definition: replication_group_member_actions.proto:34
case opt name
Definition: sslopt-case.h:29
Definition: m_ctype.h:421
Definition: parser_yystype.h:189
Definition: mysql_lex_string.h:35
Bison "location" class.
Definition: parse_location.h:43
Definition: sql_udf.h:44
Json_on_response_type
Types of ON EMPTY/ON ERROR clauses for JSON_TABLE and JSON_VALUE.
Definition: table_function.h:205