1
/*****************************************************************************
3
Copyright (c) 1997, 2009, Oracle and/or its affiliates. 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.,
15
51 Franklin Street, Suite 500, Boston, MA 02110-1335 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
const 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
Rebind literal to a node in the symbol table. */
89
/* out: symbol table node */
90
sym_node_t* node, /* in: node that is bound to literal*/
91
const void* address, /* in: pointer to data */
92
ulint length); /* in: length of data */
93
/******************************************************************//**
94
Adds an SQL null literal to a symbol table.
95
@return symbol table node */
100
sym_tab_t* sym_tab); /*!< in: symbol table */
101
/******************************************************************//**
102
Adds an identifier to a symbol table.
103
@return symbol table node */
108
sym_tab_t* sym_tab, /*!< in: symbol table */
109
byte* name, /*!< in: identifier name */
110
ulint len); /*!< in: identifier length */
112
/******************************************************************//**
113
Add a bound identifier to a symbol table.
114
@return symbol table node */
117
sym_tab_add_bound_id(
119
sym_tab_t* sym_tab, /*!< in: symbol table */
120
const char* name); /*!< in: name of bound id */
122
/** Index of sym_node_t::field_nos corresponding to the clustered index */
123
#define SYM_CLUST_FIELD_NO 0
124
/** Index of sym_node_t::field_nos corresponding to a secondary index */
125
#define SYM_SEC_FIELD_NO 1
127
/** Types of a symbol table node */
129
SYM_UNSET, /*!< Unset entry. */
130
SYM_VAR = 91, /*!< declared parameter or local
131
variable of a procedure */
132
SYM_IMPLICIT_VAR, /*!< storage for a intermediate result
134
SYM_LIT, /*!< literal */
135
SYM_TABLE_REF_COUNTED, /*!< database table name, ref counted. Must
136
be closed explicitly. */
137
SYM_TABLE, /*!< database table name */
138
SYM_COLUMN, /*!< database table name */
139
SYM_CURSOR, /*!< named cursor */
140
SYM_PROCEDURE_NAME, /*!< stored procedure name */
141
SYM_INDEX, /*!< database index name */
142
SYM_FUNCTION /*!< user function name */
145
/** Symbol table node */
147
que_common_t common; /*!< node type:
149
/* NOTE: if the data field in 'common.val' is not NULL and the symbol
150
table node is not for a temporary column, the memory for the value has
151
been allocated from dynamic memory and it should be freed when the
152
symbol table is discarded */
154
/* 'alias' and 'indirection' are almost the same, but not quite.
155
'alias' always points to the primary instance of the variable, while
156
'indirection' does the same only if we should use the primary
157
instance's values for the node's data. This is usually the case, but
158
when initializing a cursor (e.g., "DECLARE CURSOR c IS SELECT * FROM
159
t WHERE id = x;"), we copy the values from the primary instance to
160
the cursor's instance so that they are fixed for the duration of the
161
cursor, and set 'indirection' to NULL. If we did not, the value of
162
'x' could change between fetches and things would break horribly.
164
TODO: It would be cleaner to make 'indirection' a boolean field and
165
always use 'alias' to refer to the primary node. */
167
sym_node_t* indirection; /*!< pointer to
171
node, NULL otherwise */
172
sym_node_t* alias; /*!< pointer to
177
UT_LIST_NODE_T(sym_node_t) col_var_list; /*!< list of table
179
input variables for an
181
ibool copy_val; /*!< TRUE if a column
184
memory when fetched */
185
ulint field_nos[2]; /*!< if a column, in
187
SYM_CLUST_FIELD_NO is
188
the field number in the
192
the field number in the
193
non-clustered index to
194
use first; if not found
197
ibool resolved; /*!< TRUE if the
198
meaning of a variable
200
resolved; for literals
201
this is always TRUE */
202
enum sym_tab_entry token_type; /*!< type of the
204
const char* name; /*!< name of an id */
205
ulint name_len; /*!< id name length */
206
dict_table_t* table; /*!< table definition
209
ulint col_no; /*!< column number if a
211
sel_buf_t* prefetch_buf; /*!< NULL, or a buffer
213
values for prefetched
215
sel_node_t* cursor_def; /*!< cursor definition
218
ulint param_type; /*!< PARS_INPUT,
220
PARS_NOT_PARAM if not a
221
procedure parameter */
222
sym_tab_t* sym_table; /*!< back pointer to
224
UT_LIST_NODE_T(sym_node_t) sym_list; /*!< list of symbol
226
sym_node_t* like_node; /* LIKE operator node*/
232
/*!< query graph generated by the
234
const char* sql_string;
235
/*!< SQL string to parse */
237
/*!< SQL string length */
239
/*!< position of the next character in
240
sql_string to give to the lexical
242
pars_info_t* info; /*!< extra information, or NULL */
243
sym_node_list_t sym_list;
244
/*!< list of symbol nodes in the symbol
246
UT_LIST_BASE_NODE_T(func_node_t)
248
/*!< list of function nodes in the
249
parsed query graph */
250
mem_heap_t* heap; /*!< memory heap from which we can
255
#include "pars0sym.ic"