~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-01-09 22:07:54 UTC
  • Revision ID: brian@tangent.org-20090109220754-1y50h7lqi9i1ifcs
Dead test/wrong test.

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
 
1
/******************************************************
21
2
SQL parser symbol table
22
3
 
 
4
(c) 1997 Innobase Oy
 
5
 
23
6
Created 12/15/1997 Heikki Tuuri
24
7
*******************************************************/
25
8
 
33
16
#include "pars0types.h"
34
17
#include "row0types.h"
35
18
 
36
 
/******************************************************************//**
37
 
Creates a symbol table for a single stored procedure or query.
38
 
@return own: symbol table */
 
19
/**********************************************************************
 
20
Creates a symbol table for a single stored procedure or query. */
39
21
UNIV_INTERN
40
22
sym_tab_t*
41
23
sym_tab_create(
42
24
/*===========*/
43
 
        mem_heap_t*     heap);  /*!< in: memory heap where to create */
44
 
/******************************************************************//**
 
25
                                /* out, own: symbol table */
 
26
        mem_heap_t*     heap);  /* in: memory heap where to create */
 
27
/**********************************************************************
45
28
Frees the memory allocated dynamically AFTER parsing phase for variables
46
29
etc. in the symbol table. Does not free the mem heap where the table was
47
30
originally created. Frees also SQL explicit cursor definitions. */
49
32
void
50
33
sym_tab_free_private(
51
34
/*=================*/
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 */
 
35
        sym_tab_t*      sym_tab);       /* in, own: symbol table */
 
36
/**********************************************************************
 
37
Adds an integer literal to a symbol table. */
56
38
UNIV_INTERN
57
39
sym_node_t*
58
40
sym_tab_add_int_lit(
59
41
/*================*/
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 */
 
42
                                        /* out: symbol table node */
 
43
        sym_tab_t*      sym_tab,        /* in: symbol table */
 
44
        ulint           val);           /* in: integer value */
 
45
/**********************************************************************
 
46
Adds an string literal to a symbol table. */
65
47
UNIV_INTERN
66
48
sym_node_t*
67
49
sym_tab_add_str_lit(
68
50
/*================*/
69
 
        sym_tab_t*      sym_tab,        /*!< in: symbol table */
70
 
        byte*           str,            /*!< in: string with no quotes around
 
51
                                        /* out: symbol table node */
 
52
        sym_tab_t*      sym_tab,        /* in: symbol table */
 
53
        byte*           str,            /* in: string with no quotes around
71
54
                                        it */
72
 
        ulint           len);           /*!< in: string length */
73
 
/******************************************************************//**
74
 
Add a bound literal to a symbol table.
75
 
@return symbol table node */
 
55
        ulint           len);           /* in: string length */
 
56
/**********************************************************************
 
57
Add a bound literal to a symbol table. */
76
58
UNIV_INTERN
77
59
sym_node_t*
78
60
sym_tab_add_bound_lit(
79
61
/*==================*/
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 */
 
62
                                        /* out: symbol table node */
 
63
        sym_tab_t*      sym_tab,        /* in: symbol table */
 
64
        const char*     name,           /* in: name of bound literal */
 
65
        ulint*          lit_type);      /* out: type of literal (PARS_*_LIT) */
 
66
/**********************************************************************
 
67
Adds an SQL null literal to a symbol table. */
86
68
UNIV_INTERN
87
69
sym_node_t*
88
70
sym_tab_add_null_lit(
89
71
/*=================*/
90
 
        sym_tab_t*      sym_tab);       /*!< in: symbol table */
91
 
/******************************************************************//**
92
 
Adds an identifier to a symbol table.
93
 
@return symbol table node */
 
72
                                        /* out: symbol table node */
 
73
        sym_tab_t*      sym_tab);       /* in: symbol table */
 
