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