MySQL 8.1.0
Source Code Documentation
item_create.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2023, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23/* Functions to create an item. Used by sql/sql_yacc.yy */
24
25#ifndef ITEM_CREATE_H
26#define ITEM_CREATE_H
27
28/**
29 @file sql/item_create.h
30 Builder for SQL functions.
31*/
32
33#include <cstddef>
34
35#include "field_types.h"
36#include "lex_string.h"
37#include "my_inttypes.h" // uint
38#include "sql/parse_location.h" // POS
39
40/**
41 @addtogroup GROUP_PARSER
42 @{
43*/
44
45class Item;
46class PT_item_list;
47class THD;
48struct Cast_type;
49struct CHARSET_INFO;
50struct udf_func;
51enum class Json_on_response_type : uint16;
52
53/* For type casts */
54
55enum Cast_target : unsigned char {
74};
75
76/**
77 Public function builder interface.
78 The parser (sql/sql_yacc.yy) uses a factory / builder pattern to
79 construct an <code>Item</code> object for each function call.
80 All the concrete function builders implements this interface,
81 either directly or indirectly with some adapter helpers.
82 Keeping the function creation separated from the bison grammar allows
83 to simplify the parser, and avoid the need to introduce a new token
84 for each function, which has undesirable side effects in the grammar.
85*/
86
88 public:
89 /**
90 The builder create method.
91 Given the function name and list or arguments, this method creates
92 an <code>Item</code> that represents the function call.
93 In case or errors, a NULL item is returned, and an error is reported.
94 Note that the <code>thd</code> object may be modified by the builder.
95 In particular, the following members/methods can be set/called,
96 depending on the function called and the function possible side effects.
97 <ul>
98 <li><code>thd->lex->binlog_row_based_if_mixed</code></li>
99 <li><code>thd->lex->current_context()</code></li>
100 <li><code>thd->lex->safe_to_cache_query</code></li>
101 <li><code>thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT)</code></li>
102 <li><code>thd->lex->uncacheable(UNCACHEABLE_RAND)</code></li>
103 <li><code>thd->lex->add_time_zone_tables_to_query_tables(thd)</code></li>
104 </ul>
105 @param thd The current thread
106 @param name The function name
107 @param item_list The list of arguments to the function, can be NULL
108 @return An item representing the parsed function call, or NULL
109 */
111 PT_item_list *item_list) = 0;
112
113 protected:
114 Create_func() = default;
115 virtual ~Create_func() = default;
116};
117
118/**
119 Function builder for qualified functions.
120 This builder is used with functions call using a qualified function name
121 syntax, as in <code>db.func(expr, expr, ...)</code>.
122*/
123
124class Create_qfunc : public Create_func {
125 public:
126 /**
127 The builder create method, for unqualified functions.
128 This builder will use the current database for the database name.
129 @param thd The current thread
130 @param name The function name
131 @param item_list The list of arguments to the function, can be NULL
132 @return An item representing the parsed function call
133 */
135 PT_item_list *item_list) override;
136
137 /**
138 The builder create method, for qualified functions.
139 @param thd The current thread
140 @param db The database name or NULL_STR to use the default db name
141 @param name The function name
142 @param use_explicit_name Should the function be represented as 'db.name'?
143 @param item_list The list of arguments to the function, can be NULL
144 @return An item representing the parsed function call
145 */
147 bool use_explicit_name, PT_item_list *item_list) = 0;
148
149 protected:
150 /** Constructor. */
151 Create_qfunc() = default;
152 /** Destructor. */
153 ~Create_qfunc() override = default;
154};
155
156/**
157 Find the native function builder associated with a given function name.
158
159 @param name The native function name
160 @return The native function builder associated with the name, or NULL
161*/
163
164/**
165 Find the function builder for qualified functions.
166 @param thd The current thread
167 @return A function builder for qualified functions
168*/
170
171/**
172 Function builder for User Defined Functions.
173*/
174
176 public:
178 PT_item_list *item_list) override;
179
180 /**
181 The builder create method, for User Defined Functions.
182 @param thd The current thread
183 @param fct The User Defined Function metadata
184 @param item_list The list of arguments to the function, can be NULL
185 @return An item representing the parsed function call
186 */
187 Item *create(THD *thd, udf_func *fct, PT_item_list *item_list);
188
189 /** Singleton. */
191
192 protected:
193 /** Constructor. */
194 Create_udf_func() = default;
195 /** Destructor. */
196 ~Create_udf_func() override = default;
197};
198
199/**
200 Builder for cast expressions.
201 @param thd The current thread
202 @param pos Location of casting expression
203 @param arg The item to cast
204 @param type the type casted into
205 @param as_array Cast to array
206*/
207Item *create_func_cast(THD *thd, const POS &pos, Item *arg,
208 const Cast_type &type, bool as_array);
209
210Item *create_func_cast(THD *thd, const POS &pos, Item *a,
211 Cast_target cast_target, const CHARSET_INFO *cs_arg);
212
213/**
214 Creates an Item that represents a JSON_VALUE expression.
215
216 @param thd thread handler
217 @param pos the location of the expression
218 @param arg the JSON input argument to the JSON_VALUE expression
219 @param path the path to extract from the JSON document
220 @param type the target type of the JSON_VALUE expression
221 @param on_empty_type the type of the ON EMPTY clause
222 @param on_empty_default the default value specified in ON EMPTY, if any
223 @param on_error_type the type of the ON ERROR clause
224 @param on_error_default the default value specified in ON ERROR, if any
225 @return an Item on success, or nullptr on error
226*/
227Item *create_func_json_value(THD *thd, const POS &pos, Item *arg, Item *path,
228 const Cast_type &type,
229 Json_on_response_type on_empty_type,
230 Item *on_empty_default,
231 Json_on_response_type on_error_type,
232 Item *on_error_default);
233
234Item *create_temporal_literal(THD *thd, const char *str, size_t length,
236 bool send_error);
237
238/**
239 Load the hash table for native functions.
240 Note: this code is not thread safe, and is intended to be used at server
241 startup only (before going multi-threaded)
242
243 @retval false OK.
244 @retval true An exception was caught.
245*/
246bool item_create_init();
247
248/**
249 Empty the hash table for native functions.
250 Note: this code is not thread safe, and is intended to be used at server
251 shutdown only (after thread requests have been executed).
252*/
254
255/**
256 @} (end of group GROUP_PARSER)
257*/
258
259#endif
Public function builder interface.
Definition: item_create.h:87
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:124
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:175
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:853
Wrapper class for an Item list head, used to allocate Item lists in the parser in a context-independe...
Definition: parse_tree_helpers.h:104
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
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:54
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:55
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:190
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:64
static char * path
Definition: mysqldump.cc:140
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1063
Definition: commit_order_queue.h:33
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:75
required string type
Definition: replication_group_member_actions.proto:33
case opt name
Definition: sslopt-case.h:32
Definition: m_ctype.h:422
Definition: parser_yystype.h:180
Definition: mysql_lex_string.h:34
Bison "location" class.
Definition: parse_location.h:42
Definition: sql_udf.h:43
Json_on_response_type
Types of ON EMPTY/ON ERROR clauses for JSON_TABLE and JSON_VALUE.
Definition: table_function.h:191