~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 
 
3
Copyright (c) 1997, 2009, Oracle and/or its affiliates. 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.,
 
15
51 Franklin Street, Suite 500, Boston, MA 02110-1335 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
        const 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
Rebind literal to a node in the symbol table. */
 
85
 
 
86
sym_node_t*
 
87
sym_tab_rebind_lit(
 
88
/*===============*/
 
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 */
 
96
UNIV_INTERN
 
97
sym_node_t*
 
98
sym_tab_add_null_lit(
 
99
/*=================*/
 
100
        sym_tab_t*      sym_tab);       /*!< in: symbol table */
 
101
/******************************************************************//**
 
102
Adds an identifier to a symbol table.
 
103
@return symbol table node */
 
104
UNIV_INTERN
 
105
sym_node_t*
 
106
sym_tab_add_id(
 
107
/*===========*/
 
108
        sym_tab_t*      sym_tab,        /*!< in: symbol table */
 
109
        byte*           name,           /*!< in: identifier name */
 
110
        ulint           len);           /*!< in: identifier length */
 
111
 
 
112
/******************************************************************//**
 
113
Add a bound identifier to a symbol table.
 
114
@return symbol table node */
 
115
UNIV_INTERN
 
116
sym_node_t*
 
117
sym_tab_add_bound_id(
 
118
/*===========*/
 
119
        sym_tab_t*      sym_tab,        /*!< in: symbol table */
 
120
        const char*     name);          /*!< in: name of bound id */
 
121
 
 
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
 
126
 
 
127
/** Types of a symbol table node */
 
128
enum sym_tab_entry {
 
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
 
133
                                of a calculation */
 
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 */
 
143
};
 
144
 
 
145
/** Symbol table node */
 
146
struct sym_node_t{
 
147
        que_common_t                    common;         /*!< node type:
 
148
                                                        QUE_NODE_SYMBOL */
 
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 */
 
153
 
 
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.
 
163
 
 
164
        TODO: It would be cleaner to make 'indirection' a boolean field and
 
165
        always use 'alias' to refer to the primary node. */
 
166
 
 
167
        sym_node_t*                     indirection;    /*!< pointer to
 
168
                                                        another symbol table
 
169
                                                        node which contains
 
170
                                                        the value for this
 
171
                                                        node, NULL otherwise */
 
172
        sym_node_t*                     alias;          /*!< pointer to
 
173
                                                        another symbol table
 
174
                                                        node for which this
 
175
                                                        node is an alias,
 
176
                                                        NULL otherwise */
 
177
        UT_LIST_NODE_T(sym_node_t)      col_var_list;   /*!< list of table
 
178
                                                        columns or a list of
 
179
                                                        input variables for an
 
180
                                                        explicit cursor */
 
181
        ibool                           copy_val;       /*!< TRUE if a column
 
182
                                                        and its value should
 
183
                                                        be copied to dynamic
 
184
                                                        memory when fetched */
 
185
        ulint                           field_nos[2];   /*!< if a column, in
 
186
                                                        the position
 
187
                                                        SYM_CLUST_FIELD_NO is
 
188
                                                        the field number in the
 
189
                                                        clustered index; in
 
190
                                                        the position
 
191
                                                        SYM_SEC_FIELD_NO
 
192
                                                        the field number in the
 
193
                                                        non-clustered index to
 
194
                                                        use first; if not found
 
195
                                                        from the index, then
 
196
                                                        ULINT_UNDEFINED */
 
197
        ibool                           resolved;       /*!< TRUE if the
 
198
                                                        meaning of a variable
 
199
                                                        or a column has been
 
200
                                                        resolved; for literals
 
201
                                                        this is always TRUE */
 
202
        enum sym_tab_entry              token_type;     /*!< type of the
 
203
                                                        parsed token */
 
204
        const char*                     name;           /*!< name of an id */
 
205
        ulint                           name_len;       /*!< id name length */
 
206
        dict_table_t*                   table;          /*!< table definition
 
207
                                                        if a table id or a
 
208
                                                        column id */
 
209
        ulint                           col_no;         /*!< column number if a
 
210
                                                        column */
 
211
        sel_buf_t*                      prefetch_buf;   /*!< NULL, or a buffer
 
212
                                                        for cached column
 
213
                                                        values for prefetched
 
214
                                                        rows */
 
215
        sel_node_t*                     cursor_def;     /*!< cursor definition
 
216
                                                        select node if a
 
217
                                                        named cursor */
 
218
        ulint                           param_type;     /*!< PARS_INPUT,
 
219
                                                        PARS_OUTPUT, or
 
220
                                                        PARS_NOT_PARAM if not a
 
221
                                                        procedure parameter */
 
222
        sym_tab_t*                      sym_table;      /*!< back pointer to
 
223
                                                        the symbol table */
 
224
        UT_LIST_NODE_T(sym_node_t)      sym_list;       /*!< list of symbol
 
225
                                                        nodes */
 
226
        sym_node_t*                     like_node;      /* LIKE operator node*/
 
227
};
 
228
 
 
229
/** Symbol table */
 
230
struct sym_tab_t{
 
231
        que_t*                  query_graph;
 
232
                                        /*!< query graph generated by the
 
233
                                        parser */
 
234
        const char*             sql_string;
 
235
                                        /*!< SQL string to parse */
 
236
        size_t                  string_len;
 
237
                                        /*!< SQL string length */
 
238
        int                     next_char_pos;
 
239
                                        /*!< position of the next character in
 
240
                                        sql_string to give to the lexical
 
241
                                        analyzer */
 
242
        pars_info_t*            info;   /*!< extra information, or NULL */
 
243
        sym_node_list_t         sym_list;
 
244
                                        /*!< list of symbol nodes in the symbol
 
245
                                        table */
 
246
        UT_LIST_BASE_NODE_T(func_node_t)
 
247
                                func_node_list;
 
248
                                        /*!< list of function nodes in the
 
249
                                        parsed query graph */
 
250
        mem_heap_t*             heap;   /*!< memory heap from which we can
 
251
                                        allocate space */
 
252
};
 
253
 
 
254
#ifndef UNIV_NONINL
 
255
#include "pars0sym.ic"
 
256
#endif
 
257
 
 
258
#endif