~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
SQL parser symbol table
 
3
 
 
4
(c) 1997 Innobase Oy
 
5
 
 
6
Created 12/15/1997 Heikki Tuuri
 
7
*******************************************************/
 
8
 
 
9
#ifndef pars0sym_h
 
10
#define pars0sym_h
 
11
 
 
12
#include "univ.i"
 
13
#include "que0types.h"
 
14
#include "usr0types.h"
 
15
#include "dict0types.h"
 
16
#include "pars0types.h"
 
17
#include "row0types.h"
 
18
 
 
19
/**********************************************************************
 
20
Creates a symbol table for a single stored procedure or query. */
 
21
 
 
22
sym_tab_t*
 
23
sym_tab_create(
 
24
/*===========*/
 
25
                                /* out, own: symbol table */
 
26
        mem_heap_t*     heap);  /* in: memory heap where to create */
 
27
/**********************************************************************
 
28
Frees the memory allocated dynamically AFTER parsing phase for variables
 
29
etc. in the symbol table. Does not free the mem heap where the table was
 
30
originally created. Frees also SQL explicit cursor definitions. */
 
31
 
 
32
void
 
33
sym_tab_free_private(
 
34
/*=================*/
 
35
        sym_tab_t*      sym_tab);       /* in, own: symbol table */
 
36
/**********************************************************************
 
37
Adds an integer literal to a symbol table. */
 
38
 
 
39
sym_node_t*
 
