~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/eval0eval.ic

  • Committer: Jay Pipes
  • Date: 2009-02-28 17:49:22 UTC
  • mto: (910.2.6 mordred-noatomics)
  • mto: This revision was merged to the branch mainline in revision 908.
  • Revision ID: jpipes@serialcoder-20090228174922-jczgt4d0662fqmnf
Merging in old r902 temporal changes

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/eval0eval.ic
 
1
/******************************************************
21
2
SQL evaluator: evaluates simple data structures, like expressions, in
22
3
a query graph
23
4
 
 
5
(c) 1997 Innobase Oy
 
6
 
24
7
Created 12/29/1997 Heikki Tuuri
25
8
*******************************************************/
26
9
 
31
14
# include "pars0grm.h"
32
15
#endif
33
16
 
34
 
/*****************************************************************//**
 
17
/*********************************************************************
35
18
Evaluates a function node. */
36
19
UNIV_INTERN
37
20
void
38
21
eval_func(
39
22
/*======*/
40
 
        func_node_t*    func_node);     /*!< in: function node */
41
 
/*****************************************************************//**
 
23
        func_node_t*    func_node);     /* in: function node */
 
24
/*********************************************************************
42
25
Allocate a buffer from global dynamic memory for a value of a que_node.
43
26
NOTE that this memory must be explicitly freed when the query graph is
44
27
freed. If the node already has allocated buffer, that buffer is freed
45
28
here. NOTE that this is the only function where dynamic memory should be
46
 
allocated for a query node val field.
47
 
@return pointer to allocated buffer */
 
29
allocated for a query node val field. */
48
30
UNIV_INTERN
49
31
byte*
50
32
eval_node_alloc_val_buf(
51
33
/*====================*/
52
 
        que_node_t*     node,   /*!< in: query graph node; sets the val field
 
34
                                /* out: pointer to allocated buffer */
 
35
        que_node_t*     node,   /* in: query graph node; sets the val field
53
36
                                data field to point to the new buffer, and
54
37
                                len field equal to size */
55
 
        ulint           size);  /*!< in: buffer size */
56
 
 
57
 
 
58
 
/*****************************************************************//**
59
 
Allocates a new buffer if needed.
60
 
@return pointer to buffer */
 
38
        ulint           size);  /* in: buffer size */
 
39
 
 
40
 
 
41
/*********************************************************************
 
42
Allocates a new buffer if needed. */
61
43
UNIV_INLINE
62
44
byte*
63
45
eval_node_ensure_val_buf(
64
46
/*=====================*/
65
 
        que_node_t*     node,   /*!< in: query graph node; sets the val field
 
47
                                /* out: pointer to buffer */
 
48
        que_node_t*     node,   /* in: query graph node; sets the val field
66
49
                                data field to point to the new buffer, and
67
50
                                len field equal to size */
68
 
        ulint           size)   /*!< in: buffer size */
 
51
        ulint           size)   /* in: buffer size */
69
52
{
70
53
        dfield_t*       dfield;
71
54
        byte*           data;
83
66
        return(data);
84
67
}
85
68
 
86
 
/*****************************************************************//**
 
69
/*********************************************************************
87
70
Evaluates a symbol table symbol. */
88
71
UNIV_INLINE
89
72
void
90
73
eval_sym(
91
74
/*=====*/
92
 
        sym_node_t*     sym_node)       /*!< in: symbol table node */
 
75
        sym_node_t*     sym_node)       /* in: symbol table node */
93
76
{
94
77
 
95
78
        ut_ad(que_node_get_type(sym_node) == QUE_NODE_SYMBOL);
103
86
        }
104
87
}
105
88
 
106
 
/*****************************************************************//**
 
89
/*********************************************************************
107
90
Evaluates an expression. */
108
91
UNIV_INLINE
109
92
void
110
93
eval_exp(
111
94
/*=====*/
112
 
        que_node_t*     exp_node)       /*!< in: expression */
 
95
        que_node_t*     exp_node)       /* in: expression */
