1
/*****************************************************************************
3
Copyright (C) 1997, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/pars0sym.h
21
SQL parser symbol table
23
Created 12/15/1997 Heikki Tuuri
24
*******************************************************/
30
#include "que0types.h"
31
#include "usr0types.h"
32
#include "dict0types.h"
33
#include "pars0types.h"
34
#include "row0types.h"
36
/******************************************************************//**
37
Creates a symbol table for a single stored procedure or query.
38
@return own: symbol table */
43
mem_heap_t* heap); /*!< in: memory heap where to create */
44
/******************************************************************//**
45
Frees the memory allocated dynamically AFTER parsing phase for variables
46
etc. in the symbol table. Does not free the mem heap where the table was
47
originally created. Frees also SQL explicit cursor definitions. */
52
sym_tab_t* sym_tab); /*!< in, own: symbol table */
53
/******************************************************************//**
54
Adds an integer literal to a symbol table.
55
@return symbol table node */
63
sym_tab_t* sym_tab, /*!< in: symbol table */
64
ulint val); /*!< in: integer value */
65
/******************************************************************//**
66
Adds an string literal to a symbol table.
67
@return symbol table node */
75
sym_tab_t* sym_tab, /*!< in: symbol table */
76
byte* str, /*!< in: string with no quotes around
78
ulint len); /*!< in: string length */
79
/******************************************************************//**
80
Add a bound literal to a symbol table.
81
@return symbol table node */
87
sym_tab_add_bound_lit(
88
/*==================*/
89
sym_tab_t* sym_tab, /*!< in: symbol table */
90
const char* name, /*!< in: name of bound literal */
91
ulint* lit_type); /*!< out: type of literal (PARS_*_LIT) */
92
/******************************************************************//**
93
Adds an SQL null literal to a symbol table.
94
@return symbol table node */
100
sym_tab_add_null_lit(
101
/*=================*/
102
sym_tab_t* sym_tab); /*!< in: symbol table */
103
/******************************************************************//**
104
Adds an identifier to a symbol table.
105
@return symbol table node */
113
sym_tab_t* sym_tab, /*!< in: symbol table */
114
byte* name, /*!< in: identifier name */
115
ulint len); /*!< in: identifier length */
117
/******************************************************************//**
118
Add a bound identifier to a symbol table.
119
@return symbol table node */
125
sym_tab_add_bound_id(
127
sym_tab_t* sym_tab, /*!< in: symbol table */
128
const char* name); /*!< in: name of bound id */
130
/** Index of sym_node_struct::field_nos corresponding to the clustered index */
131
#define SYM_CLUST_FIELD_NO 0
132
/** Index of sym_node_struct::field_nos corresponding to a secondary index */
133
#define SYM_SEC_FIELD_NO 1
135
/** Types of a symbol table node */
137
SYM_VAR = 91, /*!< declared parameter or local
138
variable of a procedure */
139
SYM_IMPLICIT_VAR, /*!< storage for a intermediate result
141
SYM_LIT, /*!< literal */
142
SYM_TABLE, /*!< database table name */
143
SYM_COLUMN, /*!< database table name */
144
SYM_CURSOR, /*!< named cursor */
145
SYM_PROCEDURE_NAME, /*!< stored procedure name */
146
SYM_INDEX, /*!< database index name */
147
SYM_FUNCTION /*!< user function name */
150
/** Symbol table node */
151
struct sym_node_struct{
152
que_common_t common; /*!< node type:
154
/* NOTE: if the data field in 'common.val' is not NULL and the symbol
155
table node is not for a temporary column, the memory for the value has
156
been allocated from dynamic memory and it should be freed when the
157
symbol table is discarded */
159
/* 'alias' and 'indirection' are almost the same, but not quite.
160
'alias' always points to the primary instance of the variable, while
161
'indirection' does the same only if we should use the primary
162
instance's values for the node's data. This is usually the case, but
163
when initializing a cursor (e.g., "DECLARE CURSOR c IS SELECT * FROM
164
t WHERE id = x;"), we copy the values from the primary instance to
165
the cursor's instance so that they are fixed for the duration of the
166
cursor, and set 'indirection' to NULL. If we did not, the value of
167
'x' could change between fetches and things would break horribly.
169
TODO: It would be cleaner to make 'indirection' a boolean field and
170
always use 'alias' to refer to the primary node. */
172
sym_node_t* indirection; /*!< pointer to
176
node, NULL otherwise */
177
sym_node_t* alias; /*!< pointer to
182
UT_LIST_NODE_T(sym_node_t) col_var_list; /*!< list of table
184
input variables for an
186
ibool copy_val; /*!< TRUE if a column
189
memory when fetched */
190
ulint field_nos[2]; /*!< if a column, in
192
SYM_CLUST_FIELD_NO is
193
the field number in the
197
the field number in the
198
non-clustered index to
199
use first; if not found
202
ibool resolved; /*!< TRUE if the
203
meaning of a variable
205
resolved; for literals
206
this is always TRUE */
207
enum sym_tab_entry token_type; /*!< type of the
209
const char* name; /*!< name of an id */
210
ulint name_len; /*!< id name length */
211
dict_table_t* table; /*!< table definition
214
ulint col_no; /*!< column number if a
216
sel_buf_t* prefetch_buf; /*!< NULL, or a buffer
218
values for prefetched
220
sel_node_t* cursor_def; /*!< cursor definition
223
ulint param_type; /*!< PARS_INPUT,
225
PARS_NOT_PARAM if not a
226
procedure parameter */
227
sym_tab_t* sym_table; /*!< back pointer to
229
UT_LIST_NODE_T(sym_node_t) sym_list; /*!< list of symbol
234
struct sym_tab_struct{
236
/*!< query graph generated by the
238
const char* sql_string;
239
/*!< SQL string to parse */
241
/*!< SQL string length */
243
/*!< position of the next character in
244
sql_string to give to the lexical
246
pars_info_t* info; /*!< extra information, or NULL */
247
sym_node_list_t sym_list;
248
/*!< list of symbol nodes in the symbol
250
UT_LIST_BASE_NODE_T(func_node_t)
252
/*!< list of function nodes in the
253
parsed query graph */
254
mem_heap_t* heap; /*!< memory heap from which we can
259
#include "pars0sym.ic"