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 */
60
sym_tab_t* sym_tab, /*!< in: symbol table */
61
ulint val); /*!< in: integer value */
62
/******************************************************************//**
63
Adds an string literal to a symbol table.
64
@return symbol table node */
69
sym_tab_t* sym_tab, /*!< in: symbol table */
70
byte* str, /*!< in: string with no quotes around
72
ulint len); /*!< in: string length */
73
/******************************************************************//**
74
Add a bound literal to a symbol table.
75
@return symbol table node */
78
sym_tab_add_bound_lit(
79
/*==================*/
80
sym_tab_t* sym_tab, /*!< in: symbol table */
81
const char* name, /*!< in: name of bound literal */
82
ulint* lit_type); /*!< out: type of literal (PARS_*_LIT) */
83
/******************************************************************//**
84
Adds an SQL null literal to a symbol table.
85
@return symbol table node */
90
sym_tab_t* sym_tab); /*!< in: symbol table */
91
/******************************************************************//**
92
Adds an identifier to a symbol table.
93
@return symbol table node */
98
sym_tab_t* sym_tab, /*!< in: symbol table */
99
byte* name, /*!< in: identifier name */
100
ulint len); /*!< in: identifier length */
102
/******************************************************************//**
103
Add a bound identifier to a symbol table.
104
@return symbol table node */
107
sym_tab_add_bound_id(
109
sym_tab_t* sym_tab, /*!< in: symbol table */
110
const char* name); /*!< in: name of bound id */
112
/** Index of sym_node_struct::field_nos corresponding to the clustered index */
113
#define SYM_CLUST_FIELD_NO 0
114
/** Index of sym_node_struct::field_nos corresponding to a secondary index */
115
#define SYM_SEC_FIELD_NO 1
117
/** Types of a symbol table node */
119
SYM_VAR = 91, /*!< declared parameter or local
120
variable of a procedure */
121
SYM_IMPLICIT_VAR, /*!< storage for a intermediate result
123
SYM_LIT, /*!< literal */
124
SYM_TABLE, /*!< database table name */
125
SYM_COLUMN, /*!< database table name */
126
SYM_CURSOR, /*!< named cursor */
127
SYM_PROCEDURE_NAME, /*!< stored procedure name */
128
SYM_INDEX, /*!< database index name */
129
SYM_FUNCTION /*!< user function name */
132
/** Symbol table node */
133
struct sym_node_struct{
134
que_common_t common; /*!< node type:
136
/* NOTE: if the data field in 'common.val' is not NULL and the symbol
137
table node is not for a temporary column, the memory for the value has
138
been allocated from dynamic memory and it should be freed when the
139
symbol table is discarded */
141
/* 'alias' and 'indirection' are almost the same, but not quite.
142
'alias' always points to the primary instance of the variable, while
143
'indirection' does the same only if we should use the primary
144
instance's values for the node's data. This is usually the case, but
145
when initializing a cursor (e.g., "DECLARE CURSOR c IS SELECT * FROM
146
t WHERE id = x;"), we copy the values from the primary instance to
147
the cursor's instance so that they are fixed for the duration of the
148
cursor, and set 'indirection' to NULL. If we did not, the value of
149
'x' could change between fetches and things would break horribly.
151
TODO: It would be cleaner to make 'indirection' a boolean field and
152
always use 'alias' to refer to the primary node. */
154
sym_node_t* indirection; /*!< pointer to
158
node, NULL otherwise */
159
sym_node_t* alias; /*!< pointer to
164
UT_LIST_NODE_T(sym_node_t) col_var_list; /*!< list of table
166
input variables for an
168
ibool copy_val; /*!< TRUE if a column
171
memory when fetched */
172
ulint field_nos[2]; /*!< if a column, in
174
SYM_CLUST_FIELD_NO is
175
the field number in the
179
the field number in the
180
non-clustered index to
181
use first; if not found
184
ibool resolved; /*!< TRUE if the
185
meaning of a variable
187
resolved; for literals
188
this is always TRUE */
189
enum sym_tab_entry token_type; /*!< type of the
191
const char* name; /*!< name of an id */
192
ulint name_len; /*!< id name length */
193
dict_table_t* table; /*!< table definition
196
ulint col_no; /*!< column number if a
198
sel_buf_t* prefetch_buf; /*!< NULL, or a buffer
200
values for prefetched
202
sel_node_t* cursor_def; /*!< cursor definition
205
ulint param_type; /*!< PARS_INPUT,
207
PARS_NOT_PARAM if not a
208
procedure parameter */
209
sym_tab_t* sym_table; /*!< back pointer to
211
UT_LIST_NODE_T(sym_node_t) sym_list; /*!< list of symbol
216
struct sym_tab_struct{
218
/*!< query graph generated by the
220
const char* sql_string;
221
/*!< SQL string to parse */
223
/*!< SQL string length */
225
/*!< position of the next character in
226
sql_string to give to the lexical
228
pars_info_t* info; /*!< extra information, or NULL */
229
sym_node_list_t sym_list;
230
/*!< list of symbol nodes in the symbol
232
UT_LIST_BASE_NODE_T(func_node_t)
234
/*!< list of function nodes in the
235
parsed query graph */
236
mem_heap_t* heap; /*!< memory heap from which we can
241
#include "pars0sym.ic"