1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2006 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
||
17 |
#ifdef USE_PRAGMA_INTERFACE
|
|
18 |
#pragma interface /* gcc class implementation */ |
|
19 |
#endif
|
|
20 |
||
21 |
class Protocol; |
|
22 |
struct TABLE_LIST; |
|
23 |
void item_init(void); /* Init item functions */ |
|
24 |
class Item_field; |
|
25 |
||
26 |
/*
|
|
27 |
"Declared Type Collation"
|
|
28 |
A combination of collation and its derivation.
|
|
29 |
||
30 |
Flags for collation aggregation modes:
|
|
31 |
MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
|
|
32 |
MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
|
|
33 |
(i.e. constant).
|
|
34 |
MY_COLL_ALLOW_CONV - allow any kind of conversion
|
|
35 |
(combination of the above two)
|
|
36 |
MY_COLL_DISALLOW_NONE - don't allow return DERIVATION_NONE
|
|
37 |
(e.g. when aggregating for comparison)
|
|
38 |
MY_COLL_CMP_CONV - combination of MY_COLL_ALLOW_CONV
|
|
39 |
and MY_COLL_DISALLOW_NONE
|
|
40 |
*/
|
|
41 |
||
42 |
#define MY_COLL_ALLOW_SUPERSET_CONV 1
|
|
43 |
#define MY_COLL_ALLOW_COERCIBLE_CONV 2
|
|
44 |
#define MY_COLL_ALLOW_CONV 3
|
|
45 |
#define MY_COLL_DISALLOW_NONE 4
|
|
46 |
#define MY_COLL_CMP_CONV 7
|
|
47 |
||
48 |
class DTCollation { |
|
49 |
public: |
|
50 |
CHARSET_INFO *collation; |
|
51 |
enum Derivation derivation; |
|
52 |
uint repertoire; |
|
53 |
||
54 |
void set_repertoire_from_charset(CHARSET_INFO *cs) |
|
55 |
{
|
|
56 |
repertoire= cs->state & MY_CS_PUREASCII ? |
|
57 |
MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30; |
|
58 |
}
|
|
59 |
DTCollation() |
|
60 |
{
|
|
61 |
collation= &my_charset_bin; |
|
62 |
derivation= DERIVATION_NONE; |
|
63 |
repertoire= MY_REPERTOIRE_UNICODE30; |
|
64 |
}
|
|
65 |
DTCollation(CHARSET_INFO *collation_arg, Derivation derivation_arg) |
|
66 |
{
|
|
67 |
collation= collation_arg; |
|
68 |
derivation= derivation_arg; |
|
69 |
set_repertoire_from_charset(collation_arg); |
|
70 |
}
|
|
71 |
void set(DTCollation &dt) |
|
72 |
{
|
|
73 |
collation= dt.collation; |
|
74 |
derivation= dt.derivation; |
|
75 |
repertoire= dt.repertoire; |
|
76 |
}
|
|
77 |
void set(CHARSET_INFO *collation_arg, Derivation derivation_arg) |
|
78 |
{
|
|
79 |
collation= collation_arg; |
|
80 |
derivation= derivation_arg; |
|
81 |
set_repertoire_from_charset(collation_arg); |
|
82 |
}
|
|
83 |
void set(CHARSET_INFO *collation_arg, |
|
84 |
Derivation derivation_arg, |
|
85 |
uint repertoire_arg) |
|
86 |
{
|
|
87 |
collation= collation_arg; |
|
88 |
derivation= derivation_arg; |
|
89 |
repertoire= repertoire_arg; |
|
90 |
}
|
|
91 |
void set(CHARSET_INFO *collation_arg) |
|
92 |
{
|
|
93 |
collation= collation_arg; |
|
94 |
set_repertoire_from_charset(collation_arg); |
|
95 |
}
|
|
96 |
void set(Derivation derivation_arg) |
|
97 |
{ derivation= derivation_arg; } |
|
98 |
bool aggregate(DTCollation &dt, uint flags= 0); |
|
99 |
bool set(DTCollation &dt1, DTCollation &dt2, uint flags= 0) |
|
100 |
{ set(dt1); return aggregate(dt2, flags); } |
|
101 |
const char *derivation_name() const |
|
102 |
{
|
|
103 |
switch(derivation) |
|
104 |
{
|
|
105 |
case DERIVATION_IGNORABLE: return "IGNORABLE"; |
|
106 |
case DERIVATION_COERCIBLE: return "COERCIBLE"; |
|
107 |
case DERIVATION_IMPLICIT: return "IMPLICIT"; |
|
108 |
case DERIVATION_SYSCONST: return "SYSCONST"; |
|
109 |
case DERIVATION_EXPLICIT: return "EXPLICIT"; |
|
110 |
case DERIVATION_NONE: return "NONE"; |
|
111 |
default: return "UNKNOWN"; |
|
112 |
}
|
|
113 |
}
|
|
114 |
};
|
|
115 |
||
116 |
/*************************************************************************/
|
|
117 |
/*
|
|
118 |
A framework to easily handle different return types for hybrid items
|
|
119 |
(hybrid item is an item whose operand can be of any type, e.g. integer,
|
|
120 |
real, decimal).
|
|
121 |
*/
|
|
122 |
||
123 |
struct Hybrid_type_traits; |
|
124 |
||
125 |
struct Hybrid_type |
|
126 |
{
|
|
127 |
longlong integer; |
|
128 |
||
129 |
double real; |
|
130 |
/*
|
|
131 |
Use two decimal buffers interchangeably to speed up += operation
|
|
132 |
which has no native support in decimal library.
|
|
133 |
Hybrid_type+= arg is implemented as dec_buf[1]= dec_buf[0] + arg.
|
|
134 |
The third decimal is used as a handy temporary storage.
|
|
135 |
*/
|
|
136 |
my_decimal dec_buf[3]; |
|
137 |
int used_dec_buf_no; |
|
138 |
||
139 |
/*
|
|
140 |
Traits moved to a separate class to
|
|
141 |
a) be able to easily change object traits in runtime
|
|
142 |
b) they work as a differentiator for the union above
|
|
143 |
*/
|
|
144 |
const Hybrid_type_traits *traits; |
|
145 |
||
146 |
Hybrid_type() {} |
|
147 |
/* XXX: add traits->copy() when needed */
|
|
148 |
Hybrid_type(const Hybrid_type &rhs) :traits(rhs.traits) {} |
|
149 |
};
|
|
150 |
||
151 |
||
152 |
/* Hybryd_type_traits interface + default implementation for REAL_RESULT */
|
|
153 |
||
154 |
struct Hybrid_type_traits |
|
155 |
{
|
|
156 |
virtual Item_result type() const { return REAL_RESULT; } |
|
157 |
||
158 |
virtual void |
|
159 |
fix_length_and_dec(Item *item, Item *arg) const; |
|
160 |
||
161 |
/* Hybrid_type operations. */
|
|
162 |
virtual void set_zero(Hybrid_type *val) const { val->real= 0.0; } |
|
163 |
virtual void add(Hybrid_type *val, Field *f) const |
|
164 |
{ val->real+= f->val_real(); } |
|
165 |
virtual void div(Hybrid_type *val, ulonglong u) const |
|
166 |
{ val->real/= ulonglong2double(u); } |
|
167 |
||
168 |
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const |
|
169 |
{ return (longlong) rint(val->real); } |
|
170 |
virtual double val_real(Hybrid_type *val) const { return val->real; } |
|
171 |
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const; |
|
172 |
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const; |
|
173 |
static const Hybrid_type_traits *instance(); |
|
174 |
Hybrid_type_traits() {} |
|
175 |
virtual ~Hybrid_type_traits() {} |
|
176 |
};
|
|
177 |
||
178 |
||
179 |
struct Hybrid_type_traits_decimal: public Hybrid_type_traits |
|
180 |
{
|
|
181 |
virtual Item_result type() const { return DECIMAL_RESULT; } |
|
182 |
||
183 |
virtual void |
|
184 |
fix_length_and_dec(Item *arg, Item *item) const; |
|
185 |
||
186 |
/* Hybrid_type operations. */
|
|
187 |
virtual void set_zero(Hybrid_type *val) const; |
|
188 |
virtual void add(Hybrid_type *val, Field *f) const; |
|
189 |
virtual void div(Hybrid_type *val, ulonglong u) const; |
|
190 |
||
191 |
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const; |
|
192 |
virtual double val_real(Hybrid_type *val) const; |
|
193 |
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const |
|
194 |
{ return &val->dec_buf[val->used_dec_buf_no]; } |
|
195 |
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const; |
|
196 |
static const Hybrid_type_traits_decimal *instance(); |
|
197 |
Hybrid_type_traits_decimal() {}; |
|
198 |
};
|
|
199 |
||
200 |
||
201 |
struct Hybrid_type_traits_integer: public Hybrid_type_traits |
|
202 |
{
|
|
203 |
virtual Item_result type() const { return INT_RESULT; } |
|
204 |
||
205 |
virtual void |
|
206 |
fix_length_and_dec(Item *arg, Item *item) const; |
|
207 |
||
208 |
/* Hybrid_type operations. */
|
|
209 |
virtual void set_zero(Hybrid_type *val) const |
|
210 |
{ val->integer= 0; } |
|
211 |
virtual void add(Hybrid_type *val, Field *f) const |
|
212 |
{ val->integer+= f->val_int(); } |
|
213 |
virtual void div(Hybrid_type *val, ulonglong u) const |
|
214 |
{ val->integer/= (longlong) u; } |
|
215 |
||
216 |
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const |
|
217 |
{ return val->integer; } |
|
218 |
virtual double val_real(Hybrid_type *val) const |
|
219 |
{ return (double) val->integer; } |
|
220 |
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const |
|
221 |
{
|
|
222 |
int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]); |
|
223 |
return &val->dec_buf[2]; |
|
224 |
}
|
|
225 |
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const |
|
226 |
{ buf->set(val->integer, &my_charset_bin); return buf;} |
|
227 |
static const Hybrid_type_traits_integer *instance(); |
|
228 |
Hybrid_type_traits_integer() {}; |
|
229 |
};
|
|
230 |
||
231 |
||
232 |
void dummy_error_processor(THD *thd, void *data); |
|
233 |
||
234 |
void view_error_processor(THD *thd, void *data); |
|
235 |
||
236 |
/*
|
|
237 |
Instances of Name_resolution_context store the information necesary for
|
|
238 |
name resolution of Items and other context analysis of a query made in
|
|
239 |
fix_fields().
|
|
240 |
||
241 |
This structure is a part of SELECT_LEX, a pointer to this structure is
|
|
242 |
assigned when an item is created (which happens mostly during parsing
|
|
243 |
(sql_yacc.yy)), but the structure itself will be initialized after parsing
|
|
244 |
is complete
|
|
245 |
||
246 |
TODO: move subquery of INSERT ... SELECT and CREATE ... SELECT to
|
|
247 |
separate SELECT_LEX which allow to remove tricks of changing this
|
|
248 |
structure before and after INSERT/CREATE and its SELECT to make correct
|
|
249 |
field name resolution.
|
|
250 |
*/
|
|
251 |
struct Name_resolution_context: Sql_alloc |
|
252 |
{
|
|
253 |
/*
|
|
254 |
The name resolution context to search in when an Item cannot be
|
|
255 |
resolved in this context (the context of an outer select)
|
|
256 |
*/
|
|
257 |
Name_resolution_context *outer_context; |
|
258 |
||
259 |
/*
|
|
260 |
List of tables used to resolve the items of this context. Usually these
|
|
261 |
are tables from the FROM clause of SELECT statement. The exceptions are
|
|
262 |
INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
|
|
263 |
subquery is not moved to a separate SELECT_LEX. For these types of
|
|
264 |
statements we have to change this member dynamically to ensure correct
|
|
265 |
name resolution of different parts of the statement.
|
|
266 |
*/
|
|
267 |
TABLE_LIST *table_list; |
|
268 |
/*
|
|
269 |
In most cases the two table references below replace 'table_list' above
|
|
270 |
for the purpose of name resolution. The first and last name resolution
|
|
271 |
table references allow us to search only in a sub-tree of the nested
|
|
272 |
join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
|
|
273 |
and JOIN ... ON.
|
|
274 |
*/
|
|
275 |
TABLE_LIST *first_name_resolution_table; |
|
276 |
/*
|
|
277 |
Last table to search in the list of leaf table references that begins
|
|
278 |
with first_name_resolution_table.
|
|
279 |
*/
|
|
280 |
TABLE_LIST *last_name_resolution_table; |
|
281 |
||
282 |
/*
|
|
283 |
SELECT_LEX item belong to, in case of merged VIEW it can differ from
|
|
284 |
SELECT_LEX where item was created, so we can't use table_list/field_list
|
|
285 |
from there
|
|
286 |
*/
|
|
287 |
st_select_lex *select_lex; |
|
288 |
||
289 |
/*
|
|
290 |
Processor of errors caused during Item name resolving, now used only to
|
|
291 |
hide underlying tables in errors about views (i.e. it substitute some
|
|
292 |
errors for views)
|
|
293 |
*/
|
|
294 |
void (*error_processor)(THD *, void *); |
|
295 |
void *error_processor_data; |
|
296 |
||
297 |
/*
|
|
298 |
When TRUE items are resolved in this context both against the
|
|
299 |
SELECT list and this->table_list. If FALSE, items are resolved
|
|
300 |
only against this->table_list.
|
|
301 |
*/
|
|
302 |
bool resolve_in_select_list; |
|
303 |
||
304 |
/*
|
|
305 |
Security context of this name resolution context. It's used for views
|
|
306 |
and is non-zero only if the view is defined with SQL SECURITY DEFINER.
|
|
307 |
*/
|
|
308 |
Security_context *security_ctx; |
|
309 |
||
310 |
Name_resolution_context() |
|
311 |
:outer_context(0), table_list(0), select_lex(0), |
|
312 |
error_processor_data(0), |
|
313 |
security_ctx(0) |
|
314 |
{}
|
|
315 |
||
316 |
void init() |
|
317 |
{
|
|
318 |
resolve_in_select_list= FALSE; |
|
319 |
error_processor= &dummy_error_processor; |
|
320 |
first_name_resolution_table= NULL; |
|
321 |
last_name_resolution_table= NULL; |
|
322 |
}
|
|
323 |
||
324 |
void resolve_in_table_list_only(TABLE_LIST *tables) |
|
325 |
{
|
|
326 |
table_list= first_name_resolution_table= tables; |
|
327 |
resolve_in_select_list= FALSE; |
|
328 |
}
|
|
329 |
||
330 |
void process_error(THD *thd) |
|
331 |
{
|
|
332 |
(*error_processor)(thd, error_processor_data); |
|
333 |
}
|
|
334 |
};
|
|
335 |
||
336 |
||
337 |
/*
|
|
338 |
Store and restore the current state of a name resolution context.
|
|
339 |
*/
|
|
340 |
||
341 |
class Name_resolution_context_state |
|
342 |
{
|
|
343 |
private: |
|
344 |
TABLE_LIST *save_table_list; |
|
345 |
TABLE_LIST *save_first_name_resolution_table; |
|
346 |
TABLE_LIST *save_next_name_resolution_table; |
|
347 |
bool save_resolve_in_select_list; |
|
348 |
TABLE_LIST *save_next_local; |
|
349 |
||
350 |
public: |
|
351 |
Name_resolution_context_state() {} /* Remove gcc warning */ |
|
352 |
||
353 |
public: |
|
354 |
/* Save the state of a name resolution context. */
|
|
355 |
void save_state(Name_resolution_context *context, TABLE_LIST *table_list) |
|
356 |
{
|
|
357 |
save_table_list= context->table_list; |
|
358 |
save_first_name_resolution_table= context->first_name_resolution_table; |
|
359 |
save_resolve_in_select_list= context->resolve_in_select_list; |
|
360 |
save_next_local= table_list->next_local; |
|
361 |
save_next_name_resolution_table= table_list->next_name_resolution_table; |
|
362 |
}
|
|
363 |
||
364 |
/* Restore a name resolution context from saved state. */
|
|
365 |
void restore_state(Name_resolution_context *context, TABLE_LIST *table_list) |
|
366 |
{
|
|
367 |
table_list->next_local= save_next_local; |
|
368 |
table_list->next_name_resolution_table= save_next_name_resolution_table; |
|
369 |
context->table_list= save_table_list; |
|
370 |
context->first_name_resolution_table= save_first_name_resolution_table; |
|
371 |
context->resolve_in_select_list= save_resolve_in_select_list; |
|
372 |
}
|
|
373 |
||
374 |
TABLE_LIST *get_first_name_resolution_table() |
|
375 |
{
|
|
376 |
return save_first_name_resolution_table; |
|
377 |
}
|
|
378 |
};
|
|
379 |
||
380 |
||
381 |
/*
|
|
382 |
This enum is used to report information about monotonicity of function
|
|
383 |
represented by Item* tree.
|
|
384 |
Monotonicity is defined only for Item* trees that represent table
|
|
385 |
partitioning expressions (i.e. have no subselects/user vars/PS parameters
|
|
386 |
etc etc). An Item* tree is assumed to have the same monotonicity properties
|
|
387 |
as its correspoinding function F:
|
|
388 |
||
389 |
[signed] longlong F(field1, field2, ...) {
|
|
390 |
put values of field_i into table record buffer;
|
|
391 |
return item->val_int();
|
|
392 |
}
|
|
393 |
||
394 |
NOTE
|
|
395 |
At the moment function monotonicity is not well defined (and so may be
|
|
396 |
incorrect) for Item trees with parameters/return types that are different
|
|
397 |
from INT_RESULT, may be NULL, or are unsigned.
|
|
398 |
It will be possible to address this issue once the related partitioning bugs
|
|
399 |
(BUG#16002, BUG#15447, BUG#13436) are fixed.
|
|
400 |
*/
|
|
401 |
||
402 |
typedef enum monotonicity_info |
|
403 |
{
|
|
404 |
NON_MONOTONIC, /* none of the below holds */ |
|
405 |
MONOTONIC_INCREASING, /* F() is unary and (x < y) => (F(x) <= F(y)) */ |
|
406 |
MONOTONIC_STRICT_INCREASING /* F() is unary and (x < y) => (F(x) < F(y)) */ |
|
407 |
} enum_monotonicity_info; |
|
408 |
||
409 |
/*************************************************************************/
|
|
410 |
typedef bool (Item::*Item_processor) (uchar *arg); |
|
411 |
/*
|
|
412 |
Analyzer function
|
|
413 |
SYNOPSIS
|
|
414 |
argp in/out IN: Analysis parameter
|
|
415 |
OUT: Parameter to be passed to the transformer
|
|
416 |
||
417 |
RETURN
|
|
418 |
TRUE Invoke the transformer
|
|
419 |
FALSE Don't do it
|
|
420 |
||
421 |
*/
|
|
422 |
typedef bool (Item::*Item_analyzer) (uchar **argp); |
|
423 |
typedef Item* (Item::*Item_transformer) (uchar *arg); |
|
424 |
typedef void (*Cond_traverser) (const Item *item, void *arg); |
|
425 |
||
426 |
||
427 |
class Item |
|
428 |
{
|
|
429 |
Item(const Item &); /* Prevent use of these */ |
|
430 |
void operator=(Item &); |
|
431 |
/* Cache of the result of is_expensive(). */
|
|
432 |
int8 is_expensive_cache; |
|
433 |
virtual bool is_expensive_processor(uchar *arg) { return 0; } |
|
434 |
||
435 |
public: |
|
436 |
static void *operator new(size_t size) |
|
437 |
{ return sql_alloc(size); } |
|
438 |
static void *operator new(size_t size, MEM_ROOT *mem_root) |
|
439 |
{ return alloc_root(mem_root, size); } |
|
440 |
static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); } |
|
441 |
static void operator delete(void *ptr, MEM_ROOT *mem_root) {} |
|
442 |
||
443 |
enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM, |
|
444 |
INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM, |
|
445 |
COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM, |
|
446 |
PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM, |
|
447 |
FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM, |
|
448 |
SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER, |
|
449 |
PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM, |
|
450 |
XPATH_NODESET, XPATH_NODESET_CMP, |
|
451 |
VIEW_FIXER_ITEM}; |
|
452 |
||
453 |
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE }; |
|
454 |
||
455 |
enum traverse_order { POSTFIX, PREFIX }; |
|
456 |
||
457 |
/* Reuse size, only used by SP local variable assignment, otherwize 0 */
|
|
458 |
uint rsize; |
|
459 |
||
460 |
/*
|
|
461 |
str_values's main purpose is to be used to cache the value in
|
|
462 |
save_in_field
|
|
463 |
*/
|
|
464 |
String str_value; |
|
465 |
char * name; /* Name from select */ |
|
466 |
/* Original item name (if it was renamed)*/
|
|
467 |
char * orig_name; |
|
468 |
Item *next; |
|
469 |
uint32 max_length; |
|
470 |
uint name_length; /* Length of name */ |
|
471 |
int8 marker; |
|
472 |
uint8 decimals; |
|
473 |
my_bool maybe_null; /* If item may be null */ |
|
474 |
my_bool null_value; /* if item is null */ |
|
475 |
my_bool unsigned_flag; |
|
476 |
my_bool with_sum_func; |
|
477 |
my_bool fixed; /* If item fixed with fix_fields */ |
|
478 |
my_bool is_autogenerated_name; /* indicate was name of this Item |
|
479 |
autogenerated or set by user */
|
|
480 |
DTCollation collation; |
|
481 |
my_bool with_subselect; /* If this item is a subselect or some |
|
482 |
of its arguments is or contains a
|
|
483 |
subselect. Computed by fix_fields. */
|
|
484 |
Item_result cmp_context; /* Comparison context */ |
|
485 |
// alloc & destruct is done as start of select using sql_alloc
|
|
486 |
Item(); |
|
487 |
/*
|
|
488 |
Constructor used by Item_field, Item_ref & aggregate (sum) functions.
|
|
489 |
Used for duplicating lists in processing queries with temporary
|
|
490 |
tables
|
|
491 |
Also it used for Item_cond_and/Item_cond_or for creating
|
|
492 |
top AND/OR structure of WHERE clause to protect it of
|
|
493 |
optimisation changes in prepared statements
|
|
494 |
*/
|
|
495 |
Item(THD *thd, Item *item); |
|
496 |
virtual ~Item() |
|
497 |
{
|
|
498 |
#ifdef EXTRA_DEBUG
|
|
499 |
name=0; |
|
500 |
#endif
|
|
501 |
} /*lint -e1509 */ |
|
502 |
void set_name(const char *str, uint length, CHARSET_INFO *cs); |
|
503 |
void rename(char *new_name); |
|
504 |
void init_make_field(Send_field *tmp_field,enum enum_field_types type); |
|
505 |
virtual void cleanup(); |
|
506 |
virtual void make_field(Send_field *field); |
|
507 |
Field *make_string_field(TABLE *table); |
|
508 |
virtual bool fix_fields(THD *, Item **); |
|
509 |
/*
|
|
510 |
Fix after some tables has been pulled out. Basically re-calculate all
|
|
511 |
attributes that are dependent on the tables.
|
|
512 |
*/
|
|
513 |
virtual void fix_after_pullout(st_select_lex *new_parent, Item **ref) {}; |
|
514 |
||
515 |
/*
|
|
516 |
should be used in case where we are sure that we do not need
|
|
517 |
complete fix_fields() procedure.
|
|
518 |
*/
|
|
519 |
inline void quick_fix_field() { fixed= 1; } |
|
520 |
/* Function returns 1 on overflow and -1 on fatal errors */
|
|
521 |
int save_in_field_no_warnings(Field *field, bool no_conversions); |
|
522 |
virtual int save_in_field(Field *field, bool no_conversions); |
|
523 |
virtual void save_org_in_field(Field *field) |
|
524 |
{ (void) save_in_field(field, 1); } |
|
525 |
virtual int save_safe_in_field(Field *field) |
|
526 |
{ return save_in_field(field, 1); } |
|
527 |
virtual bool send(Protocol *protocol, String *str); |
|
528 |
virtual bool eq(const Item *, bool binary_cmp) const; |
|
529 |
virtual Item_result result_type() const { return REAL_RESULT; } |
|
530 |
virtual Item_result cast_to_int_type() const { return result_type(); } |
|
531 |
virtual enum_field_types string_field_type() const; |
|
532 |
virtual enum_field_types field_type() const; |
|
533 |
virtual enum Type type() const =0; |
|
534 |
||
535 |
/*
|
|
536 |
Return information about function monotonicity. See comment for
|
|
537 |
enum_monotonicity_info for details. This function can only be called
|
|
538 |
after fix_fields() call.
|
|
539 |
*/
|
|
540 |
virtual enum_monotonicity_info get_monotonicity_info() const |
|
541 |
{ return NON_MONOTONIC; } |
|
542 |
||
543 |
/*
|
|
544 |
Convert "func_arg $CMP$ const" half-interval into "FUNC(func_arg) $CMP2$ const2"
|
|
545 |
||
546 |
SYNOPSIS
|
|
547 |
val_int_endpoint()
|
|
548 |
left_endp FALSE <=> The interval is "x < const" or "x <= const"
|
|
549 |
TRUE <=> The interval is "x > const" or "x >= const"
|
|
550 |
||
551 |
incl_endp IN TRUE <=> the comparison is '<' or '>'
|
|
552 |
FALSE <=> the comparison is '<=' or '>='
|
|
553 |
OUT The same but for the "F(x) $CMP$ F(const)" comparison
|
|
554 |
||
555 |
DESCRIPTION
|
|
556 |
This function is defined only for unary monotonic functions. The caller
|
|
557 |
supplies the source half-interval
|
|
558 |
||
559 |
x $CMP$ const
|
|
560 |
||
561 |
The value of const is supplied implicitly as the value this item's
|
|
562 |
argument, the form of $CMP$ comparison is specified through the
|
|
563 |
function's arguments. The calle returns the result interval
|
|
564 |
|
|
565 |
F(x) $CMP2$ F(const)
|
|
566 |
|
|
567 |
passing back F(const) as the return value, and the form of $CMP2$
|
|
568 |
through the out parameter. NULL values are assumed to be comparable and
|
|
569 |
be less than any non-NULL values.
|
|
570 |
||
571 |
RETURN
|
|
572 |
The output range bound, which equal to the value of val_int()
|
|
573 |
- If the value of the function is NULL then the bound is the
|
|
574 |
smallest possible value of LONGLONG_MIN
|
|
575 |
*/
|
|
576 |
virtual longlong val_int_endpoint(bool left_endp, bool *incl_endp) |
|
577 |
{ DBUG_ASSERT(0); return 0; } |
|
578 |
||
579 |
||
580 |
/* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */
|
|
581 |
/*
|
|
582 |
Return double precision floating point representation of item.
|
|
583 |
||
584 |
SYNOPSIS
|
|
585 |
val_real()
|
|
586 |
||
587 |
RETURN
|
|
588 |
In case of NULL value return 0.0 and set null_value flag to TRUE.
|
|
589 |
If value is not null null_value flag will be reset to FALSE.
|
|
590 |
*/
|
|
591 |
virtual double val_real()=0; |
|
592 |
/*
|
|
593 |
Return integer representation of item.
|
|
594 |
||
595 |
SYNOPSIS
|
|
596 |
val_int()
|
|
597 |
||
598 |
RETURN
|
|
599 |
In case of NULL value return 0 and set null_value flag to TRUE.
|
|
600 |
If value is not null null_value flag will be reset to FALSE.
|
|
601 |
*/
|
|
602 |
virtual longlong val_int()=0; |
|
603 |
/*
|
|
604 |
This is just a shortcut to avoid the cast. You should still use
|
|
605 |
unsigned_flag to check the sign of the item.
|
|
606 |
*/
|
|
607 |
inline ulonglong val_uint() { return (ulonglong) val_int(); } |
|
608 |
/*
|
|
609 |
Return string representation of this item object.
|
|
610 |
||
611 |
SYNOPSIS
|
|
612 |
val_str()
|
|
613 |
str an allocated buffer this or any nested Item object can use to
|
|
614 |
store return value of this method.
|
|
615 |
||
616 |
NOTE
|
|
617 |
Buffer passed via argument should only be used if the item itself
|
|
618 |
doesn't have an own String buffer. In case when the item maintains
|
|
619 |
it's own string buffer, it's preferable to return it instead to
|
|
620 |
minimize number of mallocs/memcpys.
|
|
621 |
The caller of this method can modify returned string, but only in case
|
|
622 |
when it was allocated on heap, (is_alloced() is true). This allows
|
|
623 |
the caller to efficiently use a buffer allocated by a child without
|
|
624 |
having to allocate a buffer of it's own. The buffer, given to
|
|
625 |
val_str() as argument, belongs to the caller and is later used by the
|
|
626 |
caller at it's own choosing.
|
|
627 |
A few implications from the above:
|
|
628 |
- unless you return a string object which only points to your buffer
|
|
629 |
but doesn't manages it you should be ready that it will be
|
|
630 |
modified.
|
|
631 |
- even for not allocated strings (is_alloced() == false) the caller
|
|
632 |
can change charset (see Item_func_{typecast/binary}. XXX: is this
|
|
633 |
a bug?
|
|
634 |
- still you should try to minimize data copying and return internal
|
|
635 |
object whenever possible.
|
|
636 |
||
637 |
RETURN
|
|
638 |
In case of NULL value return 0 (NULL pointer) and set null_value flag
|
|
639 |
to TRUE.
|
|
640 |
If value is not null null_value flag will be reset to FALSE.
|
|
641 |
*/
|
|
642 |
virtual String *val_str(String *str)=0; |
|
643 |
/*
|
|
644 |
Return decimal representation of item with fixed point.
|
|
645 |
||
646 |
SYNOPSIS
|
|
647 |
val_decimal()
|
|
648 |
decimal_buffer buffer which can be used by Item for returning value
|
|
649 |
(but can be not)
|
|
650 |
||
651 |
NOTE
|
|
652 |
Returned value should not be changed if it is not the same which was
|
|
653 |
passed via argument.
|
|
654 |
||
655 |
RETURN
|
|
656 |
Return pointer on my_decimal (it can be other then passed via argument)
|
|
657 |
if value is not NULL (null_value flag will be reset to FALSE).
|
|
658 |
In case of NULL value it return 0 pointer and set null_value flag
|
|
659 |
to TRUE.
|
|
660 |
*/
|
|
661 |
virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0; |
|
662 |
/*
|
|
663 |
Return boolean value of item.
|
|
664 |
||
665 |
RETURN
|
|
666 |
FALSE value is false or NULL
|
|
667 |
TRUE value is true (not equal to 0)
|
|
668 |
*/
|
|
669 |
virtual bool val_bool(); |
|
670 |
virtual String *val_nodeset(String*) { return 0; } |
|
671 |
/* Helper functions, see item_sum.cc */
|
|
672 |
String *val_string_from_real(String *str); |
|
673 |
String *val_string_from_int(String *str); |
|
674 |
String *val_string_from_decimal(String *str); |
|
675 |
my_decimal *val_decimal_from_real(my_decimal *decimal_value); |
|
676 |
my_decimal *val_decimal_from_int(my_decimal *decimal_value); |
|
677 |
my_decimal *val_decimal_from_string(my_decimal *decimal_value); |
|
678 |
my_decimal *val_decimal_from_date(my_decimal *decimal_value); |
|
679 |
my_decimal *val_decimal_from_time(my_decimal *decimal_value); |
|
680 |
longlong val_int_from_decimal(); |
|
681 |
double val_real_from_decimal(); |
|
682 |
||
683 |
int save_time_in_field(Field *field); |
|
684 |
int save_date_in_field(Field *field); |
|
685 |
int save_str_value_in_field(Field *field, String *result); |
|
686 |
||
687 |
virtual Field *get_tmp_table_field() { return 0; } |
|
688 |
/* This is also used to create fields in CREATE ... SELECT: */
|
|
689 |
virtual Field *tmp_table_field(TABLE *t_arg) { return 0; } |
|
690 |
virtual const char *full_name() const { return name ? name : "???"; } |
|
691 |
||
692 |
/*
|
|
693 |
*result* family of methods is analog of *val* family (see above) but
|
|
694 |
return value of result_field of item if it is present. If Item have not
|
|
695 |
result field, it return val(). This methods set null_value flag in same
|
|
696 |
way as *val* methods do it.
|
|
697 |
*/
|
|
698 |
virtual double val_result() { return val_real(); } |
|
699 |
virtual longlong val_int_result() { return val_int(); } |
|
700 |
virtual String *str_result(String* tmp) { return val_str(tmp); } |
|
701 |
virtual my_decimal *val_decimal_result(my_decimal *val) |
|
702 |
{ return val_decimal(val); } |
|
703 |
virtual bool val_bool_result() { return val_bool(); } |
|
704 |
||
705 |
/* bit map of tables used by item */
|
|
706 |
virtual table_map used_tables() const { return (table_map) 0L; } |
|
707 |
/*
|
|
708 |
Return table map of tables that can't be NULL tables (tables that are
|
|
709 |
used in a context where if they would contain a NULL row generated
|
|
710 |
by a LEFT or RIGHT join, the item would not be true).
|
|
711 |
This expression is used on WHERE item to determinate if a LEFT JOIN can be
|
|
712 |
converted to a normal join.
|
|
713 |
Generally this function should return used_tables() if the function
|
|
714 |
would return null if any of the arguments are null
|
|
715 |
As this is only used in the beginning of optimization, the value don't
|
|
716 |
have to be updated in update_used_tables()
|
|
717 |
*/
|
|
718 |
virtual table_map not_null_tables() const { return used_tables(); } |
|
719 |
/*
|
|
720 |
Returns true if this is a simple constant item like an integer, not
|
|
721 |
a constant expression. Used in the optimizer to propagate basic constants.
|
|
722 |
*/
|
|
723 |
virtual bool basic_const_item() const { return 0; } |
|
724 |
/* cloning of constant items (0 if it is not const) */
|
|
725 |
virtual Item *clone_item() { return 0; } |
|
726 |
virtual cond_result eq_cmp_result() const { return COND_OK; } |
|
727 |
inline uint float_length(uint decimals_par) const |
|
728 |
{ return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;} |
|
729 |
virtual uint decimal_precision() const; |
|
730 |
inline int decimal_int_part() const |
|
731 |
{ return my_decimal_int_part(decimal_precision(), decimals); } |
|
732 |
/*
|
|
733 |
Returns true if this is constant (during query execution, i.e. its value
|
|
734 |
will not change until next fix_fields) and its value is known.
|
|
735 |
*/
|
|
736 |
virtual bool const_item() const { return used_tables() == 0; } |
|
737 |
/*
|
|
738 |
Returns true if this is constant but its value may be not known yet.
|
|
739 |
(Can be used for parameters of prep. stmts or of stored procedures.)
|
|
740 |
*/
|
|
741 |
virtual bool const_during_execution() const |
|
742 |
{ return (used_tables() & ~PARAM_TABLE_BIT) == 0; } |
|
743 |
||
744 |
/**
|
|
745 |
This method is used for to:
|
|
746 |
- to generate a view definition query (SELECT-statement);
|
|
747 |
- to generate a SQL-query for EXPLAIN EXTENDED;
|
|
748 |
- to generate a SQL-query to be shown in INFORMATION_SCHEMA;
|
|
749 |
- debug.
|
|
750 |
||
751 |
For more information about view definition query, INFORMATION_SCHEMA
|
|
752 |
query and why they should be generated from the Item-tree, @see
|
|
753 |
mysql_register_view().
|
|
754 |
*/
|
|
755 |
virtual inline void print(String *str, enum_query_type query_type) |
|
756 |
{
|
|
757 |
str->append(full_name()); |
|
758 |
}
|
|
759 |
||
760 |
void print_item_w_name(String *, enum_query_type query_type); |
|
761 |
virtual void update_used_tables() {} |
|
762 |
virtual void split_sum_func(THD *thd, Item **ref_pointer_array, |
|
763 |
List<Item> &fields) {} |
|
764 |
/* Called for items that really have to be split */
|
|
765 |
void split_sum_func2(THD *thd, Item **ref_pointer_array, List<Item> &fields, |
|
766 |
Item **ref, bool skip_registered); |
|
767 |
virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate); |
|
768 |
virtual bool get_time(MYSQL_TIME *ltime); |
|
769 |
virtual bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate) |
|
770 |
{ return get_date(ltime,fuzzydate); } |
|
771 |
/*
|
|
772 |
The method allows to determine nullness of a complex expression
|
|
773 |
without fully evaluating it, instead of calling val/result*() then
|
|
774 |
checking null_value. Used in Item_func_isnull/Item_func_isnotnull
|
|
775 |
and Item_sum_count/Item_sum_count_distinct.
|
|
776 |
Any new item which can be NULL must implement this method.
|
|
777 |
*/
|
|
778 |
virtual bool is_null() { return 0; } |
|
779 |
||
780 |
/*
|
|
781 |
Make sure the null_value member has a correct value.
|
|
782 |
*/
|
|
783 |
virtual void update_null_value () { (void) val_int(); } |
|
784 |
||
785 |
/*
|
|
786 |
Inform the item that there will be no distinction between its result
|
|
787 |
being FALSE or NULL.
|
|
788 |
||
789 |
NOTE
|
|
790 |
This function will be called for eg. Items that are top-level AND-parts
|
|
791 |
of the WHERE clause. Items implementing this function (currently
|
|
792 |
Item_cond_and and subquery-related item) enable special optimizations
|
|
793 |
when they are "top level".
|
|
794 |
*/
|
|
795 |
virtual void top_level_item() {} |
|
796 |
/*
|
|
797 |
set field of temporary table for Item which can be switched on temporary
|
|
798 |
table during query processing (grouping and so on)
|
|
799 |
*/
|
|
800 |
virtual void set_result_field(Field *field) {} |
|
801 |
virtual bool is_result_field() { return 0; } |
|
802 |
virtual bool is_bool_func() { return 0; } |
|
803 |
virtual void save_in_result_field(bool no_conversions) {} |
|
804 |
/*
|
|
805 |
set value of aggregate function in case of no rows for grouping were found
|
|
806 |
*/
|
|
807 |
virtual void no_rows_in_result() {} |
|
808 |
virtual Item *copy_or_same(THD *thd) { return this; } |
|
809 |
virtual Item *copy_andor_structure(THD *thd) { return this; } |
|
810 |
virtual Item *real_item() { return this; } |
|
811 |
virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); } |
|
812 |
||
813 |
static CHARSET_INFO *default_charset(); |
|
814 |
virtual CHARSET_INFO *compare_collation() { return NULL; } |
|
815 |
||
816 |
virtual bool walk(Item_processor processor, bool walk_subquery, uchar *arg) |
|
817 |
{
|
|
818 |
return (this->*processor)(arg); |
|
819 |
}
|
|
820 |
||
821 |
virtual Item* transform(Item_transformer transformer, uchar *arg); |
|
822 |
||
823 |
/*
|
|
824 |
This function performs a generic "compilation" of the Item tree.
|
|
825 |
The process of compilation is assumed to go as follows:
|
|
826 |
|
|
827 |
compile()
|
|
828 |
{
|
|
829 |
if (this->*some_analyzer(...))
|
|
830 |
{
|
|
831 |
compile children if any;
|
|
832 |
this->*some_transformer(...);
|
|
833 |
}
|
|
834 |
}
|
|
835 |
||
836 |
i.e. analysis is performed top-down while transformation is done
|
|
837 |
bottom-up.
|
|
838 |
*/
|
|
839 |
virtual Item* compile(Item_analyzer analyzer, uchar **arg_p, |
|
840 |
Item_transformer transformer, uchar *arg_t) |
|
841 |
{
|
|
842 |
if ((this->*analyzer) (arg_p)) |
|
843 |
return ((this->*transformer) (arg_t)); |
|
844 |
return 0; |
|
845 |
}
|
|
846 |
||
847 |
virtual void traverse_cond(Cond_traverser traverser, |
|
848 |
void *arg, traverse_order order) |
|
849 |
{
|
|
850 |
(*traverser)(this, arg); |
|
851 |
}
|
|
852 |
||
853 |
virtual bool remove_dependence_processor(uchar * arg) { return 0; } |
|
854 |
virtual bool remove_fixed(uchar * arg) { fixed= 0; return 0; } |
|
855 |
virtual bool cleanup_processor(uchar *arg); |
|
856 |
virtual bool collect_item_field_processor(uchar * arg) { return 0; } |
|
857 |
virtual bool find_item_in_field_list_processor(uchar *arg) { return 0; } |
|
858 |
virtual bool change_context_processor(uchar *context) { return 0; } |
|
859 |
virtual bool reset_query_id_processor(uchar *query_id_arg) { return 0; } |
|
860 |
virtual bool register_field_in_read_map(uchar *arg) { return 0; } |
|
861 |
virtual bool subst_argument_checker(uchar **arg) |
|
862 |
{
|
|
863 |
if (*arg) |
|
864 |
*arg= NULL; |
|
865 |
return TRUE; |
|
866 |
}
|
|
867 |
||
868 |
virtual Item *equal_fields_propagator(uchar * arg) { return this; } |
|
869 |
virtual bool set_no_const_sub(uchar *arg) { return FALSE; } |
|
870 |
virtual Item *replace_equal_field(uchar * arg) { return this; } |
|
871 |
||
872 |
/*
|
|
873 |
For SP local variable returns pointer to Item representing its
|
|
874 |
current value and pointer to current Item otherwise.
|
|
875 |
*/
|
|
876 |
virtual Item *this_item() { return this; } |
|
877 |
virtual const Item *this_item() const { return this; } |
|
878 |
||
879 |
/*
|
|
880 |
For SP local variable returns address of pointer to Item representing its
|
|
881 |
current value and pointer passed via parameter otherwise.
|
|
882 |
*/
|
|
883 |
virtual Item **this_item_addr(THD *thd, Item **addr_arg) { return addr_arg; } |
|
884 |
||
885 |
// Row emulation
|
|
886 |
virtual uint cols() { return 1; } |
|
887 |
virtual Item* element_index(uint i) { return this; } |
|
888 |
virtual Item** addr(uint i) { return 0; } |
|
889 |
virtual bool check_cols(uint c); |
|
890 |
// It is not row => null inside is impossible
|
|
891 |
virtual bool null_inside() { return 0; } |
|
892 |
// used in row subselects to get value of elements
|
|
893 |
virtual void bring_value() {} |
|
894 |
||
895 |
Field *tmp_table_field_from_field_type(TABLE *table, bool fixed_length); |
|
896 |
virtual Item_field *filed_for_view_update() { return 0; } |
|
897 |
||
898 |
virtual Item *neg_transformer(THD *thd) { return NULL; } |
|
899 |
virtual Item *update_value_transformer(uchar *select_arg) { return this; } |
|
900 |
virtual Item *safe_charset_converter(CHARSET_INFO *tocs); |
|
901 |
void delete_self() |
|
902 |
{
|
|
903 |
cleanup(); |
|
904 |
delete this; |
|
905 |
}
|
|
906 |
||
907 |
/*
|
|
908 |
result_as_longlong() must return TRUE for Items representing DATE/TIME
|
|
909 |
functions and DATE/TIME table fields.
|
|
910 |
Those Items have result_type()==STRING_RESULT (and not INT_RESULT), but
|
|
911 |
their values should be compared as integers (because the integer
|
|
912 |
representation is more precise than the string one).
|
|
913 |
*/
|
|
914 |
virtual bool result_as_longlong() { return FALSE; } |
|
915 |
bool is_datetime(); |
|
916 |
||
917 |
/*
|
|
918 |
Test whether an expression is expensive to compute. Used during
|
|
919 |
optimization to avoid computing expensive expressions during this
|
|
920 |
phase. Also used to force temp tables when sorting on expensive
|
|
921 |
functions.
|
|
922 |
TODO:
|
|
923 |
Normally we should have a method:
|
|
924 |
cost Item::execution_cost(),
|
|
925 |
where 'cost' is either 'double' or some structure of various cost
|
|
926 |
parameters.
|
|
927 |
*/
|
|
928 |
virtual bool is_expensive() |
|
929 |
{
|
|
930 |
if (is_expensive_cache < 0) |
|
931 |
is_expensive_cache= walk(&Item::is_expensive_processor, 0, (uchar*)0); |
|
932 |
return test(is_expensive_cache); |
|
933 |
}
|
|
934 |
String *check_well_formed_result(String *str, bool send_error= 0); |
|
935 |
bool eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs); |
|
936 |
};
|
|
937 |
||
938 |
||
939 |
class Item_basic_constant :public Item |
|
940 |
{
|
|
941 |
public: |
|
942 |
/* to prevent drop fixed flag (no need parent cleanup call) */
|
|
943 |
void cleanup() |
|
944 |
{
|
|
945 |
/*
|
|
946 |
Restore the original field name as it might not have been allocated
|
|
947 |
in the statement memory. If the name is auto generated, it must be
|
|
948 |
done again between subsequent executions of a prepared statement.
|
|
949 |
*/
|
|
950 |
if (orig_name) |
|
951 |
name= orig_name; |
|
952 |
}
|
|
953 |
};
|
|
954 |
||
955 |
bool agg_item_collations(DTCollation &c, const char *name, |
|
956 |
Item **items, uint nitems, uint flags, int item_sep); |
|
957 |
bool agg_item_collations_for_comparison(DTCollation &c, const char *name, |
|
958 |
Item **items, uint nitems, uint flags); |
|
959 |
bool agg_item_charsets(DTCollation &c, const char *name, |
|
960 |
Item **items, uint nitems, uint flags, int item_sep); |
|
961 |
||
962 |
||
963 |
class Item_num: public Item_basic_constant |
|
964 |
{
|
|
965 |
public: |
|
966 |
Item_num() {} /* Remove gcc warning */ |
|
967 |
virtual Item_num *neg()= 0; |
|
968 |
Item *safe_charset_converter(CHARSET_INFO *tocs); |
|
969 |
};
|
|
970 |
||
971 |
#define NO_CACHED_FIELD_INDEX ((uint)(-1))
|
|
972 |
||
973 |
class st_select_lex; |
|
974 |
class Item_ident :public Item |
|
975 |
{
|
|
976 |
protected: |
|
977 |
/*
|
|
978 |
We have to store initial values of db_name, table_name and field_name
|
|
979 |
to be able to restore them during cleanup() because they can be
|
|
980 |
updated during fix_fields() to values from Field object and life-time
|
|
981 |
of those is shorter than life-time of Item_field.
|
|
982 |
*/
|
|
983 |
const char *orig_db_name; |
|
984 |
const char *orig_table_name; |
|
985 |
const char *orig_field_name; |
|
986 |
||
987 |
public: |
|
988 |
Name_resolution_context *context; |
|
989 |
const char *db_name; |
|
990 |
const char *table_name; |
|
991 |
const char *field_name; |
|
992 |
bool alias_name_used; /* true if item was resolved against alias */ |
|
993 |
/*
|
|
994 |
Cached value of index for this field in table->field array, used by prep.
|
|
995 |
stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX
|
|
996 |
if index value is not known.
|
|
997 |
*/
|
|
998 |
uint cached_field_index; |
|
999 |
/*
|
|
1000 |
Cached pointer to table which contains this field, used for the same reason
|
|
1001 |
by prep. stmt. too in case then we have not-fully qualified field.
|
|
1002 |
0 - means no cached value.
|
|
1003 |
*/
|
|
1004 |
TABLE_LIST *cached_table; |
|
1005 |
st_select_lex *depended_from; |
|
1006 |
Item_ident(Name_resolution_context *context_arg, |
|
1007 |
const char *db_name_arg, const char *table_name_arg, |
|
1008 |
const char *field_name_arg); |
|
1009 |
Item_ident(THD *thd, Item_ident *item); |
|
1010 |
const char *full_name() const; |
|
1011 |
void cleanup(); |
|
1012 |
bool remove_dependence_processor(uchar * arg); |
|
1013 |
virtual void print(String *str, enum_query_type query_type); |
|
1014 |
virtual bool change_context_processor(uchar *cntx) |
|
1015 |
{ context= (Name_resolution_context *)cntx; return FALSE; } |
|
1016 |
friend bool insert_fields(THD *thd, Name_resolution_context *context, |
|
1017 |
const char *db_name, |
|
1018 |
const char *table_name, List_iterator<Item> *it, |
|
1019 |
bool any_privileges); |
|
1020 |
};
|
|
1021 |
||
1022 |
||
1023 |
class Item_ident_for_show :public Item |
|
1024 |
{
|
|
1025 |
public: |
|
1026 |
Field *field; |
|
1027 |
const char *db_name; |
|
1028 |
const char *table_name; |
|
1029 |
||
1030 |
Item_ident_for_show(Field *par_field, const char *db_arg, |
|
1031 |
const char *table_name_arg) |
|
1032 |
:field(par_field), db_name(db_arg), table_name(table_name_arg) |
|
1033 |
{}
|
|
1034 |
||
1035 |
enum Type type() const { return FIELD_ITEM; } |
|
1036 |
double val_real() { return field->val_real(); } |
|
1037 |
longlong val_int() { return field->val_int(); } |
|
1038 |
String *val_str(String *str) { return field->val_str(str); } |
|
1039 |
my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); } |
|
1040 |
void make_field(Send_field *tmp_field); |
|
1041 |
};
|
|
1042 |
||
1043 |
||
1044 |
class Item_equal; |
|
1045 |
class COND_EQUAL; |
|
1046 |
||
1047 |
class Item_field :public Item_ident |
|
1048 |
{
|
|
1049 |
protected: |
|
1050 |
void set_field(Field *field); |
|
1051 |
public: |
|
1052 |
Field *field,*result_field; |
|
1053 |
Item_equal *item_equal; |
|
1054 |
bool no_const_subst; |
|
1055 |
/*
|
|
1056 |
if any_privileges set to TRUE then here real effective privileges will
|
|
1057 |
be stored
|
|
1058 |
*/
|
|
1059 |
uint have_privileges; |
|
1060 |
/* field need any privileges (for VIEW creation) */
|
|
1061 |
bool any_privileges; |
|
1062 |
Item_field(Name_resolution_context *context_arg, |
|
1063 |
const char *db_arg,const char *table_name_arg, |
|
1064 |
const char *field_name_arg); |
|
1065 |
/*
|
|
1066 |
Constructor needed to process subselect with temporary tables (see Item)
|
|
1067 |
*/
|
|
1068 |
Item_field(THD *thd, Item_field *item); |
|
1069 |
/*
|
|
1070 |
Constructor used inside setup_wild(), ensures that field, table,
|
|
1071 |
and database names will live as long as Item_field (this is important
|
|
1072 |
in prepared statements).
|
|
1073 |
*/
|
|
1074 |
Item_field(THD *thd, Name_resolution_context *context_arg, Field *field); |
|
1075 |
/*
|
|
1076 |
If this constructor is used, fix_fields() won't work, because
|
|
1077 |
db_name, table_name and column_name are unknown. It's necessary to call
|
|
1078 |
reset_field() before fix_fields() for all fields created this way.
|
|
1079 |
*/
|
|
1080 |
Item_field(Field *field); |
|
1081 |
enum Type type() const { return FIELD_ITEM; } |
|
1082 |
bool eq(const Item *item, bool binary_cmp) const; |
|
1083 |
double val_real(); |
|
1084 |
longlong val_int(); |
|
1085 |
my_decimal *val_decimal(my_decimal *); |
|
1086 |
String *val_str(String*); |
|
1087 |
double val_result(); |
|
1088 |
longlong val_int_result(); |
|
1089 |
String *str_result(String* tmp); |
|
1090 |
my_decimal *val_decimal_result(my_decimal *); |
|
1091 |
bool val_bool_result(); |
|
1092 |
bool send(Protocol *protocol, String *str_arg); |
|
1093 |
void reset_field(Field *f); |
|
1094 |
bool fix_fields(THD *, Item **); |
|
1095 |
void fix_after_pullout(st_select_lex *new_parent, Item **ref); |
|
1096 |
void make_field(Send_field *tmp_field); |
|
1097 |
int save_in_field(Field *field,bool no_conversions); |
|
1098 |
void save_org_in_field(Field *field); |
|
1099 |
table_map used_tables() const; |
|
1100 |
enum Item_result result_type () const |
|
1101 |
{
|
|
1102 |
return field->result_type(); |
|
1103 |
}
|
|
1104 |
Item_result cast_to_int_type() const |
|
1105 |
{
|
|
1106 |
return field->cast_to_int_type(); |
|
1107 |
}
|
|
1108 |
enum_field_types field_type() const |
|
1109 |
{
|
|
1110 |
return field->type(); |
|
1111 |
}
|
|
1112 |
enum_monotonicity_info get_monotonicity_info() const |
|
1113 |
{
|
|
1114 |
return MONOTONIC_STRICT_INCREASING; |
|
1115 |
}
|
|
1116 |
longlong val_int_endpoint(bool left_endp, bool *incl_endp); |
|
1117 |
Field *get_tmp_table_field() { return result_field; } |
|
1118 |
Field *tmp_table_field(TABLE *t_arg) { return result_field; } |
|
1119 |
bool get_date(MYSQL_TIME *ltime,uint fuzzydate); |
|
1120 |
bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate); |
|
1121 |
bool get_time(MYSQL_TIME *ltime); |
|
1122 |
bool is_null() { return field->is_null(); } |
|
1123 |
void update_null_value(); |
|
1124 |
Item *get_tmp_table_item(THD *thd); |
|
1125 |
bool collect_item_field_processor(uchar * arg); |
|
1126 |
bool find_item_in_field_list_processor(uchar *arg); |
|
1127 |
bool register_field_in_read_map(uchar *arg); |
|
1128 |
void cleanup(); |
|
1129 |
bool result_as_longlong() |
|
1130 |
{
|
|
1131 |
return field->can_be_compared_as_longlong(); |
|
1132 |
}
|
|
1133 |
Item_equal *find_item_equal(COND_EQUAL *cond_equal); |
|
1134 |
bool subst_argument_checker(uchar **arg); |
|
1135 |
Item *equal_fields_propagator(uchar *arg); |
|
1136 |
bool set_no_const_sub(uchar *arg); |
|
1137 |
Item *replace_equal_field(uchar *arg); |
|
1138 |
inline uint32 max_disp_length() { return field->max_display_length(); } |
|
1139 |
Item_field *filed_for_view_update() { return this; } |
|
1140 |
Item *safe_charset_converter(CHARSET_INFO *tocs); |
|
1141 |
int fix_outer_field(THD *thd, Field **field, Item **reference); |
|
1142 |
virtual Item *update_value_transformer(uchar *select_arg); |
|
1143 |
virtual void print(String *str, enum_query_type query_type); |
|
1144 |
||
1145 |
#ifndef DBUG_OFF
|
|
1146 |
void dbug_print() |
|
1147 |
{
|
|
1148 |
fprintf(DBUG_FILE, "<field "); |
|
1149 |
if (field) |
|
1150 |
{
|
|
1151 |
fprintf(DBUG_FILE, "'%s.%s': ", field->table->alias, field->field_name); |
|
1152 |
field->dbug_print(); |
|
1153 |
}
|
|
1154 |
else
|
|
1155 |
fprintf(DBUG_FILE, "NULL"); |
|
1156 |
||
1157 |
fprintf(DBUG_FILE, ", result_field: "); |
|
1158 |
if (result_field) |
|
1159 |
{
|
|
1160 |
fprintf(DBUG_FILE, "'%s.%s': ", |
|
1161 |
result_field->table->alias, result_field->field_name); |
|
1162 |
result_field->dbug_print(); |
|
1163 |
}
|
|
1164 |
else
|
|
1165 |
fprintf(DBUG_FILE, "NULL"); |
|
1166 |
fprintf(DBUG_FILE, ">\n"); |
|
1167 |
}
|
|
1168 |
#endif
|
|
1169 |
||
1170 |
friend class Item_default_value; |
|
1171 |
friend class Item_insert_value; |
|
1172 |
friend class st_select_lex_unit; |
|
1173 |
};
|
|
1174 |
||
1175 |
class Item_null :public Item_basic_constant |
|
1176 |
{
|
|
1177 |
public: |
|
1178 |
Item_null(char *name_par=0) |
|
1179 |
{
|
|
1180 |
maybe_null= null_value= TRUE; |
|
1181 |
max_length= 0; |
|
1182 |
name= name_par ? name_par : (char*) "NULL"; |
|
1183 |
fixed= 1; |
|
1184 |
collation.set(&my_charset_bin, DERIVATION_IGNORABLE); |
|
1185 |
}
|
|
1186 |
enum Type type() const { return NULL_ITEM; } |
|
1187 |
bool eq(const Item *item, bool binary_cmp) const; |
|
1188 |
double val_real(); |
|
1189 |
longlong val_int(); |
|
1190 |
String *val_str(String *str); |
|
1191 |
my_decimal *val_decimal(my_decimal *); |
|
1192 |
int save_in_field(Field *field, bool no_conversions); |
|
1193 |
int save_safe_in_field(Field *field); |
|
1194 |
bool send(Protocol *protocol, String *str); |
|
1195 |
enum Item_result result_type () const { return STRING_RESULT; } |
|
1196 |
enum_field_types field_type() const { return MYSQL_TYPE_NULL; } |
|
1197 |
bool basic_const_item() const { return 1; } |
|
1198 |
Item *clone_item() { return new Item_null(name); } |
|
1199 |
bool is_null() { return 1; } |
|
1200 |
||
1201 |
virtual inline void print(String *str, enum_query_type query_type) |
|
1202 |
{
|
|
1203 |
str->append(STRING_WITH_LEN("NULL")); |
|
1204 |
}
|
|
1205 |
||
1206 |
Item *safe_charset_converter(CHARSET_INFO *tocs); |
|
1207 |
};
|
|
1208 |
||
1209 |
class Item_null_result :public Item_null |
|
1210 |
{
|
|
1211 |
public: |
|
1212 |
Field *result_field; |
|
1213 |
Item_null_result() : Item_null(), result_field(0) {} |
|
1214 |
bool is_result_field() { return result_field != 0; } |
|
1215 |
void save_in_result_field(bool no_conversions) |
|
1216 |
{
|
|
1217 |
save_in_field(result_field, no_conversions); |
|
1218 |
}
|
|
1219 |
};
|
|
1220 |
||
1221 |
/* Item represents one placeholder ('?') of prepared statement */
|
|
1222 |
||
1223 |
class Item_param :public Item |
|
1224 |
{
|
|
1225 |
char cnvbuf[MAX_FIELD_WIDTH]; |
|
1226 |
String cnvstr; |
|
1227 |
Item *cnvitem; |
|
1228 |
||
1229 |
public: |
|
1230 |
enum enum_item_param_state |
|
1231 |
{
|
|
1232 |
NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE, |
|
1233 |
STRING_VALUE, TIME_VALUE, LONG_DATA_VALUE, |
|
1234 |
DECIMAL_VALUE
|
|
1235 |
} state; |
|
1236 |
||
1237 |
/*
|
|
1238 |
A buffer for string and long data values. Historically all allocated
|
|
1239 |
values returned from val_str() were treated as eligible to
|
|
1240 |
modification. I. e. in some cases Item_func_concat can append it's
|
|
1241 |
second argument to return value of the first one. Because of that we
|
|
1242 |
can't return the original buffer holding string data from val_str(),
|
|
1243 |
and have to have one buffer for data and another just pointing to
|
|
1244 |
the data. This is the latter one and it's returned from val_str().
|
|
1245 |
Can not be declared inside the union as it's not a POD type.
|
|
1246 |
*/
|
|
1247 |
String str_value_ptr; |
|
1248 |
my_decimal decimal_value; |
|
1249 |
union
|
|
1250 |
{
|
|
1251 |
longlong integer; |
|
1252 |
double real; |
|
1253 |
/*
|
|
1254 |
Character sets conversion info for string values.
|
|
1255 |
Character sets of client and connection defined at bind time are used
|
|
1256 |
for all conversions, even if one of them is later changed (i.e.
|
|
1257 |
between subsequent calls to mysql_stmt_execute).
|
|
1258 |
*/
|
|
1259 |
struct CONVERSION_INFO |
|
1260 |
{
|
|
1261 |
CHARSET_INFO *character_set_client; |
|
1262 |
CHARSET_INFO *character_set_of_placeholder; |
|
1263 |
/*
|
|
1264 |
This points at character set of connection if conversion
|
|
1265 |
to it is required (i. e. if placeholder typecode is not BLOB).
|
|
1266 |
Otherwise it's equal to character_set_client (to simplify
|
|
1267 |
check in convert_str_value()).
|
|
1268 |
*/
|
|
1269 |
CHARSET_INFO *final_character_set_of_str_value; |
|
1270 |
} cs_info; |
|
1271 |
MYSQL_TIME time; |
|
1272 |
} value; |
|
1273 |
||
1274 |
/* Cached values for virtual methods to save us one switch. */
|
|
1275 |
enum Item_result item_result_type; |
|
1276 |
enum Type item_type; |
|
1277 |
||
1278 |
/*
|
|
1279 |
Used when this item is used in a temporary table.
|
|
1280 |
This is NOT placeholder metadata sent to client, as this value
|
|
1281 |
is assigned after sending metadata (in setup_one_conversion_function).
|
|
1282 |
For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both
|
|
1283 |
in result set and placeholders metadata, no matter what type you will
|
|
1284 |
supply for this placeholder in mysql_stmt_execute.
|
|
1285 |
*/
|
|
1286 |
enum enum_field_types param_type; |
|
1287 |
/*
|
|
1288 |
Offset of placeholder inside statement text. Used to create
|
|
1289 |
no-placeholders version of this statement for the binary log.
|
|
1290 |
*/
|
|
1291 |
uint pos_in_query; |
|
1292 |
||
1293 |
Item_param(uint pos_in_query_arg); |
|
1294 |
||
1295 |
enum Item_result result_type () const { return item_result_type; } |
|
1296 |
enum Type type() const { return item_type; } |
|
1297 |
enum_field_types field_type() const { return param_type; } |
|
1298 |
||
1299 |
double val_real(); |
|
1300 |
longlong val_int(); |
|
1301 |
my_decimal *val_decimal(my_decimal*); |
|
1302 |
String *val_str(String*); |
|
1303 |
bool get_time(MYSQL_TIME *tm); |
|
1304 |
bool get_date(MYSQL_TIME *tm, uint fuzzydate); |
|
1305 |
int save_in_field(Field *field, bool no_conversions); |
|
1306 |
||
1307 |
void set_null(); |
|
1308 |
void set_int(longlong i, uint32 max_length_arg); |
|
1309 |
void set_double(double i); |
|
1310 |
void set_decimal(const char *str, ulong length); |
|
1311 |
bool set_str(const char *str, ulong length); |
|
1312 |
bool set_longdata(const char *str, ulong length); |
|
1313 |
void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg); |
|
1314 |
bool set_from_user_var(THD *thd, const user_var_entry *entry); |
|
1315 |
void reset(); |
|
1316 |
/*
|
|
1317 |
Assign placeholder value from bind data.
|
|
1318 |
Note, that 'len' has different semantics in embedded library (as we
|
|
1319 |
don't need to check that packet is not broken there). See
|
|
1320 |
sql_prepare.cc for details.
|
|
1321 |
*/
|
|
1322 |
void (*set_param_func)(Item_param *param, uchar **pos, ulong len); |
|
1323 |
||
1324 |
const String *query_val_str(String *str) const; |
|
1325 |
||
1326 |
bool convert_str_value(THD *thd); |
|
1327 |
||
1328 |
/*
|
|
1329 |
If value for parameter was not set we treat it as non-const
|
|
1330 |
so noone will use parameters value in fix_fields still
|
|
1331 |
parameter is constant during execution.
|
|
1332 |
*/
|
|
1333 |
virtual table_map used_tables() const |
|
1334 |
{ return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; } |
|
1335 |
virtual void print(String *str, enum_query_type query_type); |
|
1336 |
bool is_null() |
|
1337 |
{ DBUG_ASSERT(state != NO_VALUE); return state == NULL_VALUE; } |
|
1338 |
bool basic_const_item() const; |
|
1339 |
/*
|
|
1340 |
This method is used to make a copy of a basic constant item when
|
|
1341 |
propagating constants in the optimizer. The reason to create a new
|
|
1342 |
item and not use the existing one is not precisely known (2005/04/16).
|
|
1343 |
Probably we are trying to preserve tree structure of items, in other
|
|
1344 |
words, avoid pointing at one item from two different nodes of the tree.
|
|
1345 |
Return a new basic constant item if parameter value is a basic
|
|
1346 |
constant, assert otherwise. This method is called only if
|
|
1347 |
basic_const_item returned TRUE.
|
|
1348 |
*/
|
|
1349 |
Item *safe_charset_converter(CHARSET_INFO *tocs); |
|
1350 |
Item *clone_item(); |
|
1351 |
/*
|
|
1352 |
Implement by-value equality evaluation if parameter value
|
|
1353 |
is set and is a basic constant (integer, real or string).
|
|
1354 |
Otherwise return FALSE.
|
|
1355 |
*/
|
|
1356 |
bool eq(const Item *item, bool binary_cmp) const; |
|
1357 |
/** Item is a argument to a limit clause. */
|
|
1358 |
bool limit_clause_param; |
|
1359 |
};
|
|
1360 |
||
1361 |
||
1362 |
class Item_int :public Item_num |
|
1363 |
{
|
|
1364 |
public: |
|
1365 |
longlong value; |
|
1366 |
Item_int(int32 i,uint length= MY_INT32_NUM_DECIMAL_DIGITS) |
|
1367 |
:value((longlong) i) |
|
1368 |
{ max_length=length; fixed= 1; } |
|
1369 |
Item_int(longlong i,uint length= MY_INT64_NUM_DECIMAL_DIGITS) |
|
1370 |
:value(i) |
|
1371 |
{ max_length=length; fixed= 1; } |
|
1372 |
Item_int(ulonglong i, uint length= MY_INT64_NUM_DECIMAL_DIGITS) |
|
1373 |
:value((longlong)i) |
|
1374 |
{ max_length=length; fixed= 1; unsigned_flag= 1; } |
|
1375 |
Item_int(const char *str_arg,longlong i,uint length) :value(i) |
|
1376 |
{ max_length=length; name=(char*) str_arg; fixed= 1; } |
|
1377 |
Item_int(const char *str_arg, uint length=64); |
|
1378 |
enum Type type() const { return INT_ITEM; } |
|
1379 |
enum Item_result result_type () const { return INT_RESULT; } |
|
1380 |
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; } |
|
1381 |
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; } |
|
1382 |
double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; } |
|
1383 |
my_decimal *val_decimal(my_decimal *); |
|
1384 |
String *val_str(String*); |
|
1385 |
int save_in_field(Field *field, bool no_conversions); |
|
1386 |
bool basic_const_item() const { return 1; } |
|
1387 |
Item *clone_item() { return new Item_int(name,value,max_length); } |
|
1388 |
virtual void print(String *str, enum_query_type query_type); |
|
1389 |
Item_num *neg() { value= -value; return this; } |
|
1390 |
uint decimal_precision() const |
|
1391 |
{ return (uint)(max_length - test(value < 0)); } |
|
1392 |
bool eq(const Item *, bool binary_cmp) const; |
|
1393 |
};
|
|
1394 |
||
1395 |
||
1396 |
class Item_uint :public Item_int |
|
1397 |
{
|
|
1398 |
public: |
|
1399 |
Item_uint(const char *str_arg, uint length); |
|
1400 |
Item_uint(ulonglong i) :Item_int((ulonglong) i, 10) {} |
|
1401 |
Item_uint(const char *str_arg, longlong i, uint length); |
|
1402 |
double val_real() |
|
1403 |
{ DBUG_ASSERT(fixed == 1); return ulonglong2double((ulonglong)value); } |
|
1404 |
String *val_str(String*); |
|
1405 |
Item *clone_item() { return new Item_uint(name, value, max_length); } |
|
1406 |
int save_in_field(Field *field, bool no_conversions); |
|
1407 |
virtual void print(String *str, enum_query_type query_type); |
|
1408 |
Item_num *neg (); |
|
1409 |
uint decimal_precision() const { return max_length; } |
|
1410 |
};
|
|
1411 |
||
1412 |
||
1413 |
/* decimal (fixed point) constant */
|
|
1414 |
class Item_decimal :public Item_num |
|
1415 |
{
|
|
1416 |
protected: |
|
1417 |
my_decimal decimal_value; |
|
1418 |
public: |
|
1419 |
Item_decimal(const char *str_arg, uint length, CHARSET_INFO *charset); |
|
1420 |
Item_decimal(const char *str, const my_decimal *val_arg, |
|
1421 |
uint decimal_par, uint length); |
|
1422 |
Item_decimal(my_decimal *value_par); |
|
1423 |
Item_decimal(longlong val, bool unsig); |
|
1424 |
Item_decimal(double val, int precision, int scale); |
|
1425 |
Item_decimal(const uchar *bin, int precision, int scale); |
|
1426 |
||
1427 |
enum Type type() const { return DECIMAL_ITEM; } |
|
1428 |
enum Item_result result_type () const { return DECIMAL_RESULT; } |
|
1429 |
enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; } |
|
1430 |
longlong val_int(); |
|
1431 |
double val_real(); |
|
1432 |
String *val_str(String*); |
|
1433 |
my_decimal *val_decimal(my_decimal *val) { return &decimal_value; } |
|
1434 |
int save_in_field(Field *field, bool no_conversions); |
|
1435 |
bool basic_const_item() const { return 1; } |
|
1436 |
Item *clone_item() |
|
1437 |
{
|
|
1438 |
return new Item_decimal(name, &decimal_value, decimals, max_length); |
|
1439 |
}
|
|
1440 |
virtual void print(String *str, enum_query_type query_type); |
|
1441 |
Item_num *neg() |
|
1442 |
{
|
|
1443 |
my_decimal_neg(&decimal_value); |
|
1444 |
unsigned_flag= !decimal_value.sign(); |
|
1445 |
return this; |
|
1446 |
}
|
|
1447 |
uint decimal_precision() const { return decimal_value.precision(); } |
|
1448 |
bool eq(const Item *, bool binary_cmp) const; |
|
1449 |
void set_decimal_value(my_decimal *value_par); |
|
1450 |
};
|
|
1451 |
||
1452 |
||
1453 |
class Item_float :public Item_num |
|
1454 |
{
|
|
1455 |
char *presentation; |
|
1456 |
public: |
|
1457 |
double value; |
|
1458 |
// Item_real() :value(0) {}
|
|
1459 |
Item_float(const char *str_arg, uint length); |
|
1460 |
Item_float(const char *str,double val_arg,uint decimal_par,uint length) |
|
1461 |
:value(val_arg) |
|
1462 |
{
|
|
1463 |
presentation= name=(char*) str; |
|
1464 |
decimals=(uint8) decimal_par; |
|
1465 |
max_length=length; |
|
1466 |
fixed= 1; |
|
1467 |
}
|
|
1468 |
Item_float(double value_par, uint decimal_par) :presentation(0), value(value_par) |
|
1469 |
{
|
|
1470 |
decimals= (uint8) decimal_par; |
|
1471 |
fixed= 1; |
|
1472 |
}
|
|
1473 |
int save_in_field(Field *field, bool no_conversions); |
|
1474 |
enum Type type() const { return REAL_ITEM; } |
|
1475 |
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; } |
|
1476 |
double val_real() { DBUG_ASSERT(fixed == 1); return value; } |
|
1477 |
longlong val_int() |
|
1478 |
{
|
|
1479 |
DBUG_ASSERT(fixed == 1); |
|
1480 |
if (value <= (double) LONGLONG_MIN) |
|
1481 |
{
|
|
1482 |
return LONGLONG_MIN; |
|
1483 |
}
|
|
1484 |
else if (value >= (double) (ulonglong) LONGLONG_MAX) |
|
1485 |
{
|
|
1486 |
return LONGLONG_MAX; |
|
1487 |
}
|
|
1488 |
return (longlong) rint(value); |
|
1489 |
}
|
|
1490 |
String *val_str(String*); |
|
1491 |
my_decimal *val_decimal(my_decimal *); |
|
1492 |
bool basic_const_item() const { return 1; } |
|
1493 |
Item *clone_item() |
|
1494 |
{ return new Item_float(name, value, decimals, max_length); } |
|
1495 |
Item_num *neg() { value= -value; return this; } |
|
1496 |
virtual void print(String *str, enum_query_type query_type); |
|
1497 |
bool eq(const Item *, bool binary_cmp) const; |
|
1498 |
};
|
|
1499 |
||
1500 |
||
1501 |
class Item_static_float_func :public Item_float |
|
1502 |
{
|
|
1503 |
const char *func_name; |
|
1504 |
public: |
|
1505 |
Item_static_float_func(const char *str, double val_arg, uint decimal_par, |
|
1506 |
uint length) |
|
1507 |
:Item_float(NullS, val_arg, decimal_par, length), func_name(str) |
|
1508 |
{}
|
|
1509 |
||
1510 |
virtual inline void print(String *str, enum_query_type query_type) |
|
1511 |
{
|
|
1512 |
str->append(func_name); |
|
1513 |
}
|
|
1514 |
||
1515 |
Item *safe_charset_converter(CHARSET_INFO *tocs); |
|
1516 |
};
|
|
1517 |
||
1518 |
||
1519 |
class Item_string :public Item_basic_constant |
|
1520 |
{
|
|
1521 |
public: |
|
1522 |
Item_string(const char *str,uint length, |
|
1523 |
CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE, |
|
1524 |
uint repertoire= MY_REPERTOIRE_UNICODE30) |
|
1525 |
: m_cs_specified(FALSE) |
|
1526 |
{
|
|
1527 |
str_value.set_or_copy_aligned(str, length, cs); |
|
1528 |
collation.set(cs, dv, repertoire); |
|
1529 |
/*
|
|
1530 |
We have to have a different max_length than 'length' here to
|
|
1531 |
ensure that we get the right length if we do use the item
|
|
1532 |
to create a new table. In this case max_length must be the maximum
|
|
1533 |
number of chars for a string of this type because we in Create_field::
|
|
1534 |
divide the max_length with mbmaxlen).
|
|
1535 |
*/
|
|
1536 |
max_length= str_value.numchars()*cs->mbmaxlen; |
|
1537 |
set_name(str, length, cs); |
|
1538 |
decimals=NOT_FIXED_DEC; |
|
1539 |
// it is constant => can be used without fix_fields (and frequently used)
|
|
1540 |
fixed= 1; |
|
1541 |
}
|
|
1542 |
/* Just create an item and do not fill string representation */
|
|
1543 |
Item_string(CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE) |
|
1544 |
: m_cs_specified(FALSE) |
|
1545 |
{
|
|
1546 |
collation.set(cs, dv); |
|
1547 |
max_length= 0; |
|
1548 |
set_name(NULL, 0, cs); |
|
1549 |
decimals= NOT_FIXED_DEC; |
|
1550 |
fixed= 1; |
|
1551 |
}
|
|
1552 |
Item_string(const char *name_par, const char *str, uint length, |
|
1553 |
CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE, |
|
1554 |
uint repertoire= MY_REPERTOIRE_UNICODE30) |
|
1555 |
: m_cs_specified(FALSE) |
|
1556 |
{
|
|
1557 |
str_value.set_or_copy_aligned(str, length, cs); |
|
1558 |
collation.set(cs, dv, repertoire); |
|
1559 |
max_length= str_value.numchars()*cs->mbmaxlen; |
|
1560 |
set_name(name_par, 0, cs); |
|
1561 |
decimals=NOT_FIXED_DEC; |
|
1562 |
// it is constant => can be used without fix_fields (and frequently used)
|
|
1563 |
fixed= 1; |
|
1564 |
}
|
|
1565 |
/*
|
|
1566 |
This is used in stored procedures to avoid memory leaks and
|
|
1567 |
does a deep copy of its argument.
|
|
1568 |
*/
|
|
1569 |
void set_str_with_copy(const char *str_arg, uint length_arg) |
|
1570 |
{
|
|
1571 |
str_value.copy(str_arg, length_arg, collation.collation); |
|
1572 |
max_length= str_value.numchars() * collation.collation->mbmaxlen; |
|
1573 |
}
|
|
1574 |
void set_repertoire_from_value() |
|
1575 |
{
|
|
1576 |
collation.repertoire= my_string_repertoire(str_value.charset(), |
|
1577 |
str_value.ptr(), |
|
1578 |
str_value.length()); |
|
1579 |
}
|
|
1580 |
enum Type type() const { return STRING_ITEM; } |
|
1581 |
double val_real(); |
|
1582 |
longlong val_int(); |
|
1583 |
String *val_str(String*) |
|
1584 |
{
|
|
1585 |
DBUG_ASSERT(fixed == 1); |
|
1586 |
return (String*) &str_value; |
|
1587 |
}
|
|
1588 |
my_decimal *val_decimal(my_decimal *); |
|
1589 |
int save_in_field(Field *field, bool no_conversions); |
|
1590 |
enum Item_result result_type () const { return STRING_RESULT; } |
|
1591 |
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; } |
|
1592 |
bool basic_const_item() const { return 1; } |
|
1593 |
bool eq(const Item *item, bool binary_cmp) const; |
|
1594 |
Item *clone_item() |
|
1595 |
{
|
|
1596 |
return new Item_string(name, str_value.ptr(), |
|
1597 |
str_value.length(), collation.collation); |
|
1598 |
}
|
|
1599 |
Item *safe_charset_converter(CHARSET_INFO *tocs); |
|
1600 |
inline void append(char *str, uint length) |
|
1601 |
{
|
|
1602 |
str_value.append(str, length); |
|
1603 |
max_length= str_value.numchars() * collation.collation->mbmaxlen; |
|
1604 |
}
|
|
1605 |
virtual void print(String *str, enum_query_type query_type); |
|
1606 |
||
1607 |
/**
|
|
1608 |
Return TRUE if character-set-introducer was explicitly specified in the
|
|
1609 |
original query for this item (text literal).
|
|
1610 |
||
1611 |
This operation is to be called from Item_string::print(). The idea is
|
|
1612 |
that when a query is generated (re-constructed) from the Item-tree,
|
|
1613 |
character-set-introducers should appear only for those literals, where
|
|
1614 |
they were explicitly specified by the user. Otherwise, that may lead to
|
|
1615 |
loss collation information (character set introducers implies default
|
|
1616 |
collation for the literal).
|
|
1617 |
||
1618 |
Basically, that makes sense only for views and hopefully will be gone
|
|
1619 |
one day when we start using original query as a view definition.
|
|
1620 |
||
1621 |
@return This operation returns the value of m_cs_specified attribute.
|
|
1622 |
@retval TRUE if character set introducer was explicitly specified in
|
|
1623 |
the original query.
|
|
1624 |
@retval FALSE otherwise.
|
|
1625 |
*/
|
|
1626 |
inline bool is_cs_specified() const |
|
1627 |
{
|
|
1628 |
return m_cs_specified; |
|
1629 |
}
|
|
1630 |
||
1631 |
/**
|
|
1632 |
Set the value of m_cs_specified attribute.
|
|
1633 |
||
1634 |
m_cs_specified attribute shows whether character-set-introducer was
|
|
1635 |
explicitly specified in the original query for this text literal or
|
|
1636 |
not. The attribute makes sense (is used) only for views.
|
|
1637 |
||
1638 |
This operation is to be called from the parser during parsing an input
|
|
1639 |
query.
|
|
1640 |
*/
|
|
1641 |
inline void set_cs_specified(bool cs_specified) |
|
1642 |
{
|
|
1643 |
m_cs_specified= cs_specified; |
|
1644 |
}
|
|
1645 |
||
1646 |
private: |
|
1647 |
bool m_cs_specified; |
|
1648 |
};
|
|
1649 |
||
1650 |
||
1651 |
class Item_static_string_func :public Item_string |
|
1652 |
{
|
|
1653 |
const char *func_name; |
|
1654 |
public: |
|
1655 |
Item_static_string_func(const char *name_par, const char *str, uint length, |
|
1656 |
CHARSET_INFO *cs, |
|
1657 |
Derivation dv= DERIVATION_COERCIBLE) |
|
1658 |
:Item_string(NullS, str, length, cs, dv), func_name(name_par) |
|
1659 |
{}
|
|
1660 |
Item *safe_charset_converter(CHARSET_INFO *tocs); |
|
1661 |
||
1662 |
virtual inline void print(String *str, enum_query_type query_type) |
|
1663 |
{
|
|
1664 |
str->append(func_name); |
|
1665 |
}
|
|
1666 |
};
|
|
1667 |
||
1668 |
||
1669 |
/* for show tables */
|
|
1670 |
class Item_return_date_time :public Item_string |
|
1671 |
{
|
|
1672 |
enum_field_types date_time_field_type; |
|
1673 |
public: |
|
1674 |
Item_return_date_time(const char *name_arg, enum_field_types field_type_arg) |
|
1675 |
:Item_string(name_arg, 0, &my_charset_bin), |
|
1676 |
date_time_field_type(field_type_arg) |
|
1677 |
{ } |
|
1678 |
enum_field_types field_type() const { return date_time_field_type; } |
|
1679 |
};
|
|
1680 |
||
1681 |
||
1682 |
class Item_blob :public Item_string |
|
1683 |
{
|
|
1684 |
public: |
|
1685 |
Item_blob(const char *name, uint length) : |
|
1686 |
Item_string(name, length, &my_charset_bin) |
|
1687 |
{ max_length= length; } |
|
1688 |
enum Type type() const { return TYPE_HOLDER; } |
|
1689 |
enum_field_types field_type() const { return MYSQL_TYPE_BLOB; } |
|
1690 |
};
|
|
1691 |
||
1692 |
||
1693 |
/**
|
|
1694 |
Item_empty_string -- is a utility class to put an item into List<Item>
|
|
1695 |
which is then used in protocol.send_fields() when sending SHOW output to
|
|
1696 |
the client.
|
|
1697 |
*/
|
|
1698 |
||
1699 |
class Item_empty_string :public Item_string |
|
1700 |
{
|
|
1701 |
public: |
|
1702 |
Item_empty_string(const char *header,uint length, CHARSET_INFO *cs= NULL) : |
|
1703 |
Item_string("",0, cs ? cs : &my_charset_utf8_general_ci) |
|
1704 |
{ name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; } |
|
1705 |
void make_field(Send_field *field); |
|
1706 |
};
|
|
1707 |
||
1708 |
||
1709 |
class Item_return_int :public Item_int |
|
1710 |
{
|
|
1711 |
enum_field_types int_field_type; |
|
1712 |
public: |
|
1713 |
Item_return_int(const char *name_arg, uint length, |
|
1714 |
enum_field_types field_type_arg, longlong value= 0) |
|
1715 |
:Item_int(name_arg, value, length), int_field_type(field_type_arg) |
|
1716 |
{
|
|
1717 |
unsigned_flag=1; |
|
1718 |
}
|
|
1719 |
enum_field_types field_type() const { return int_field_type; } |
|
1720 |
};
|
|
1721 |
||
1722 |
||
1723 |
class Item_hex_string: public Item_basic_constant |
|
1724 |
{
|
|
1725 |
public: |
|
1726 |
Item_hex_string() {} |
|
1727 |
Item_hex_string(const char *str,uint str_length); |
|
1728 |
enum Type type() const { return VARBIN_ITEM; } |
|
1729 |
double val_real() |
|
1730 |
{
|
|
1731 |
DBUG_ASSERT(fixed == 1); |
|
1732 |
return (double) (ulonglong) Item_hex_string::val_int(); |
|
1733 |
}
|
|
1734 |
longlong val_int(); |
|
1735 |
bool basic_const_item() const { return 1; } |
|
1736 |
String *val_str(String*) { DBUG_ASSERT(fixed == 1); return &str_value; } |
|
1737 |
my_decimal *val_decimal(my_decimal *); |
|
1738 |
int save_in_field(Field *field, bool no_conversions); |
|
1739 |
enum Item_result result_type () const { return STRING_RESULT; } |
|
1740 |
enum Item_result cast_to_int_type() const { return INT_RESULT; } |
|
1741 |
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; } |
|
1742 |
virtual void print(String *str, enum_query_type query_type); |
|
1743 |
bool eq(const Item *item, bool binary_cmp) const; |
|
1744 |
virtual Item *safe_charset_converter(CHARSET_INFO *tocs); |
|
1745 |
};
|
|
1746 |
||
1747 |
||
1748 |
class Item_bin_string: public Item_hex_string |
|
1749 |
{
|
|
1750 |
public: |
|
1751 |
Item_bin_string(const char *str,uint str_length); |
|
1752 |
};
|
|
1753 |
||
1754 |
class Item_result_field :public Item /* Item with result field */ |
|
1755 |
{
|
|
1756 |
public: |
|
1757 |
Field *result_field; /* Save result here */ |
|
1758 |
Item_result_field() :result_field(0) {} |
|
1759 |
// Constructor used for Item_sum/Item_cond_and/or (see Item comment)
|
|
1760 |
Item_result_field(THD *thd, Item_result_field *item): |
|
1761 |
Item(thd, item), result_field(item->result_field) |
|
1762 |
{}
|
|
1763 |
~Item_result_field() {} /* Required with gcc 2.95 */ |
|
1764 |
Field *get_tmp_table_field() { return result_field; } |
|
1765 |
Field *tmp_table_field(TABLE *t_arg) { return result_field; } |
|
1766 |
table_map used_tables() const { return 1; } |
|
1767 |
virtual void fix_length_and_dec()=0; |
|
1768 |
void set_result_field(Field *field) { result_field= field; } |
|
1769 |
bool is_result_field() { return 1; } |
|
1770 |
void save_in_result_field(bool no_conversions) |
|
1771 |
{
|
|
1772 |
save_in_field(result_field, no_conversions); |
|
1773 |
}
|
|
1774 |
void cleanup(); |
|
1775 |
};
|
|
1776 |
||
1777 |
||
1778 |
class Item_ref :public Item_ident |
|
1779 |
{
|
|
1780 |
protected: |
|
1781 |
void set_properties(); |
|
1782 |
public: |
|
1783 |
enum Ref_Type { REF, DIRECT_REF, VIEW_REF, OUTER_REF }; |
|
1784 |
Field *result_field; /* Save result here */ |
|
1785 |
Item **ref; |
|
1786 |
Item_ref(Name_resolution_context *context_arg, |
|
1787 |
const char *db_arg, const char *table_name_arg, |
|
1788 |
const char *field_name_arg) |
|
1789 |
:Item_ident(context_arg, db_arg, table_name_arg, field_name_arg), |
|
1790 |
result_field(0), ref(0) {} |
|
1791 |
/*
|
|
1792 |
This constructor is used in two scenarios:
|
|
1793 |
A) *item = NULL
|
|
1794 |
No initialization is performed, fix_fields() call will be necessary.
|
|
1795 |
|
|
1796 |
B) *item points to an Item this Item_ref will refer to. This is
|
|
1797 |
used for GROUP BY. fix_fields() will not be called in this case,
|
|
1798 |
so we call set_properties to make this item "fixed". set_properties
|
|
1799 |
performs a subset of action Item_ref::fix_fields does, and this subset
|
|
1800 |
is enough for Item_ref's used in GROUP BY.
|
|
1801 |
|
|
1802 |
TODO we probably fix a superset of problems like in BUG#6658. Check this
|
|
1803 |
with Bar, and if we have a more broader set of problems like this.
|
|
1804 |
*/
|
|
1805 |
Item_ref(Name_resolution_context *context_arg, Item **item, |
|
1806 |
const char *table_name_arg, const char *field_name_arg, |
|
1807 |
bool alias_name_used_arg= FALSE); |
|
1808 |
||
1809 |
/* Constructor need to process subselect with temporary tables (see Item) */
|
|
1810 |
Item_ref(THD *thd, Item_ref *item) |
|
1811 |
:Item_ident(thd, item), result_field(item->result_field), ref(item->ref) {} |
|
1812 |
enum Type type() const { return REF_ITEM; } |
|
1813 |
bool eq(const Item *item, bool binary_cmp) const |
|
1814 |
{
|
|
1815 |
Item *it= ((Item *) item)->real_item(); |
|
1816 |
return ref && (*ref)->eq(it, binary_cmp); |
|
1817 |
}
|
|
1818 |
double val_real(); |
|
1819 |
longlong val_int(); |
|
1820 |
my_decimal *val_decimal(my_decimal *); |
|
1821 |
bool val_bool(); |
|
1822 |
String *val_str(String* tmp); |
|
1823 |
bool is_null(); |
|
1824 |
bool get_date(MYSQL_TIME *ltime,uint fuzzydate); |
|
1825 |
double val_result(); |
|
1826 |
longlong val_int_result(); |
|
1827 |
String *str_result(String* tmp); |
|
1828 |
my_decimal *val_decimal_result(my_decimal *); |
|
1829 |
bool val_bool_result(); |
|
1830 |
bool send(Protocol *prot, String *tmp); |
|
1831 |
void make_field(Send_field *field); |
|
1832 |
bool fix_fields(THD *, Item **); |
|
1833 |
void fix_after_pullout(st_select_lex *new_parent, Item **ref); |
|
1834 |
int save_in_field(Field *field, bool no_conversions); |
|
1835 |
void save_org_in_field(Field *field); |
|
1836 |
enum Item_result result_type () const { return (*ref)->result_type(); } |
|
1837 |
enum_field_types field_type() const { return (*ref)->field_type(); } |
|
1838 |
Field *get_tmp_table_field() |
|
1839 |
{ return result_field ? result_field : (*ref)->get_tmp_table_field(); } |
|
1840 |
Item *get_tmp_table_item(THD *thd); |
|
1841 |
table_map used_tables() const |
|
1842 |
{
|
|
1843 |
return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables(); |
|
1844 |
}
|
|
1845 |
void update_used_tables() |
|
1846 |
{
|
|
1847 |
if (!depended_from) |
|
1848 |
(*ref)->update_used_tables(); |
|
1849 |
}
|
|
1850 |
table_map not_null_tables() const { return (*ref)->not_null_tables(); } |
|
1851 |
void set_result_field(Field *field) { result_field= field; } |
|
1852 |
bool is_result_field() { return 1; } |
|
1853 |
void save_in_result_field(bool no_conversions) |
|
1854 |
{
|
|
1855 |
(*ref)->save_in_field(result_field, no_conversions); |
|
1856 |
}
|
|
1857 |
Item *real_item() |
|
1858 |
{
|
|
1859 |
return ref ? (*ref)->real_item() : this; |
|
1860 |
}
|
|
1861 |
bool walk(Item_processor processor, bool walk_subquery, uchar *arg) |
|
1862 |
{ return (*ref)->walk(processor, walk_subquery, arg); } |
|
1863 |
virtual void print(String *str, enum_query_type query_type); |
|
1864 |
bool result_as_longlong() |
|
1865 |
{
|
|
1866 |
return (*ref)->result_as_longlong(); |
|
1867 |
}
|
|
1868 |
void cleanup(); |
|
1869 |
Item_field *filed_for_view_update() |
|
1870 |
{ return (*ref)->filed_for_view_update(); } |
|
1871 |
virtual Ref_Type ref_type() { return REF; } |
|
1872 |
||
1873 |
// Row emulation: forwarding of ROW-related calls to ref
|
|
1874 |
uint cols() |
|
1875 |
{
|
|
1876 |
return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1; |
|
1877 |
}
|
|
1878 |
Item* element_index(uint i) |
|
1879 |
{
|
|
1880 |
return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this; |
|
1881 |
}
|
|
1882 |
Item** addr(uint i) |
|
1883 |
{
|
|
1884 |
return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0; |
|
1885 |
}
|
|
1886 |
bool check_cols(uint c) |
|
1887 |
{
|
|
1888 |
return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c) |
|
1889 |
: Item::check_cols(c); |
|
1890 |
}
|
|
1891 |
bool null_inside() |
|
1892 |
{
|
|
1893 |
return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0; |
|
1894 |
}
|
|
1895 |
void bring_value() |
|
1896 |
{
|
|
1897 |
if (ref && result_type() == ROW_RESULT) |
|
1898 |
(*ref)->bring_value(); |
|
1899 |
}
|
|
1900 |
||
1901 |
};
|
|
1902 |
||
1903 |
||
1904 |
/*
|
|
1905 |
The same as Item_ref, but get value from val_* family of method to get
|
|
1906 |
value of item on which it referred instead of result* family.
|
|
1907 |
*/
|
|
1908 |
class Item_direct_ref :public Item_ref |
|
1909 |
{
|
|
1910 |
public: |
|
1911 |
Item_direct_ref(Name_resolution_context *context_arg, Item **item, |
|
1912 |
const char *table_name_arg, |
|
1913 |
const char *field_name_arg, |
|
1914 |
bool alias_name_used_arg= FALSE) |
|
1915 |
:Item_ref(context_arg, item, table_name_arg, |
|
1916 |
field_name_arg, alias_name_used_arg) |
|
1917 |
{}
|
|
1918 |
/* Constructor need to process subselect with temporary tables (see Item) */
|
|
1919 |
Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {} |
|
1920 |
||
1921 |
double val_real(); |
|
1922 |
longlong val_int(); |
|
1923 |
String *val_str(String* tmp); |
|
1924 |
my_decimal *val_decimal(my_decimal *); |
|
1925 |
bool val_bool(); |
|
1926 |
bool is_null(); |
|
1927 |
bool get_date(MYSQL_TIME *ltime,uint fuzzydate); |
|
1928 |
virtual Ref_Type ref_type() { return DIRECT_REF; } |
|
1929 |
};
|
|
1930 |
||
1931 |
/*
|
|
1932 |
Class for view fields, the same as Item_direct_ref, but call fix_fields
|
|
1933 |
of reference if it is not called yet
|
|
1934 |
*/
|
|
1935 |
class Item_direct_view_ref :public Item_direct_ref |
|
1936 |
{
|
|
1937 |
public: |
|
1938 |
Item_direct_view_ref(Name_resolution_context *context_arg, Item **item, |
|
1939 |
const char *table_name_arg, |
|
1940 |
const char *field_name_arg) |
|
1941 |
:Item_direct_ref(context_arg, item, table_name_arg, field_name_arg) {} |
|
1942 |
/* Constructor need to process subselect with temporary tables (see Item) */
|
|
1943 |
Item_direct_view_ref(THD *thd, Item_direct_ref *item) |
|
1944 |
:Item_direct_ref(thd, item) {} |
|
1945 |
||
1946 |
bool fix_fields(THD *, Item **); |
|
1947 |
bool eq(const Item *item, bool binary_cmp) const; |
|
1948 |
Item *get_tmp_table_item(THD *thd) |
|
1949 |
{
|
|
1950 |
Item *item= Item_ref::get_tmp_table_item(thd); |
|
1951 |
item->name= name; |
|
1952 |
return item; |
|
1953 |
}
|
|
1954 |
virtual Ref_Type ref_type() { return VIEW_REF; } |
|
1955 |
};
|
|
1956 |
||
1957 |
||
1958 |
/*
|
|
1959 |
Class for outer fields.
|
|
1960 |
An object of this class is created when the select where the outer field was
|
|
1961 |
resolved is a grouping one. After it has been fixed the ref field will point
|
|
1962 |
to either an Item_ref or an Item_direct_ref object which will be used to
|
|
1963 |
access the field.
|
|
1964 |
See also comments for the fix_inner_refs() and the
|
|
1965 |
Item_field::fix_outer_field() functions.
|
|
1966 |
*/
|
|
1967 |
||
1968 |
class Item_sum; |
|
1969 |
class Item_outer_ref :public Item_direct_ref |
|
1970 |
{
|
|
1971 |
public: |
|
1972 |
Item *outer_ref; |
|
1973 |
/* The aggregate function under which this outer ref is used, if any. */
|
|
1974 |
Item_sum *in_sum_func; |
|
1975 |
/*
|
|
1976 |
TRUE <=> that the outer_ref is already present in the select list
|
|
1977 |
of the outer select.
|
|
1978 |
*/
|
|
1979 |
bool found_in_select_list; |
|
1980 |
Item_outer_ref(Name_resolution_context *context_arg, |
|
1981 |
Item_field *outer_field_arg) |
|
1982 |
:Item_direct_ref(context_arg, 0, outer_field_arg->table_name, |
|
1983 |
outer_field_arg->field_name), |
|
1984 |
outer_ref(outer_field_arg), in_sum_func(0), |
|
1985 |
found_in_select_list(0) |
|
1986 |
{
|
|
1987 |
ref= &outer_ref; |
|
1988 |
set_properties(); |
|
1989 |
fixed= 0; |
|
1990 |
}
|
|
1991 |
Item_outer_ref(Name_resolution_context *context_arg, Item **item, |
|
1992 |
const char *table_name_arg, const char *field_name_arg, |
|
1993 |
bool alias_name_used_arg) |
|
1994 |
:Item_direct_ref(context_arg, item, table_name_arg, field_name_arg, |
|
1995 |
alias_name_used_arg), |
|
1996 |
outer_ref(0), in_sum_func(0), found_in_select_list(1) |
|
1997 |
{}
|
|
1998 |
void save_in_result_field(bool no_conversions) |
|
1999 |
{
|
|
2000 |
outer_ref->save_org_in_field(result_field); |
|
2001 |
}
|
|
2002 |
bool fix_fields(THD *, Item **); |
|
2003 |
void fix_after_pullout(st_select_lex *new_parent, Item **ref); |
|
2004 |
table_map used_tables() const |
|
2005 |
{
|
|
2006 |
return (*ref)->const_item() ? 0 : OUTER_REF_TABLE_BIT; |
|
2007 |
}
|
|
2008 |
virtual Ref_Type ref_type() { return OUTER_REF; } |
|
2009 |
};
|
|
2010 |
||
2011 |
||
2012 |
class Item_in_subselect; |
|
2013 |
||
2014 |
||
2015 |
/*
|
|
2016 |
An object of this class:
|
|
2017 |
- Converts val_XXX() calls to ref->val_XXX_result() calls, like Item_ref.
|
|
2018 |
- Sets owner->was_null=TRUE if it has returned a NULL value from any
|
|
2019 |
val_XXX() function. This allows to inject an Item_ref_null_helper
|
|
2020 |
object into subquery and then check if the subquery has produced a row
|
|
2021 |
with NULL value.
|
|
2022 |
*/
|
|
2023 |
||
2024 |
class Item_ref_null_helper: public Item_ref |
|
2025 |
{
|
|
2026 |
protected: |
|
2027 |
Item_in_subselect* owner; |
|
2028 |
public: |
|
2029 |
Item_ref_null_helper(Name_resolution_context *context_arg, |
|
2030 |
Item_in_subselect* master, Item **item, |
|
2031 |
const char *table_name_arg, const char *field_name_arg) |
|
2032 |
:Item_ref(context_arg, item, table_name_arg, field_name_arg), |
|
2033 |
owner(master) {} |
|
2034 |
double val_real(); |
|
2035 |
longlong val_int(); |
|
2036 |
String* val_str(String* s); |
|
2037 |
my_decimal *val_decimal(my_decimal *); |
|
2038 |
bool val_bool(); |
|
2039 |
bool get_date(MYSQL_TIME *ltime, uint fuzzydate); |
|
2040 |
virtual void print(String *str, enum_query_type query_type); |
|
2041 |
/*
|
|
2042 |
we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
|
|
2043 |
*/
|
|
2044 |
table_map used_tables() const |
|
2045 |
{
|
|
2046 |
return (depended_from ? |
|
2047 |
OUTER_REF_TABLE_BIT : |
|
2048 |
(*ref)->used_tables() | RAND_TABLE_BIT); |
|
2049 |
}
|
|
2050 |
};
|
|
2051 |
||
2052 |
/*
|
|
2053 |
The following class is used to optimize comparing of date and bigint columns
|
|
2054 |
We need to save the original item ('ref') to be able to call
|
|
2055 |
ref->save_in_field(). This is used to create index search keys.
|
|
2056 |
|
|
2057 |
An instance of Item_int_with_ref may have signed or unsigned integer value.
|
|
2058 |
|
|
2059 |
*/
|
|
2060 |
||
2061 |
class Item_int_with_ref :public Item_int |
|
2062 |
{
|
|
2063 |
Item *ref; |
|
2064 |
public: |
|
2065 |
Item_int_with_ref(longlong i, Item *ref_arg, my_bool unsigned_arg) : |
|
2066 |
Item_int(i), ref(ref_arg) |
|
2067 |
{
|
|
2068 |
unsigned_flag= unsigned_arg; |
|
2069 |
}
|
|
2070 |
int save_in_field(Field *field, bool no_conversions) |
|
2071 |
{
|
|
2072 |
return ref->save_in_field(field, no_conversions); |
|
2073 |
}
|
|
2074 |
Item *clone_item(); |
|
2075 |
virtual Item *real_item() { return ref; } |
|
2076 |
};
|
|
2077 |
||
2078 |
#ifdef MYSQL_SERVER
|
|
2079 |
#include "item_sum.h" |
|
2080 |
#include "item_func.h" |
|
2081 |
#include "item_row.h" |
|
2082 |
#include "item_cmpfunc.h" |
|
2083 |
#include "item_strfunc.h" |
|
2084 |
#include "item_timefunc.h" |
|
2085 |
#include "item_subselect.h" |
|
2086 |
#endif
|
|
2087 |
||
2088 |
class Item_copy_string :public Item |
|
2089 |
{
|
|
2090 |
enum enum_field_types cached_field_type; |
|
2091 |
public: |
|
2092 |
Item *item; |
|
2093 |
Item_copy_string(Item *i) :item(i) |
|
2094 |
{
|
|
2095 |
null_value=maybe_null=item->maybe_null; |
|
2096 |
decimals=item->decimals; |
|
2097 |
max_length=item->max_length; |
|
2098 |
name=item->name; |
|
2099 |
cached_field_type= item->field_type(); |
|
2100 |
}
|
|
2101 |
enum Type type() const { return COPY_STR_ITEM; } |
|
2102 |
enum Item_result result_type () const { return STRING_RESULT; } |
|
2103 |
enum_field_types field_type() const { return cached_field_type; } |
|
2104 |
double val_real() |
|
2105 |
{
|
|
2106 |
int err_not_used; |
|
2107 |
char *end_not_used; |
|
2108 |
return (null_value ? 0.0 : |
|
2109 |
my_strntod(str_value.charset(), (char*) str_value.ptr(), |
|
2110 |
str_value.length(), &end_not_used, &err_not_used)); |
|
2111 |
}
|
|
2112 |
longlong val_int() |
|
2113 |
{
|
|
2114 |
int err; |
|
2115 |
return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(), |
|
2116 |
str_value.length(),10, (char**) 0, |
|
2117 |
&err); |
|
2118 |
}
|
|
2119 |
String *val_str(String*); |
|
2120 |
my_decimal *val_decimal(my_decimal *); |
|
2121 |
void make_field(Send_field *field) { item->make_field(field); } |
|
2122 |
void copy(); |
|
2123 |
int save_in_field(Field *field, bool no_conversions) |
|
2124 |
{
|
|
2125 |
return save_str_value_in_field(field, &str_value); |
|
2126 |
}
|
|
2127 |
table_map used_tables() const { return (table_map) 1L; } |
|
2128 |
bool const_item() const { return 0; } |
|
2129 |
bool is_null() { return null_value; } |
|
2130 |
};
|
|
2131 |
||
2132 |
||
2133 |
class Cached_item :public Sql_alloc |
|
2134 |
{
|
|
2135 |
public: |
|
2136 |
my_bool null_value; |
|
2137 |
Cached_item() :null_value(0) {} |
|
2138 |
virtual bool cmp(void)=0; |
|
2139 |
virtual ~Cached_item(); /*line -e1509 */ |
|
2140 |
};
|
|
2141 |
||
2142 |
class Cached_item_str :public Cached_item |
|
2143 |
{
|
|
2144 |
Item *item; |
|
2145 |
String value,tmp_value; |
|
2146 |
public: |
|
2147 |
Cached_item_str(THD *thd, Item *arg); |
|
2148 |
bool cmp(void); |
|
2149 |
~Cached_item_str(); // Deallocate String:s |
|
2150 |
};
|
|
2151 |
||
2152 |
||
2153 |
class Cached_item_real :public Cached_item |
|
2154 |
{
|
|
2155 |
Item *item; |
|
2156 |
double value; |
|
2157 |
public: |
|
2158 |
Cached_item_real(Item *item_par) :item(item_par),value(0.0) {} |
|
2159 |
bool cmp(void); |
|
2160 |
};
|
|
2161 |
||
2162 |
class Cached_item_int :public Cached_item |
|
2163 |
{
|
|
2164 |
Item *item; |
|
2165 |
longlong value; |
|
2166 |
public: |
|
2167 |
Cached_item_int(Item *item_par) :item(item_par),value(0) {} |
|
2168 |
bool cmp(void); |
|
2169 |
};
|
|
2170 |
||
2171 |
||
2172 |
class Cached_item_decimal :public Cached_item |
|
2173 |
{
|
|
2174 |
Item *item; |
|
2175 |
my_decimal value; |
|
2176 |
public: |
|
2177 |
Cached_item_decimal(Item *item_par); |
|
2178 |
bool cmp(void); |
|
2179 |
};
|
|
2180 |
||
2181 |
class Cached_item_field :public Cached_item |
|
2182 |
{
|
|
2183 |
uchar *buff; |
|
2184 |
Field *field; |
|
2185 |
uint length; |
|
2186 |
||
2187 |
public: |
|
2188 |
#ifndef DBUG_OFF
|
|
2189 |
void dbug_print() |
|
2190 |
{
|
|
2191 |
uchar *org_ptr; |
|
2192 |
org_ptr= field->ptr; |
|
2193 |
fprintf(DBUG_FILE, "new: "); |
|
2194 |
field->dbug_print(); |
|
2195 |
field->ptr= buff; |
|
2196 |
fprintf(DBUG_FILE, ", old: "); |
|
2197 |
field->dbug_print(); |
|
2198 |
field->ptr= org_ptr; |
|
2199 |
fprintf(DBUG_FILE, "\n"); |
|
2200 |
}
|
|
2201 |
#endif
|
|
2202 |
Cached_item_field(Field *arg_field) : field(arg_field) |
|
2203 |
{
|
|
2204 |
field= arg_field; |
|
2205 |
/* TODO: take the memory allocation below out of the constructor. */
|
|
2206 |
buff= (uchar*) sql_calloc(length=field->pack_length()); |
|
2207 |
}
|
|
2208 |
bool cmp(void); |
|
2209 |
};
|
|
2210 |
||
2211 |
class Item_default_value : public Item_field |
|
2212 |
{
|
|
2213 |
public: |
|
2214 |
Item *arg; |
|
2215 |
Item_default_value(Name_resolution_context *context_arg) |
|
2216 |
:Item_field(context_arg, (const char *)NULL, (const char *)NULL, |
|
2217 |
(const char *)NULL), |
|
2218 |
arg(NULL) {} |
|
2219 |
Item_default_value(Name_resolution_context *context_arg, Item *a) |
|
2220 |
:Item_field(context_arg, (const char *)NULL, (const char *)NULL, |
|
2221 |
(const char *)NULL), |
|
2222 |
arg(a) {} |
|
2223 |
enum Type type() const { return DEFAULT_VALUE_ITEM; } |
|
2224 |
bool eq(const Item *item, bool binary_cmp) const; |
|
2225 |
bool fix_fields(THD *, Item **); |
|
2226 |
virtual void print(String *str, enum_query_type query_type); |
|
2227 |
int save_in_field(Field *field_arg, bool no_conversions); |
|
2228 |
table_map used_tables() const { return (table_map)0L; } |
|
2229 |
||
2230 |
bool walk(Item_processor processor, bool walk_subquery, uchar *args) |
|
2231 |
{
|
|
2232 |
return arg->walk(processor, walk_subquery, args) || |
|
2233 |
(this->*processor)(args); |
|
2234 |
}
|
|
2235 |
||
2236 |
Item *transform(Item_transformer transformer, uchar *args); |
|
2237 |
};
|
|
2238 |
||
2239 |
/*
|
|
2240 |
Item_insert_value -- an implementation of VALUES() function.
|
|
2241 |
You can use the VALUES(col_name) function in the UPDATE clause
|
|
2242 |
to refer to column values from the INSERT portion of the INSERT
|
|
2243 |
... UPDATE statement. In other words, VALUES(col_name) in the
|
|
2244 |
UPDATE clause refers to the value of col_name that would be
|
|
2245 |
inserted, had no duplicate-key conflict occurred.
|
|
2246 |
In all other places this function returns NULL.
|
|
2247 |
*/
|
|
2248 |
||
2249 |
class Item_insert_value : public Item_field |
|
2250 |
{
|
|
2251 |
public: |
|
2252 |
Item *arg; |
|
2253 |
Item_insert_value(Name_resolution_context *context_arg, Item *a) |
|
2254 |
:Item_field(context_arg, (const char *)NULL, (const char *)NULL, |
|
2255 |
(const char *)NULL), |
|
2256 |
arg(a) {} |
|
2257 |
bool eq(const Item *item, bool binary_cmp) const; |
|
2258 |
bool fix_fields(THD *, Item **); |
|
2259 |
virtual void print(String *str, enum_query_type query_type); |
|
2260 |
int save_in_field(Field *field_arg, bool no_conversions) |
|
2261 |
{
|
|
2262 |
return Item_field::save_in_field(field_arg, no_conversions); |
|
2263 |
}
|
|
2264 |
/*
|
|
2265 |
We use RAND_TABLE_BIT to prevent Item_insert_value from
|
|
2266 |
being treated as a constant and precalculated before execution
|
|
2267 |
*/
|
|
2268 |
table_map used_tables() const { return RAND_TABLE_BIT; } |
|
2269 |
||
2270 |
bool walk(Item_processor processor, bool walk_subquery, uchar *args) |
|
2271 |
{
|
|
2272 |
return arg->walk(processor, walk_subquery, args) || |
|
2273 |
(this->*processor)(args); |
|
2274 |
}
|
|
2275 |
};
|
|
2276 |
||
2277 |
||
2278 |
class Item_cache: public Item_basic_constant |
|
2279 |
{
|
|
2280 |
protected: |
|
2281 |
Item *example; |
|
2282 |
table_map used_table_map; |
|
2283 |
/*
|
|
2284 |
Field that this object will get value from. This is set/used by
|
|
2285 |
index-based subquery engines to detect and remove the equality injected
|
|
2286 |
by IN->EXISTS transformation.
|
|
2287 |
For all other uses of Item_cache, cached_field doesn't matter.
|
|
2288 |
*/
|
|
2289 |
Field *cached_field; |
|
2290 |
enum enum_field_types cached_field_type; |
|
2291 |
public: |
|
2292 |
Item_cache(): |
|
2293 |
example(0), used_table_map(0), cached_field(0), cached_field_type(MYSQL_TYPE_STRING) |
|
2294 |
{
|
|
2295 |
fixed= 1; |
|
2296 |
null_value= 1; |
|
2297 |
}
|
|
2298 |
Item_cache(enum_field_types field_type_arg): |
|
2299 |
example(0), used_table_map(0), cached_field(0), cached_field_type(field_type_arg) |
|
2300 |
{
|
|
2301 |
fixed= 1; |
|
2302 |
null_value= 1; |
|
2303 |
}
|
|
2304 |
||
2305 |
void set_used_tables(table_map map) { used_table_map= map; } |
|
2306 |
||
2307 |
virtual bool allocate(uint i) { return 0; } |
|
2308 |
virtual bool setup(Item *item) |
|
2309 |
{
|
|
2310 |
example= item; |
|
2311 |
max_length= item->max_length; |
|
2312 |
decimals= item->decimals; |
|
2313 |
collation.set(item->collation); |
|
2314 |
unsigned_flag= item->unsigned_flag; |
|
2315 |
if (item->type() == FIELD_ITEM) |
|
2316 |
cached_field= ((Item_field *)item)->field; |
|
2317 |
return 0; |
|
2318 |
};
|
|
2319 |
virtual void store(Item *)= 0; |
|
2320 |
enum Type type() const { return CACHE_ITEM; } |
|
2321 |
enum_field_types field_type() const { return cached_field_type; } |
|
2322 |
static Item_cache* get_cache(const Item *item); |
|
2323 |
table_map used_tables() const { return used_table_map; } |
|
2324 |
virtual void keep_array() {} |
|
2325 |
virtual void print(String *str, enum_query_type query_type); |
|
2326 |
bool eq_def(Field *field) |
|
2327 |
{
|
|
2328 |
return cached_field ? cached_field->eq_def (field) : FALSE; |
|
2329 |
}
|
|
2330 |
bool eq(const Item *item, bool binary_cmp) const |
|
2331 |
{
|
|
2332 |
return this == item; |
|
2333 |
}
|
|
2334 |
};
|
|
2335 |
||
2336 |
||
2337 |
class Item_cache_int: public Item_cache |
|
2338 |
{
|
|
2339 |
protected: |
|
2340 |
longlong value; |
|
2341 |
public: |
|
2342 |
Item_cache_int(): Item_cache(), value(0) {} |
|
2343 |
Item_cache_int(enum_field_types field_type_arg): |
|
2344 |
Item_cache(field_type_arg), value(0) {} |
|
2345 |
||
2346 |
void store(Item *item); |
|
2347 |
void store(Item *item, longlong val_arg); |
|
2348 |
double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; } |
|
2349 |
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; } |
|
2350 |
String* val_str(String *str); |
|
2351 |
my_decimal *val_decimal(my_decimal *); |
|
2352 |
enum Item_result result_type() const { return INT_RESULT; } |
|
2353 |
bool result_as_longlong() { return TRUE; } |
|
2354 |
};
|
|
2355 |
||
2356 |
||
2357 |
class Item_cache_real: public Item_cache |
|
2358 |
{
|
|
2359 |
double value; |
|
2360 |
public: |
|
2361 |
Item_cache_real(): Item_cache(), value(0) {} |
|
2362 |
||
2363 |
void store(Item *item); |
|
2364 |
double val_real() { DBUG_ASSERT(fixed == 1); return value; } |
|
2365 |
longlong val_int(); |
|
2366 |
String* val_str(String *str); |
|
2367 |
my_decimal *val_decimal(my_decimal *); |
|
2368 |
enum Item_result result_type() const { return REAL_RESULT; } |
|
2369 |
};
|
|
2370 |
||
2371 |
||
2372 |
class Item_cache_decimal: public Item_cache |
|
2373 |
{
|
|
2374 |
protected: |
|
2375 |
my_decimal decimal_value; |
|
2376 |
public: |
|
2377 |
Item_cache_decimal(): Item_cache() {} |
|
2378 |
||
2379 |
void store(Item *item); |
|
2380 |
double val_real(); |
|
2381 |
longlong val_int(); |
|
2382 |
String* val_str(String *str); |
|
2383 |
my_decimal *val_decimal(my_decimal *); |
|
2384 |
enum Item_result result_type() const { return DECIMAL_RESULT; } |
|
2385 |
};
|
|
2386 |
||
2387 |
||
2388 |
class Item_cache_str: public Item_cache |
|
2389 |
{
|
|
2390 |
char buffer[STRING_BUFFER_USUAL_SIZE]; |
|
2391 |
String *value, value_buff; |
|
2392 |
bool is_varbinary; |
|
2393 |
||
2394 |
public: |
|
2395 |
Item_cache_str(const Item *item) : |
|
2396 |
Item_cache(), value(0), |
|
2397 |
is_varbinary(item->type() == FIELD_ITEM && |
|
2398 |
((const Item_field *) item)->field->type() == |
|
2399 |
MYSQL_TYPE_VARCHAR && |
|
2400 |
!((const Item_field *) item)->field->has_charset()) |
|
2401 |
{}
|
|
2402 |
void store(Item *item); |
|
2403 |
double val_real(); |
|
2404 |
longlong val_int(); |
|
2405 |
String* val_str(String *) { DBUG_ASSERT(fixed == 1); return value; } |
|
2406 |
my_decimal *val_decimal(my_decimal *); |
|
2407 |
enum Item_result result_type() const { return STRING_RESULT; } |
|
2408 |
CHARSET_INFO *charset() const { return value->charset(); }; |
|
2409 |
int save_in_field(Field *field, bool no_conversions); |
|
2410 |
};
|
|
2411 |
||
2412 |
class Item_cache_row: public Item_cache |
|
2413 |
{
|
|
2414 |
Item_cache **values; |
|
2415 |
uint item_count; |
|
2416 |
bool save_array; |
|
2417 |
public: |
|
2418 |
Item_cache_row() |
|
2419 |
:Item_cache(), values(0), item_count(2), save_array(0) {} |
|
2420 |
||
2421 |
/*
|
|
2422 |
'allocate' used only in row transformer, to preallocate space for row
|
|
2423 |
cache.
|
|
2424 |
*/
|
|
2425 |
bool allocate(uint num); |
|
2426 |
/*
|
|
2427 |
'setup' is needed only by row => it not called by simple row subselect
|
|
2428 |
(only by IN subselect (in subselect optimizer))
|
|
2429 |
*/
|
|
2430 |
bool setup(Item *item); |
|
2431 |
void store(Item *item); |
|
2432 |
void illegal_method_call(const char *); |
|
2433 |
void make_field(Send_field *) |
|
2434 |
{
|
|
2435 |
illegal_method_call((const char*)"make_field"); |
|
2436 |
};
|
|
2437 |
double val_real() |
|
2438 |
{
|
|
2439 |
illegal_method_call((const char*)"val"); |
|
2440 |
return 0; |
|
2441 |
};
|
|
2442 |
longlong val_int() |
|
2443 |
{
|
|
2444 |
illegal_method_call((const char*)"val_int"); |
|
2445 |
return 0; |
|
2446 |
};
|
|
2447 |
String *val_str(String *) |
|
2448 |
{
|
|
2449 |
illegal_method_call((const char*)"val_str"); |
|
2450 |
return 0; |
|
2451 |
};
|
|
2452 |
my_decimal *val_decimal(my_decimal *val) |
|
2453 |
{
|
|
2454 |
illegal_method_call((const char*)"val_decimal"); |
|
2455 |
return 0; |
|
2456 |
};
|
|
2457 |
||
2458 |
enum Item_result result_type() const { return ROW_RESULT; } |
|
2459 |
||
2460 |
uint cols() { return item_count; } |
|
2461 |
Item *element_index(uint i) { return values[i]; } |
|
2462 |
Item **addr(uint i) { return (Item **) (values + i); } |
|
2463 |
bool check_cols(uint c); |
|
2464 |
bool null_inside(); |
|
2465 |
void bring_value(); |
|
2466 |
void keep_array() { save_array= 1; } |
|
2467 |
void cleanup() |
|
2468 |
{
|
|
2469 |
DBUG_ENTER("Item_cache_row::cleanup"); |
|
2470 |
Item_cache::cleanup(); |
|
2471 |
if (save_array) |
|
2472 |
bzero(values, item_count*sizeof(Item**)); |
|
2473 |
else
|
|
2474 |
values= 0; |
|
2475 |
DBUG_VOID_RETURN; |
|
2476 |
}
|
|
2477 |
};
|
|
2478 |
||
2479 |
||
2480 |
/*
|
|
2481 |
Item_type_holder used to store type. name, length of Item for UNIONS &
|
|
2482 |
derived tables.
|
|
2483 |
||
2484 |
Item_type_holder do not need cleanup() because its time of live limited by
|
|
2485 |
single SP/PS execution.
|
|
2486 |
*/
|
|
2487 |
class Item_type_holder: public Item |
|
2488 |
{
|
|
2489 |
protected: |
|
2490 |
TYPELIB *enum_set_typelib; |
|
2491 |
enum_field_types fld_type; |
|
2492 |
||
2493 |
void get_full_info(Item *item); |
|
2494 |
||
2495 |
/* It is used to count decimal precision in join_types */
|
|
2496 |
int prev_decimal_int_part; |
|
2497 |
public: |
|
2498 |
Item_type_holder(THD*, Item*); |
|
2499 |
||
2500 |
Item_result result_type() const; |
|
2501 |
enum_field_types field_type() const { return fld_type; }; |
|
2502 |
enum Type type() const { return TYPE_HOLDER; } |
|
2503 |
double val_real(); |
|
2504 |
longlong val_int(); |
|
2505 |
my_decimal *val_decimal(my_decimal *); |
|
2506 |
String *val_str(String*); |
|
2507 |
bool join_types(THD *thd, Item *); |
|
2508 |
Field *make_field_by_type(TABLE *table); |
|
2509 |
static uint32 display_length(Item *item); |
|
2510 |
static enum_field_types get_real_type(Item *); |
|
2511 |
};
|
|
2512 |
||
2513 |
||
2514 |
class st_select_lex; |
|
2515 |
void mark_select_range_as_dependent(THD *thd, |
|
2516 |
st_select_lex *last_select, |
|
2517 |
st_select_lex *current_sel, |
|
2518 |
Field *found_field, Item *found_item, |
|
2519 |
Item_ident *resolved_item); |
|
2520 |
||
2521 |
extern Cached_item *new_Cached_item(THD *thd, Item *item, |
|
2522 |
bool use_result_field); |
|
2523 |
extern Item_result item_cmp_type(Item_result a,Item_result b); |
|
2524 |
extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item); |
|
2525 |
extern bool field_is_equal_to_item(Field *field,Item *item); |