113
96
{
114
97
        if (que_node_get_type(exp_node) == QUE_NODE_SYMBOL) {
115
98
 
121
104
        eval_func(exp_node);
122
105
}
123
106
 
124
 
/*****************************************************************//**
 
107
/*********************************************************************
125
108
Sets an integer value as the value of an expression node. */
126
109
UNIV_INLINE
127
110
void
128
111
eval_node_set_int_val(
129
112
/*==================*/
130
 
        que_node_t*     node,   /*!< in: expression node */
131
 
        lint            val)    /*!< in: value to set */
 
113
        que_node_t*     node,   /* in: expression node */
 
114
        lint            val)    /* in: value to set */
132
115
{
133
116
        dfield_t*       dfield;
134
117
        byte*           data;
146
129
        mach_write_to_4(data, (ulint)val);
147
130
}
148
131
 
149
 
/*****************************************************************//**
150
 
Gets an integer non-SQL null value from an expression node.
151
 
@return integer value */
 
132
/*********************************************************************
 
133
Gets an integer non-SQL null value from an expression node. */
152
134
UNIV_INLINE
153
135
lint
154
136
eval_node_get_int_val(
155
137
/*==================*/
156
 
        que_node_t*     node)   /*!< in: expression node */
 
138
                                /* out: integer value */
 
139
        que_node_t*     node)   /* in: expression node */
157
140
{
158
141
        dfield_t*       dfield;
159
142
 
164
147
        return((int)mach_read_from_4(dfield_get_data(dfield)));
165
148
}
166
149
 
167
 
/*****************************************************************//**
168
 
Gets a iboolean value from a query node.
169
 
@return iboolean value */
 
150
/*********************************************************************
 
151
Gets a iboolean value from a query node. */
170
152
UNIV_INLINE
171
153
ibool
172
154
eval_node_get_ibool_val(
173
155
/*====================*/
174
 
        que_node_t*     node)   /*!< in: query graph node */
 
156
                                /* out: iboolean value */
 
157
        que_node_t*     node)   /* in: query graph node */
175
158
{
176
159
        dfield_t*       dfield;
177
160
        byte*           data;
185
168
        return(mach_read_from_1(data));
186
169
}
187
170
 
188
 
/*****************************************************************//**
 
171
/*********************************************************************
189
172
Sets a iboolean value as the value of a function node. */
190
173
UNIV_INLINE
191
174
void
192
175
eval_node_set_ibool_val(
193
176
/*====================*/
194
 
        func_node_t*    func_node,      /*!< in: function node */
195
 
        ibool           val)            /*!< in: value to set */
 
177
        func_node_t*    func_node,      /* in: function node */
 
178
        ibool           val)            /* in: value to set */
196
179
{
197
180
        dfield_t*       dfield;
198
181
        byte*           data;
212
195
        mach_write_to_1(data, val);
213
196
}
214
197
 
215
 
/*****************************************************************//**
 
198
/*********************************************************************
216
199
Copies a binary string value as the value of a query graph node. Allocates a
217
200
new buffer if necessary. */
218
201
UNIV_INLINE
219
202
void
220
203
eval_node_copy_and_alloc_val(
221
204
/*=========================*/
222
 
        que_node_t*     node,   /*!< in: query graph node */
223
 
        const byte*     str,    /*!< in: binary string */
224
 
        ulint           len)    /*!< in: string length or UNIV_SQL_NULL */
 
205
        que_node_t*     node,   /* in: query graph node */
 
206
        const byte*     str,    /* in: binary string */
 
207
        ulint           len)    /* in: string length or UNIV_SQL_NULL */
225
208
{
226
209
        byte*           data;
227
210
 
236
219
        ut_memcpy(data, str, len);
237
220
}
238
221
 
239
 
/*****************************************************************//**
 
222
/*********************************************************************
240
223
Copies a query node value to another node. */
241
224
UNIV_INLINE
242
225
void
243
226
eval_node_copy_val(
244
227
/*===============*/
245
 
        que_node_t*     node1,  /*!< in: node to copy to */
246
 
        que_node_t*     node2)  /*!< in: node to copy from */
 
228
        que_node_t*     node1,  /* in: node to copy to */
 
229
        que_node_t*     node2)  /* in: node to copy from */
247
230
{
248
231
        dfield_t*       dfield2;
249
232