1
/******************************************************
2
SQL evaluator: evaluates simple data structures, like expressions, in
7
Created 12/29/1997 Heikki Tuuri
8
*******************************************************/
14
/*********************************************************************
15
Evaluates a function node. */
20
func_node_t* func_node); /* in: function node */
21
/*********************************************************************
22
Allocate a buffer from global dynamic memory for a value of a que_node.
23
NOTE that this memory must be explicitly freed when the query graph is
24
freed. If the node already has allocated buffer, that buffer is freed
25
here. NOTE that this is the only function where dynamic memory should be
26
allocated for a query node val field. */
29
eval_node_alloc_val_buf(
30
/*====================*/
31
/* out: pointer to allocated buffer */
32
que_node_t* node, /* in: query graph node; sets the val field
33
data field to point to the new buffer, and
34
len field equal to size */
35
ulint size); /* in: buffer size */
38
/*********************************************************************
39
Allocates a new buffer if needed. */
42
eval_node_ensure_val_buf(
43
/*=====================*/
44
/* out: pointer to buffer */
45
que_node_t* node, /* in: query graph node; sets the val field
46
data field to point to the new buffer, and
47
len field equal to size */
48
ulint size) /* in: buffer size */
53
dfield = que_node_get_val(node);
54
dfield_set_len(dfield, size);
56
data = dfield_get_data(dfield);
58
if (!data || que_node_get_val_buf_size(node) < size) {
60
data = eval_node_alloc_val_buf(node, size);
66
/*********************************************************************
67
Evaluates a symbol table symbol. */
72
sym_node_t* sym_node) /* in: symbol table node */
75
ut_ad(que_node_get_type(sym_node) == QUE_NODE_SYMBOL);
77
if (sym_node->indirection) {
78
/* The symbol table node is an alias for a variable or a
81
dfield_copy_data(que_node_get_val(sym_node),
82
que_node_get_val(sym_node->indirection));
86
/*********************************************************************
87
Evaluates an expression. */
92
que_node_t* exp_node) /* in: expression */
94
if (que_node_get_type(exp_node) == QUE_NODE_SYMBOL) {
96
eval_sym((sym_node_t*)exp_node);
104
/*********************************************************************
105
Sets an integer value as the value of an expression node. */
108
eval_node_set_int_val(
109
/*==================*/
110
que_node_t* node, /* in: expression node */
111
lint val) /* in: value to set */
116
dfield = que_node_get_val(node);
118
data = dfield_get_data(dfield);
121
data = eval_node_alloc_val_buf(node, 4);
124
ut_ad(dfield_get_len(dfield) == 4);
126
mach_write_to_4(data, (ulint)val);
129
/*********************************************************************
130
Gets an integer non-SQL null value from an expression node. */
133
eval_node_get_int_val(
134
/*==================*/
135
/* out: integer value */
136
que_node_t* node) /* in: expression node */
140
dfield = que_node_get_val(node);
142
ut_ad(dfield_get_len(dfield) == 4);
144
return((int)mach_read_from_4(dfield_get_data(dfield)));
147
/*********************************************************************
148
Gets a iboolean value from a query node. */
151
eval_node_get_ibool_val(
152
/*====================*/
153
/* out: iboolean value */
154
que_node_t* node) /* in: query graph node */
159
dfield = que_node_get_val(node);
161
data = dfield_get_data(dfield);
165
return(mach_read_from_1(data));
168
/*********************************************************************
169
Sets a iboolean value as the value of a function node. */
172
eval_node_set_ibool_val(
173
/*====================*/
174
func_node_t* func_node, /* in: function node */
175
ibool val) /* in: value to set */
180
dfield = que_node_get_val(func_node);
182
data = dfield_get_data(dfield);
185
/* Allocate 1 byte to hold the value */
187
data = eval_node_alloc_val_buf(func_node, 1);
190
ut_ad(dfield_get_len(dfield) == 1);
192
mach_write_to_1(data, val);
195
/*********************************************************************
196
Copies a binary string value as the value of a query graph node. Allocates a
197
new buffer if necessary. */
200
eval_node_copy_and_alloc_val(
201
/*=========================*/
202
que_node_t* node, /* in: query graph node */
203
byte* str, /* in: binary string */
204
ulint len) /* in: string length or UNIV_SQL_NULL */
208
if (len == UNIV_SQL_NULL) {
209
dfield_set_len(que_node_get_val(node), len);
214
data = eval_node_ensure_val_buf(node, len);
216
ut_memcpy(data, str, len);
219
/*********************************************************************
220
Copies a query node value to another node. */
225
que_node_t* node1, /* in: node to copy to */
226
que_node_t* node2) /* in: node to copy from */
230
dfield2 = que_node_get_val(node2);
232
eval_node_copy_and_alloc_val(node1, dfield_get_data(dfield2),
233
dfield_get_len(dfield2));