MySQL 8.2.0
Source Code Documentation
pars0sym.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1997, 2023, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/pars0sym.h
28 SQL parser symbol table
29
30 Created 12/15/1997 Heikki Tuuri
31 *******************************************************/
32
33#ifndef pars0sym_h
34#define pars0sym_h
35
36#include "dict0types.h"
37#include "pars0types.h"
38#include "que0types.h"
39#include "row0types.h"
40#include "univ.i"
41#include "usr0types.h"
42
43/** Creates a symbol table for a single stored procedure or query.
44 @return own: symbol table */
46 mem_heap_t *heap); /*!< in: memory heap where to create */
47/** Frees the memory allocated dynamically AFTER parsing phase for variables
48 etc. in the symbol table. Does not free the mem heap where the table was
49 originally created. Frees also SQL explicit cursor definitions. */
50void sym_tab_free_private(sym_tab_t *sym_tab); /*!< in, own: symbol table */
51/** Adds an integer literal to a symbol table.
52 @return symbol table node */
53sym_node_t *sym_tab_add_int_lit(sym_tab_t *sym_tab, /*!< in: symbol table */
54 ulint val); /*!< in: integer value */
55/** Adds an string literal to a symbol table.
56 @return symbol table node */
57sym_node_t *sym_tab_add_str_lit(sym_tab_t *sym_tab, /*!< in: symbol table */
58 const byte *str, /*!< in: string with no quotes
59 around it */
60 ulint len); /*!< in: string length */
61/** Add a bound literal to a symbol table.
62 @return symbol table node */
64 sym_tab_t *sym_tab, /*!< in: symbol table */
65 const char *name, /*!< in: name of bound literal */
66 ulint *lit_type); /*!< out: type of literal (PARS_*_LIT) */
67/**********************************************************************
68Rebind literal to a node in the symbol table. */
70 /* out: symbol table node */
71 sym_node_t *node, /* in: node that is bound to literal*/
72 const void *address, /* in: pointer to data */
73 ulint length); /* in: length of data */
74/** Adds an SQL null literal to a symbol table.
75 @return symbol table node */
76sym_node_t *sym_tab_add_null_lit(sym_tab_t *sym_tab); /*!< in: symbol table */
77/** Adds an identifier to a symbol table.
78 @return symbol table node */
79sym_node_t *sym_tab_add_id(sym_tab_t *sym_tab, /*!< in: symbol table */
80 byte *name, /*!< in: identifier name */
81 ulint len); /*!< in: identifier length */
82
83/** Add a bound identifier to a symbol table.
84 @return symbol table node */
85sym_node_t *sym_tab_add_bound_id(sym_tab_t *sym_tab, /*!< in: symbol table */
86 const char *name); /*!< in: name of bound id */
87
88/** Index of sym_node_t::field_nos corresponding to the clustered index */
89#define SYM_CLUST_FIELD_NO 0
90/** Index of sym_node_t::field_nos corresponding to a secondary index */
91#define SYM_SEC_FIELD_NO 1
92
93/** Types of a symbol table node */
95 SYM_UNSET, /*!< Unset entry. */
96 SYM_VAR = 91, /*!< declared parameter or local
97 variable of a procedure */
98 SYM_IMPLICIT_VAR, /*!< storage for a intermediate result
99 of a calculation */
100 SYM_LIT, /*!< literal */
101 SYM_TABLE_REF_COUNTED, /*!< database table name, ref counted. Must
102 be closed explicitly. */
103 SYM_TABLE, /*!< database table name */
104 SYM_COLUMN, /*!< database table name */
105 SYM_CURSOR, /*!< named cursor */
106 SYM_PROCEDURE_NAME, /*!< stored procedure name */
107 SYM_INDEX, /*!< database index name */
108 SYM_FUNCTION /*!< user function name */
110
111/** Symbol table node */
113 que_common_t common; /*!< node type:
114 QUE_NODE_SYMBOL */
115 /* NOTE: if the data field in 'common.val' is not NULL and the symbol
116 table node is not for a temporary column, the memory for the value has
117 been allocated from dynamic memory and it should be freed when the
118 symbol table is discarded */
119
120 /* 'alias' and 'indirection' are almost the same, but not quite.
121 'alias' always points to the primary instance of the variable, while
122 'indirection' does the same only if we should use the primary
123 instance's values for the node's data. This is usually the case, but
124 when initializing a cursor (e.g., "DECLARE CURSOR c IS SELECT * FROM
125 t WHERE id = x;"), we copy the values from the primary instance to
126 the cursor's instance so that they are fixed for the duration of the
127 cursor, and set 'indirection' to NULL. If we did not, the value of
128 'x' could change between fetches and things would break horribly.
129
130 TODO: It would be cleaner to make 'indirection' a boolean field and
131 always use 'alias' to refer to the primary node. */
132
133 sym_node_t *indirection; /*!< pointer to
134 another symbol table
135 node which contains
136 the value for this
137 node, NULL otherwise */
138 sym_node_t *alias; /*!< pointer to
139 another symbol table
140 node for which this
141 node is an alias,
142 NULL otherwise */
144 col_var_list; /*!< list of table
145 columns or a list of
146 input variables for an
147 explicit cursor */
148 bool copy_val; /*!< true if a column
149 and its value should
150 be copied to dynamic
151 memory when fetched */
152 ulint field_nos[2]; /*!< if a column, in
153 the position
154 SYM_CLUST_FIELD_NO is
155 the field number in the
156 clustered index; in
157 the position
158 SYM_SEC_FIELD_NO
159 the field number in the
160 non-clustered index to
161 use first; if not found
162 from the index, then
163 ULINT_UNDEFINED */
164 bool resolved; /*!< true if the
165 meaning of a variable
166 or a column has been
167 resolved; for literals
168 this is always true */
169 enum sym_tab_entry token_type; /*!< type of the
170 parsed token */
171 const char *name; /*!< name of an id */
172 ulint name_len; /*!< id name length */
173 dict_table_t *table; /*!< table definition
174 if a table id or a
175 column id */
176 ulint col_no; /*!< column number if a
177 column */
178 sel_buf_t *prefetch_buf; /*!< NULL, or a buffer
179 for cached column
180 values for prefetched
181 rows */
182 sel_node_t *cursor_def; /*!< cursor definition
183 select node if a
184 named cursor */
185 ulint param_type; /*!< PARS_INPUT,
186 PARS_OUTPUT, or
187 PARS_NOT_PARAM if not a
188 procedure parameter */
189 sym_tab_t *sym_table; /*!< back pointer to
190 the symbol table */
192 sym_list; /*!< list of symbol
193 nodes */
194 sym_node_t *like_node; /* LIKE operator node*/
195
196 MDL_ticket *mdl; /* MDL placed on table */
197};
198
200
201/** Symbol table */
202struct sym_tab_t {
204 /*!< query graph generated by the
205 parser */
206 const char *sql_string;
207 /*!< SQL string to parse */
209 /*!< SQL string length */
211 /*!< position of the next character in
212 sql_string to give to the lexical
213 analyzer */
214 pars_info_t *info; /*!< extra information, or NULL */
216 /*!< list of symbol nodes in the symbol
217 table */
218 UT_LIST_BASE_NODE_T_EXTERN(func_node_t, func_node_list) func_node_list;
219 /*!< list of function nodes in the
220 parsed query graph */
221 mem_heap_t *heap; /*!< memory heap from which we can
222 allocate space */
223};
224
225#endif
A granted metadata lock.
Definition: mdl.h:984
Data dictionary global types.
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1085
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
sym_node_t * sym_tab_rebind_lit(sym_node_t *node, const void *address, ulint length)
Definition: pars0sym.cc:260
sym_tab_t * sym_tab_create(mem_heap_t *heap)
Creates a symbol table for a single stored procedure or query.
Definition: pars0sym.cc:48
sym_tab_entry
Types of a symbol table node.
Definition: pars0sym.h:94
@ SYM_COLUMN
database table name
Definition: pars0sym.h:104
@ SYM_PROCEDURE_NAME
stored procedure name
Definition: pars0sym.h:106
@ SYM_TABLE_REF_COUNTED
database table name, ref counted.
Definition: pars0sym.h:101
@ SYM_VAR
declared parameter or local variable of a procedure
Definition: pars0sym.h:96
@ SYM_CURSOR
named cursor
Definition: pars0sym.h:105
@ SYM_TABLE
database table name
Definition: pars0sym.h:103
@ SYM_IMPLICIT_VAR
storage for a intermediate result of a calculation
Definition: pars0sym.h:98
@ SYM_FUNCTION
user function name
Definition: pars0sym.h:108
@ SYM_UNSET
Unset entry.
Definition: pars0sym.h:95
@ SYM_LIT
literal
Definition: pars0sym.h:100
@ SYM_INDEX
database index name
Definition: pars0sym.h:107
sym_node_t * sym_tab_add_null_lit(sym_tab_t *sym_tab)
Adds an SQL null literal to a symbol table.
Definition: pars0sym.cc:299
sym_node_t * sym_tab_add_str_lit(sym_tab_t *sym_tab, const byte *str, ulint len)
Adds an string literal to a symbol table.
Definition: pars0sym.cc:143
void sym_tab_free_private(sym_tab_t *sym_tab)
Frees the memory allocated dynamically AFTER parsing phase for variables etc.
Definition: pars0sym.cc:66
sym_node_t * sym_tab_add_int_lit(sym_tab_t *sym_tab, ulint val)
Adds an integer literal to a symbol table.
Definition: pars0sym.cc:104
sym_node_t * sym_tab_add_bound_lit(sym_tab_t *sym_tab, const char *name, ulint *lit_type)
Add a bound literal to a symbol table.
Definition: pars0sym.cc:184
sym_node_t * sym_tab_add_bound_id(sym_tab_t *sym_tab, const char *name)
Add a bound identifier to a symbol table.
Definition: pars0sym.cc:358
sym_node_t * sym_tab_add_id(sym_tab_t *sym_tab, byte *name, ulint len)
Adds an identifier to a symbol table.
Definition: pars0sym.cc:333
SQL parser global types.
Query graph global types.
Row operation global types.
case opt name
Definition: sslopt-case.h:32
Data structure for a database table.
Definition: dict0mem.h:1908
A predefined function or operator node in a parsing tree; this construct is also used for some non-fu...
Definition: pars0pars.h:496
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:301
Extra information supplied for pars_sql().
Definition: pars0pars.h:451
Definition: que0types.h:50
Definition: que0que.h:300
A structure for caching column values for prefetched rows.
Definition: row0sel.h:233
Select statement node.
Definition: row0sel.h:328
Symbol table node.
Definition: pars0sym.h:112
sel_node_t * cursor_def
cursor definition select node if a named cursor
Definition: pars0sym.h:182
bool resolved
true if the meaning of a variable or a column has been resolved; for literals this is always true
Definition: pars0sym.h:164
ulint name_len
id name length
Definition: pars0sym.h:172
enum sym_tab_entry token_type
type of the parsed token
Definition: pars0sym.h:169
dict_table_t * table
table definition if a table id or a column id
Definition: pars0sym.h:173
sel_buf_t * prefetch_buf
NULL, or a buffer for cached column values for prefetched rows.
Definition: pars0sym.h:178
MDL_ticket * mdl
Definition: pars0sym.h:196
sym_list
list of symbol nodes
Definition: pars0sym.h:192
sym_node_t * alias
pointer to another symbol table node for which this node is an alias, NULL otherwise
Definition: pars0sym.h:138
ulint field_nos[2]
if a column, in the position SYM_CLUST_FIELD_NO is the field number in the clustered index; in the po...
Definition: pars0sym.h:152
ulint param_type
PARS_INPUT, PARS_OUTPUT, or PARS_NOT_PARAM if not a procedure parameter.
Definition: pars0sym.h:185
col_var_list
list of table columns or a list of input variables for an explicit cursor
Definition: pars0sym.h:144
sym_node_t * like_node
Definition: pars0sym.h:194
sym_tab_t * sym_table
back pointer to the symbol table
Definition: pars0sym.h:189
que_common_t common
node type: QUE_NODE_SYMBOL
Definition: pars0sym.h:113
bool copy_val
true if a column and its value should be copied to dynamic memory when fetched
Definition: pars0sym.h:148
sym_node_t * indirection
pointer to another symbol table node which contains the value for this node, NULL otherwise
Definition: pars0sym.h:133
const char * name
name of an id
Definition: pars0sym.h:171
ulint col_no
column number if a column
Definition: pars0sym.h:176
Symbol table.
Definition: pars0sym.h:202
mem_heap_t * heap
memory heap from which we can allocate space
Definition: pars0sym.h:221
UT_LIST_BASE_NODE_T(sym_node_t, sym_list) sym_list
list of symbol nodes in the symbol table
size_t string_len
SQL string length.
Definition: pars0sym.h:208
int next_char_pos
position of the next character in sql_string to give to the lexical analyzer
Definition: pars0sym.h:210
que_t * query_graph
query graph generated by the parser
Definition: pars0sym.h:203
UT_LIST_BASE_NODE_T_EXTERN(func_node_t, func_node_list) func_node_list
list of function nodes in the parsed query graph
pars_info_t * info
extra information, or NULL
Definition: pars0sym.h:214
const char * sql_string
SQL string to parse.
Definition: pars0sym.h:206
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:405
Users and sessions global types.
#define UT_LIST_NODE_GETTER_DEFINITION(t, m)
A helper for the UT_LIST_BASE_NODE_T_EXTERN which declares a node getter struct which extracts member...
Definition: ut0lst.h:269
#define UT_LIST_NODE_T(t)
Macro used for legacy reasons.
Definition: ut0lst.h:63