74
/**********************************************************************
 
75
Adds an identifier to a symbol table. */
94
76
UNIV_INTERN
95
77
sym_node_t*
96
78
sym_tab_add_id(
97
79
/*===========*/
98
 
        sym_tab_t*      sym_tab,        /*!< in: symbol table */
99
 
        byte*           name,           /*!< in: identifier name */
100
 
        ulint           len);           /*!< in: identifier length */
 
80
                                        /* out: symbol table node */
 
81
        sym_tab_t*      sym_tab,        /* in: symbol table */
 
82
        byte*           name,           /* in: identifier name */
 
83
        ulint           len);           /* in: identifier length */
101
84
 
102
 
/******************************************************************//**
103
 
Add a bound identifier to a symbol table.
104
 
@return symbol table node */
 
85
/**********************************************************************
 
86
Add a bound identifier to a symbol table. */
105
87
UNIV_INTERN
106
88
sym_node_t*
107
89
sym_tab_add_bound_id(
108
90
/*===========*/
109
 
        sym_tab_t*      sym_tab,        /*!< in: symbol table */
110
 
        const char*     name);          /*!< in: name of bound id */
 
91
                                        /* out: symbol table node */
 
92
        sym_tab_t*      sym_tab,        /* in: symbol table */
 
93
        const char*     name);          /* in: name of bound id */
111
94
 
112
 
/** Index of sym_node_struct::field_nos corresponding to the clustered index */
113
95
#define SYM_CLUST_FIELD_NO      0
114
 
/** Index of sym_node_struct::field_nos corresponding to a secondary index */
115
96
#define SYM_SEC_FIELD_NO        1
116
97
 
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
98
struct sym_node_struct{
134
 
        que_common_t                    common;         /*!< node type:
 
99
        que_common_t                    common;         /* node type:
135
100
                                                        QUE_NODE_SYMBOL */
136
101
        /* NOTE: if the data field in 'common.val' is not NULL and the symbol
137
102
        table node is not for a temporary column, the memory for the value has
151
116
        TODO: It would be cleaner to make 'indirection' a boolean field and
152
117
        always use 'alias' to refer to the primary node. */
153
118
 
154
 
        sym_node_t*                     indirection;    /*!< pointer to
 
119
        sym_node_t*                     indirection;    /* pointer to
155
120
                                                        another symbol table
156
121
                                                        node which contains
157
122
                                                        the value for this
158
123
                                                        node, NULL otherwise */
159
 
        sym_node_t*                     alias;          /*!< pointer to
 
124
        sym_node_t*                     alias;          /* pointer to
160
125
                                                        another symbol table
161
126
                                                        node for which this
162
127
                                                        node is an alias,
163
128
                                                        NULL otherwise */
164
 
        UT_LIST_NODE_T(sym_node_t)      col_var_list;   /*!< list of table
 
129
        UT_LIST_NODE_T(sym_node_t)      col_var_list;   /* list of table
165
130
                                                        columns or a list of
166
131
                                                        input variables for an
167
132
                                                        explicit cursor */
168
 
        ibool                           copy_val;       /*!< TRUE if a column
 
133
        ibool                           copy_val;       /* TRUE if a column
169
134
                                                        and its value should
170
135
                                                        be copied to dynamic
171
136
                                                        memory when fetched */
172
 
        ulint                           field_nos[2];   /*!< if a column, in
 
137
        ulint                           field_nos[2];   /* if a column, in
173
138
                                                        the position
174
139
                                                        SYM_CLUST_FIELD_NO is
175
140
                                                        the field number in the
181
146
                                                        use first; if not found
182
147
                                                        from the index, then
183
148
                                                        ULINT_UNDEFINED */
184
 
        ibool                           resolved;       /*!< TRUE if the
 
149
        ibool                           resolved;       /* TRUE if the
185
150
                                                        meaning of a variable
186
151
                                                        or a column has been
187
152
                                                        resolved; for literals
188
153
                                                        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
 
154
        ulint                           token_type;     /* SYM_VAR, SYM_COLUMN,
 
155
                                                        SYM_IMPLICIT_VAR,
 
156
                                                        SYM_LIT, SYM_TABLE,
 
157
                                                        SYM_CURSOR, ... */
 
158
        const char*                     name;           /* name of an id */
 
159
        ulint                           name_len;       /* id name length */
 
160
        dict_table_t*                   table;          /* table definition
194
161
                                                        if a table id or a
195
162
                                                        column id */
196
 