40
sym_tab_add_int_lit(
 
41
/*================*/
 
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. */
 
47
 
 
48
sym_node_t*
 
49
sym_tab_add_str_lit(
 
50
/*================*/
 
51
                                        /* out: symbol table node */
 
52
        sym_tab_t*      sym_tab,        /* in: symbol table */
 
53
        byte*           str,            /* in: string with no quotes around
 
54
                                        it */
 
55
        ulint           len);           /* in: string length */
 
56
/**********************************************************************
 
57
Add a bound literal to a symbol table. */
 
58
 
 
59
sym_node_t*
 
60
sym_tab_add_bound_lit(
 
61
/*==================*/
 
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. */
 
68
 
 
69
sym_node_t*
 
70
sym_tab_add_null_lit(
 
71
/*=================*/
 
72
                                        /* out: symbol table node */
 
73
        sym_tab_t*      sym_tab);       /* in: symbol table */
 
74
/**********************************************************************
 
75
Adds an identifier to a symbol table. */
 
76
 
 
77
sym_node_t*
 
78
sym_tab_add_id(
 
79
/*===========*/
 
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 */
 
84
 
 
85
/**********************************************************************
 
86
Add a bound identifier to a symbol table. */
 
87
 
 
88
sym_node_t*
 
89
sym_tab_add_bound_id(
 
90
/*===========*/
 
91
                                        /* out: symbol table node */
 
92
        sym_tab_t*      sym_tab,        /* in: symbol table */
 
93
        const char*     name);          /* in: name of bound id */
 
94
 
 
95
#define SYM_CLUST_FIELD_NO      0
 
96
#define SYM_SEC_FIELD_NO        1
 
97
 
 
98
struct sym_node_struct{
 
99
        que_common_t                    common;         /* node type:
 
100
                                                        QUE_NODE_SYMBOL */
 
101
        /* NOTE: if the data field in 'common.val' is not NULL and the symbol
 
102
        table node is not for a temporary column, the memory for the value has
 
103
        been allocated from dynamic memory and it should be freed when the
 
104
        symbol table is discarded */
 
105
 
 
106
        /* 'alias' and 'indirection' are almost the same, but not quite.
 
107
        'alias' always points to the primary instance of the variable, while
 
108
        'indirection' does the same only if we should use the primary
 
109
        instance's values for the node's data. This is usually the case, but
 
110
        when initializing a cursor (e.g., "DECLARE CURSOR c IS SELECT * FROM
 
111
        t WHERE id = x;"), we copy the values from the primary instance to
 
112
        the cursor's instance so that they are fixed for the duration of the
 
113
        cursor, and set 'indirection' to NULL. If we did not, the value of
 
114
        'x' could change between fetches and things would break horribly.
 
115
 
 
116
        TODO: It would be cleaner to make 'indirection' a boolean field and
 
117
        always use 'alias' to refer to the primary node. */
 
118
 
 
119
        sym_node_t*                     indirection;    /* pointer to
 
120
                                                        another symbol table
 
121
                                                        node which contains
 
122
                                                        the value for this
 
123
                                                        node, NULL otherwise */
 
124
        sym_node_t*                     alias;          /* pointer to
 
125
                                                        another symbol table
 
126
                                                        node for which this
 
127
                                                        node is an alias,
 
128
                                                        NULL otherwise */
 
129
        UT_LIST_NODE_T(sym_node_t)      col_var_list;   /* list of table
 
130
                                                        columns or a list of
 
131
                                                        input variables for an
 
132
                                                        explicit cursor */
 
133
        ibool                           copy_val;       /* TRUE if a column
 
134
                                                        and its value should
 
135
                                                        be copied to dynamic
 
136
                                                        memory when fetched */
 
137
        ulint                           field_nos[2];   /* if a column, in
 
138
                                                        the position
 
139
                                                        SYM_CLUST_FIELD_NO is
 
140
                                                        the field number in the
 
141
                                                        clustered index; in
 
142
                                                        the position
 
143
                                                        SYM_SEC_FIELD_NO
 
144
                                                        the field number in the
 
145
                                                        non-clustered index to
 
146
                                                        use first; if not found
 
147
                                                        from the index, then
 
148
                                                        ULINT_UNDEFINED */
 
149
        ibool                           resolved;       /* TRUE if the
 
150
                                                        meaning of a variable
 
151
                                                        or a column has been
 
152
                                                        resolved; for literals
 
153
                                                        this is always TRUE */
 
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
 
161
                                                        if a table id or a
 
162
                                                        column id */
 
163
        ulint                           col_no;         /* column number if a
 
164
                                                        column */
 
165
        sel_buf_t*                      prefetch_buf;   /* NULL, or a buffer
 
166
                                                        for cached column
 
167
                                                        values for prefetched
 
168
                                                        rows */
 
169
        sel_node_t*                     cursor_def;     /* cursor definition
 
170
                                                        select node if a
 
171
                                                        named cursor */
 
172
        ulint                           param_type;     /* PARS_INPUT,
 
173
                                                        PARS_OUTPUT, or
 
174
                                                        PARS_NOT_PARAM if not a
 
175
                                                        procedure parameter */
 
176
        sym_tab_t*                      sym_table;      /* back pointer to
 
177
                                                        the symbol table */
 
178
        UT_LIST_NODE_T(sym_node_t)      sym_list;       /* list of symbol
 
179
                                                        nodes */
 
180
};
 
181
 
 
182
struct sym_tab_struct{
 
183
        que_t*                  query_graph;
 
184
                                        /* query graph generated by the
 
185
                                        parser */
 
186
        const char*             sql_string;
 
187
                                        /* SQL string to parse */
 
188
        size_t                  string_len;
 
189
                                        /* SQL string length */
 
190
        int                     next_char_pos;
 
191
                                        /* position of the next character in
 
192
                                        sql_string to give to the lexical
 
193
                                        analyzer */
 
194
        pars_info_t*            info;   /* extra information, or NULL */
 
195
        sym_node_list_t         sym_list;
 
196
                                        /* list of symbol nodes in the symbol
 
197
                                        table */
 
198
        UT_LIST_BASE_NODE_T(func_node_t)
 
199
                                func_node_list;
 
200
                                        /* list of function nodes in the
 
201
                                        parsed query graph */
 
202
        mem_heap_t*             heap;   /* memory heap from which we can
 
203
                                        allocate space */
 
204
};
 
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
 
 
219
#ifndef UNIV_NONINL
 
220
#include "pars0sym.ic"
 
221
#endif
 
222
 
 
223
#endif