~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/pars0sym.h

Merge Stewart's dead code removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1997, 2009, Innobase Oy. All Rights Reserved.
4
 
 
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.
8
 
 
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.
12
 
 
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
16
 
 
17
 
*****************************************************************************/
18
 
 
19
 
/**************************************************//**
20
 
@file include/pars0sym.h
21
 
SQL parser symbol table
22
 
 
23
 
Created 12/15/1997 Heikki Tuuri
24
 
*******************************************************/
25
 
 
26
 
#ifndef pars0sym_h
27
 
#define pars0sym_h
28
 
 
29
 
#include "univ.i"
30
 
#include "que0types.h"
31
 
#include "usr0types.h"
32
 
#include "dict0types.h"
33
 
#include "pars0types.h"
34
 
#include "row0types.h"
35
 
 
36
 
/******************************************************************//**
37
 
Creates a symbol table for a single stored procedure or query.
38
 
@return own: symbol table */
39
 
UNIV_INTERN
40
 
sym_tab_t*
41
 
sym_tab_create(
42
 
/*===========*/
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. */
48
 
UNIV_INTERN
49
 
void
50
 
sym_tab_free_private(
51
 
/*=================*/
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 */
56
 
#ifdef __cplusplus
57
 
extern "C"
58
 
#endif
59
 
UNIV_INTERN
60
 
sym_node_t*
61
 
sym_tab_add_int_lit(
62
 
/*================*/
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 */
68
 
#ifdef __cplusplus
69
 
extern "C"
70
 
#endif
71
 
UNIV_INTERN
72
 
sym_node_t*
73
 
sym_tab_add_str_lit(
74
 
/*================*/
75
 
        sym_tab_t*      sym_tab,        /*!< in: symbol table */
76
 
        byte*           str,            /*!< in: string with no quotes around
77
 
                                        it */
78
 
        ulint           len);           /*!< in: string length */
79
 
/******************************************************************//**
80
 
Add a bound literal to a symbol table.
81
 
@return symbol table node */
82
 
#ifdef __cplusplus
83
 
extern "C"
84
 
#endif
85
 
UNIV_INTERN
86
 
sym_node_t*
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 */
95
 
#ifdef __cplusplus
96
 
extern "C"
97
 
#endif
98
 
UNIV_INTERN
99
 
sym_node_t*
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 */
106
 
#ifdef __cplusplus
107
 
extern "C"
108
 
#endif
109
 
UNIV_INTERN
110
 
sym_node_t*
111
 
sym_tab_add_id(
112
 
/*===========*/
113
 
        sym_tab_t*      sym_tab,        /*!< in: symbol table */
114
 
        byte*           name,           /*!< in: identifier name */
115
 
        ulint           len);           /*!< in: identifier length */
116
 
 
117
 
/******************************************************************//**
118
 
Add a bound identifier to a symbol table.
119
 
@return symbol table node */
120
 
#ifdef __cplusplus
121
 
extern "C"
122
 
#endif
123
 
UNIV_INTERN
124
 
sym_node_t*
125
 
sym_tab_add_bound_id(
126
 
/*===========*/
127
 
        sym_tab_t*      sym_tab,        /*!< in: symbol table */
128
 
        const char*     name);          /*!< in: name of bound id */
129
 
 
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
134
 
 
135
 
/** Types of a symbol table node */
136
 
enum sym_tab_entry {
137
 
        SYM_VAR = 91,           /*!< declared parameter or local
138
 
                                variable of a procedure */
139
 
        SYM_IMPLICIT_VAR,       /*!< storage for a intermediate result
140
 
                                of a calculation */
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 */
148
 
};
149
 
 
150
 
/** Symbol table node */
151
 
struct sym_node_struct{
152
 
        que_common_t                    common;         /*!< node type:
153
 
                                                        QUE_NODE_SYMBOL */
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 */
158
 
 
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.
168
 
 
169
 
        TODO: It would be cleaner to make 'indirection' a boolean field and
170
 
        always use 'alias' to refer to the primary node. */
171
 
 
172
 
        sym_node_t*                     indirection;    /*!< pointer to
173
 
                                                        another symbol table
174
 
                                                        node which contains
175
 
                                                        the value for this
176
 
                                                        node, NULL otherwise */
177
 
        sym_node_t*                     alias;          /*!< pointer to
178
 
                                                        another symbol table
179
 
                                                        node for which this
180
 
                                                        node is an alias,
181
 
                                                        NULL otherwise */
182
 
        UT_LIST_NODE_T(sym_node_t)      col_var_list;   /*!< list of table
183
 
                                                        columns or a list of
184
 
                                                        input variables for an
185
 
                                                        explicit cursor */
186
 
        ibool                           copy_val;       /*!< TRUE if a column
187
 
                                                        and its value should
188
 
                                                        be copied to dynamic
189
 
                                                        memory when fetched */
190
 
        ulint                           field_nos[2];   /*!< if a column, in
191
 
                                                        the position
192
 
                                                        SYM_CLUST_FIELD_NO is
193
 
                                                        the field number in the
194
 
                                                        clustered index; in
195
 
                                                        the position
196
 
                                                        SYM_SEC_FIELD_NO
197
 
                                                        the field number in the
198
 
                                                        non-clustered index to
199
 
                                                        use first; if not found
200
 
                                                        from the index, then
201
 
                                                        ULINT_UNDEFINED */
202
 
        ibool                           resolved;       /*!< TRUE if the
203
 
                                                        meaning of a variable
204
 
                                                        or a column has been
205
 
                                                        resolved; for literals
206
 
                                                        this is always TRUE */
207
 
        enum sym_tab_entry              token_type;     /*!< type of the
208
 
                                                        parsed token */
209
 
        const char*                     name;           /*!< name of an id */
210
 
        ulint                           name_len;       /*!< id name length */
211
 
        dict_table_t*                   table;          /*!< table definition
212
 
                                                        if a table id or a
213
 
                                                        column id */
214
 
        ulint                           col_no;         /*!< column number if a
215
 
                                                        column */
216
 
        sel_buf_t*                      prefetch_buf;   /*!< NULL, or a buffer
217
 
                                                        for cached column
218
 
                                                        values for prefetched
219
 
                                                        rows */
220
 
        sel_node_t*                     cursor_def;     /*!< cursor definition
221
 
                                                        select node if a
222
 
                                                        named cursor */
223
 
        ulint                           param_type;     /*!< PARS_INPUT,
224
 
                                                        PARS_OUTPUT, or
225
 
                                                        PARS_NOT_PARAM if not a
226
 
                                                        procedure parameter */
227
 
        sym_tab_t*                      sym_table;      /*!< back pointer to
228
 
                                                        the symbol table */
229
 
        UT_LIST_NODE_T(sym_node_t)      sym_list;       /*!< list of symbol
230
 
                                                        nodes */
231
 
};
232
 
 
233
 
/** Symbol table */
234
 
struct sym_tab_struct{
235
 
        que_t*                  query_graph;
236
 
                                        /*!< query graph generated by the
237
 
                                        parser */
238
 
        const char*             sql_string;
239
 
                                        /*!< SQL string to parse */
240
 
        size_t                  string_len;
241
 
                                        /*!< SQL string length */
242
 
        int                     next_char_pos;
243
 
                                        /*!< position of the next character in
244
 
                                        sql_string to give to the lexical
245
 
                                        analyzer */
246
 
        pars_info_t*            info;   /*!< extra information, or NULL */
247
 
        sym_node_list_t         sym_list;
248
 
                                        /*!< list of symbol nodes in the symbol
249
 
                                        table */
250
 
        UT_LIST_BASE_NODE_T(func_node_t)
251
 
                                func_node_list;
252
 
                                        /*!< list of function nodes in the
253
 
                                        parsed query graph */
254
 
        mem_heap_t*             heap;   /*!< memory heap from which we can
255
 
                                        allocate space */
256
 
};
257
 
 
258
 
#ifndef UNIV_NONINL
259
 
#include "pars0sym.ic"
260
 
#endif
261
 
 
262
 
#endif