        ulint                           col_no;         /*!< column number if a
 
163
        ulint                           col_no;         /* column number if a
197
164
                                                        column */
198
 
        sel_buf_t*                      prefetch_buf;   /*!< NULL, or a buffer
 
165
        sel_buf_t*                      prefetch_buf;   /* NULL, or a buffer
199
166
                                                        for cached column
200
167
                                                        values for prefetched
201
168
                                                        rows */
202
 
        sel_node_t*                     cursor_def;     /*!< cursor definition
 
169
        sel_node_t*                     cursor_def;     /* cursor definition
203
170
                                                        select node if a
204
171
                                                        named cursor */
205
 
        ulint                           param_type;     /*!< PARS_INPUT,
 
172
        ulint                           param_type;     /* PARS_INPUT,
206
173
                                                        PARS_OUTPUT, or
207
174
                                                        PARS_NOT_PARAM if not a
208
175
                                                        procedure parameter */
209
 
        sym_tab_t*                      sym_table;      /*!< back pointer to
 
176
        sym_tab_t*                      sym_table;      /* back pointer to
210
177
                                                        the symbol table */
211
 
        UT_LIST_NODE_T(sym_node_t)      sym_list;       /*!< list of symbol
 
178
        UT_LIST_NODE_T(sym_node_t)      sym_list;       /* list of symbol
212
179
                                                        nodes */
213
180
};
214
181
 
215
 
/** Symbol table */
216
182
struct sym_tab_struct{
217
183
        que_t*                  query_graph;
218
 
                                        /*!< query graph generated by the
 
184
                                        /* query graph generated by the
219
185
                                        parser */
220
186
        const char*             sql_string;
221
 
                                        /*!< SQL string to parse */
 
187
                                        /* SQL string to parse */
222
188
        size_t                  string_len;
223
 
                                        /*!< SQL string length */
 
189
                                        /* SQL string length */
224
190
        int                     next_char_pos;
225
 
                                        /*!< position of the next character in
 
191
                                        /* position of the next character in
226
192
                                        sql_string to give to the lexical
227
193
                                        analyzer */
228
 
        pars_info_t*            info;   /*!< extra information, or NULL */
 
194
        pars_info_t*            info;   /* extra information, or NULL */
229
195
        sym_node_list_t         sym_list;
230
 
                                        /*!< list of symbol nodes in the symbol
 
196
                                        /* list of symbol nodes in the symbol
231
197
                                        table */
232
198
        UT_LIST_BASE_NODE_T(func_node_t)
233
199
                                func_node_list;
234
 
                                        /*!< list of function nodes in the
 
200
                                        /* list of function nodes in the
235
201
                                        parsed query graph */
236
 
        mem_heap_t*             heap;   /*!< memory heap from which we can
 
202
        mem_heap_t*             heap;   /* memory heap from which we can
237
203
                                        allocate space */
238
204
};
239
205
 
 
206
/* Types of a symbol table entry */
 
207
#define SYM_VAR                 91      /* declared parameter or local
 
208
                                        variable of a procedure */
 
209
#define SYM_IMPLICIT_VAR        92      /* storage for a intermediate result
 
210
                                        of a calculation */
 
211
#define SYM_LIT                 93      /* literal */
 
212
#define SYM_TABLE               94      /* database table name */
 
213
#define SYM_COLUMN              95      /* database table name */
 
214
#define SYM_CURSOR              96      /* named cursor */
 
215
#define SYM_PROCEDURE_NAME      97      /* stored procedure name */
 
216
#define SYM_INDEX               98      /* database index name */
 
217
#define SYM_FUNCTION            99      /* user function name */
 
218
 
240
219
#ifndef UNIV_NONINL
241
220
#include "pars0sym.ic"
242
221
#endif