MySQL 8.4.0
Source Code Documentation
item_create.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2024, 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 name The function name
108 @param item_list The list of arguments to the function, can be NULL
109 @return An item representing the parsed function call, or NULL
110 */
112 PT_item_list *item_list) = 0;
113
114 protected:
115 Create_func() = default;
116 virtual ~Create_func() = default;
117};
118
119/**
120 Function builder for qualified functions.
121 This builder is used with functions call using a qualified function name
122 syntax, as in <code>db.func(expr, expr, ...)</code>.
123*/
124
125class Create_qfunc : public Create_func {
126 public:
127 /**
128 The builder create method, for unqualified functions.
129 This builder will use the current database for the database name.
130 @param thd The current thread
131 @param name The function name
132 @param item_list The list of arguments to the function, can be NULL
133 @return An item representing the parsed function call
134 */
136 PT_item_list *item_list) override;
137
138 /**
139 The builder create method, for qualified functions.
140 @param thd The current thread
141 @param db The database name or NULL_STR to use the default db name
142 @param name The function name
143 @param use_explicit_name Should the function be represented as 'db.name'?
144 @param item_list The list of arguments to the function, can be NULL
145 @return An item representing the parsed function call
146 */
148 bool use_explicit_name, PT_item_list *item_list) = 0;
149
150 protected:
151 /** Constructor. */
152 Create_qfunc() = default;
153 /** Destructor. */
154 ~Create_qfunc() override = default;
155};
156
157/**
158 Find the native function builder associated with a given function name.
159
160 @param name The native function name
161 @return The native function builder associated with the name, or NULL
162*/
164
165/**
166 Find the function builder for qualified functions.
167 @param thd The current thread
168 @return A function builder for qualified functions
169*/
171
172/**
173 Function builder for User Defined Functions.
174*/
175
177 public:
179 PT_item_list *item_list) override;
180
181 /**
182 The builder create method, for User Defined Functions.
183 @param thd The current thread
184 @param fct The User Defined Function metadata
185 @param item_list The list of arguments to the function, can be NULL
186 @return An item representing the parsed function call
187 */
188 Item *create(THD *thd, udf_func *fct, PT_item_list *item_list);
189
190 /** Singleton. */
192
193 protected:
194 /** Constructor. */
195 Create_udf_func() = default;
196 /** Destructor. */
197 ~Create_udf_func() override = default;
198};
199
200/**
201 Builder for cast expressions.
202 @param thd The current thread
203 @param pos Location of casting expression
204 @param arg The item to cast
205 @param type the type casted into
206 @param as_array Cast to array
207*/
208Item *create_func_cast(THD *thd, const POS &pos, Item *arg,
209 const Cast_type &type, bool as_array);
210
211Item *create_func_cast(THD *thd, const POS &pos, Item *a,
212 Cast_target cast_target, const CHARSET_INFO *cs_arg);
213
214/**
215 Creates an Item that represents a JSON_VALUE expression.
216
217 @param thd thread handler
218 @param pos the location of the expression
219 @param arg the JSON input argument to the JSON_VALUE expression
220 @param path the path to extract from the JSON document
221 @param type the target type of the JSON_VALUE expression
222 @param on_empty_type the type of the ON EMPTY clause
223 @param on_empty_default the default value specified in ON EMPTY, if any
224 @param on_error_type the type of the ON ERROR clause
225 @param on_error_default the default value specified in ON ERROR, if any
226 @return an Item on success, or nullptr on error
227*/
228Item *create_func_json_value(THD *thd, const POS &pos, Item *arg, Item *path,
229 const Cast_type &type,
230 Json_on_response_type on_empty_type,
231 Item *on_empty_default,
232 Json_on_response_type on_error_type,
233 Item *on_error_default);
234
235Item *create_temporal_literal(THD *thd, const char *str, size_t length,
237 bool send_error);
238
239/**
240 Load the hash table for native functions.
241 Note: this code is not thread safe, and is intended to be used at server
242 startup only (before going multi-threaded)
243
244 @retval false OK.
245 @retval true An exception was caught.
246*/
247bool item_create_init();
248
249/**
250 Empty the hash table for native functions.
251 Note: this code is not thread safe, and is intended to be used at server
252 shutdown only (after thread requests have been executed).
253*/
255
256/**
257 @} (end of group GROUP_PARSER)
258*/
259
260#endif
Public function builder interface.
Definition: item_create.h:88
Create_func()=default
virtual Item * create_func(THD *thd, LEX_STRING name, PT_item_list *item_list)=0
The builder create method.
virtual ~Create_func()=default
Function builder for qualified functions.
Definition: item_create.h:125
virtual Item * create(THD *thd, 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()=default
Constructor.
~Create_qfunc() override=default
Destructor.
Function builder for User Defined Functions.
Definition: item_create.h:176
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:934
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:1808
bool item_create_init()
Load the hash table for native functions.
Definition: item_create.cc:1795
Item * create_func(THD *thd, LEX_STRING name, PT_item_list *item_list) override
The builder create method, for unqualified functions.
Definition: item_create.cc:1162
Item * create(THD *thd, udf_func *fct, PT_item_list *item_list)
The builder create method, for User Defined Functions.
Definition: item_create.cc:1176
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:1826
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:2145
Create_qfunc * find_qualified_function_builder(THD *)
Find the function builder for qualified functions.
Definition: item_create.cc:1822
void item_create_cleanup()
Empty the hash table for native functions.
Definition: item_create.cc:1806
static Create_udf_func s_singleton
Singleton.
Definition: item_create.h:191
Item * create_func(THD *thd, LEX_STRING name, PT_item_list *item_list) override
The builder create method.
Definition: item_create.cc:1169
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:2179
@ 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:149
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1073
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
required string type
Definition: replication_group_member_actions.proto:34
case opt name
Definition: sslopt-case.h:29
Definition: m_ctype.h:423
Definition: parser_yystype.h:182
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:192