~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2010-04-22 02:46:23 UTC
  • mto: (1497.3.4 enable-dtrace)
  • mto: This revision was merged to the branch mainline in revision 1527.
  • Revision ID: mordred@inaugust.com-20100422024623-4urw8fi8eraci08p
Don't overwrite the pandora_vc_revinfo file if we don't have new
authoratative information.

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
 
UNIV_INTERN
57
 
sym_node_t*
58
 
sym_tab_add_int_lit(
59
 
/*================*/
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 */
65
 
UNIV_INTERN
66
 
sym_node_t*
67
 
sym_tab_add_str_lit(
68
 
/*================*/
69
 
        sym_tab_t*      sym_tab,        /*!< in: symbol table */
70
 
        byte*           str,            /*!< in: string with no quotes around
71
 
                                        it */
72
 
        ulint           len);           /*!< in: string length */
73
 
/******************************************************************//**
74
 
Add a bound literal to a symbol table.
75
 
@return symbol table node */
76
 
UNIV_INTERN
77
 
sym_node_t*
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 */
86
 
UNIV_INTERN
87
 
sym_node_t*
88
 
sym_tab_add_null_lit(
89
 
/*=================*/
90
 
        sym_tab_t*      sym_tab);       /*!< in: symbol table */
91
 
/******************************************************************//**
92
 
Adds an identifier to a symbol table.
93
 
@return symbol table node */
94
 
UNIV_INTERN
95
 
sym_node_t*
96
 
sym_tab_add_id(
97
 
/*===========*/
98
 
        sym_tab_t*      sym_tab,        /*!< in: symbol table */
99
 
        byte*           name,           /*!< in: identifier name */
100
 
        ulint           len);           /*!< in: identifier length */
101
 
 
102
 
/******************************************************************//**
103
 
Add a bound identifier to a symbol table.
104
 
@return symbol table node */
105
 
UNIV_INTERN
106
 
sym_node_t*
107
 
sym_tab_add_bound_id(
108
 
/*===========*/
109
 
        sym_tab_t*      sym_tab,        /*!< in: symbol table */
110
 
        const char*     name);          /*!< in: name of bound id */
111
 
 
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
116
 
 
117
 
/** Types of a symbol table node */
118
 
enum sym_tab_entry {
119
 
        SYM_VAR = 91,           /*!< declared parameter or local
120
 
                                variable of a procedure */
121
 
        SYM_IMPLICIT_VAR,       /*!< storage for a intermediate result
122
 
                                of a calculation */
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 */
130
 
};
131
 
 
132
 
/** Symbol table node */
133
 
struct sym_node_struct{
134
 
        que_common_t                    common;         /*!< node type:
135
 
                                                        QUE_NODE_SYMBOL */
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 */
140
 
 
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.
150
 
 
151
 
        TODO: It would be cleaner to make 'indirection' a boolean field and
152
 
        always use 'alias' to refer to the primary node. */
153
 
 
154
 
        sym_node_t*                     indirection;    /*!< pointer to
155
 
                                                        another symbol table
156
 
                                                        node which contains
157
 
                                                        the value for this
158
 
                                                        node, NULL otherwise */
159
 
        sym_node_t*                     alias;          /*!< pointer to
160
 
                                                        another symbol table
161
 
                                                        node for which this
162
 
                                                        node is an alias,
163
 
                                                        NULL otherwise */
164
 
        UT_LIST_NODE_T(sym_node_t)      col_var_list;   /*!< list of table
165
 
                                                        columns or a list of
166
 
                                                        input variables for an
167
 
                                                        explicit cursor */
168
 
        ibool                           copy_val;       /*!< TRUE if a column
169
 
                                                        and its value should
170
 
                                                        be copied to dynamic
171
 
                                                        memory when fetched */
172
 
        ulint                           field_nos[2];   /*!< if a column, in
173
 
                                                        the position
174
 
                                                        SYM_CLUST_FIELD_NO is
175
 
                                                        the field number in the
176
 
                                                        clustered index; in
177
 
                                                        the position
178
 
                                                        SYM_SEC_FIELD_NO
179
 
                                                        the field number in the
180
 
                                                        non-clustered index to
181
 
                                                        use first; if not found
182
 
                                                        from the index, then
183
 
                                                        ULINT_UNDEFINED */
184
 
        ibool                           resolved;       /*!< TRUE if the
185
 
                                                        meaning of a variable
186
 
                                                        or a column has been
187
 
                                                        resolved; for literals
188
 
                                                        this is always TRUE */
189
 
        enum sym_tab_entry              token_type;     /*!< type of the
190
 
                                                        parsed token */
191
 
        const char*                     name;           /*!< name of an id */
192
 
        ulint                           name_len;       /*!< id name length */
193
 
        dict_table_t*                   table;          /*!< table definition
194
 
                                                        if a table id or a
195
 
                                                        column id */
196
 
        ulint                           col_no;         /*!< column number if a
197
 
                                                        column */
198
 
        sel_buf_t*                      prefetch_buf;   /*!< NULL, or a buffer
199
 
                                                        for cached column
200
 
                                                        values for prefetched
201
 
                                                        rows */
202
 
        sel_node_t*                     cursor_def;     /*!< cursor definition
203
 
                                                        select node if a
204
 
                                                        named cursor */
205
 
        ulint                           param_type;     /*!< PARS_INPUT,
206
 
                                                        PARS_OUTPUT, or
207
 
                                                        PARS_NOT_PARAM if not a
208
 
                                                        procedure parameter */
209
 
        sym_tab_t*                      sym_table;      /*!< back pointer to
210
 
                                                        the symbol table */
211
 
        UT_LIST_NODE_T(sym_node_t)      sym_list;       /*!< list of symbol
212
 
                                                        nodes */
213
 
};
214
 
 
215
 
/** Symbol table */
216
 
struct sym_tab_struct{
217
 
        que_t*                  query_graph;
218
 
                                        /*!< query graph generated by the
219
 
                                        parser */
220
 
        const char*             sql_string;
221
 
                                        /*!< SQL string to parse */
222
 
        size_t                  string_len;
223
 
                                        /*!< SQL string length */
224
 
        int                     next_char_pos;
225
 
                                        /*!< position of the next character in
226
 
                                        sql_string to give to the lexical
227
 
                                        analyzer */
228
 
        pars_info_t*            info;   /*!< extra information, or NULL */
229
 
        sym_node_list_t         sym_list;
230
 
                                        /*!< list of symbol nodes in the symbol
231
 
                                        table */
232
 
        UT_LIST_BASE_NODE_T(func_node_t)
233
 
                                func_node_list;
234
 
                                        /*!< list of function nodes in the
235
 
                                        parsed query graph */
236
 
        mem_heap_t*             heap;   /*!< memory heap from which we can
237
 
                                        allocate space */
238
 
};
239
 
 
240
 
#ifndef UNIV_NONINL
241
 
#include "pars0sym.ic"
242
 
#endif
243
 
 
244
 
#endif