1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_ITEM_H
21
#define DRIZZLED_ITEM_H
23
#include <drizzled/dtcollation.h>
24
#include <drizzled/drizzle_time.h>
25
#include <drizzled/decimal.h>
26
#include <drizzled/sql_bitmap.h>
27
#include <drizzled/sql_list.h>
28
#include "drizzled/memory/sql_alloc.h"
29
#include <drizzled/table.h>
30
#include "drizzled/item_result.h"
1
/* Copyright (C) 2000-2006 MySQL AB
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.
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.
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 */
18
void item_init(void); /* Init item functions */
37
class Name_resolution_context;
42
class Item_in_subselect;
52
Dummy error processor used by default by Name_resolution_context.
57
void dummy_error_processor(Session *session, void *data);
22
"Declared Type Collation"
23
A combination of collation and its derivation.
25
Flags for collation aggregation modes:
26
MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
27
MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
29
MY_COLL_ALLOW_CONV - allow any kind of conversion
30
(combination of the above two)
31
MY_COLL_DISALLOW_NONE - don't allow return DERIVATION_NONE
32
(e.g. when aggregating for comparison)
33
MY_COLL_CMP_CONV - combination of MY_COLL_ALLOW_CONV
34
and MY_COLL_DISALLOW_NONE
37
#define MY_COLL_ALLOW_SUPERSET_CONV 1
38
#define MY_COLL_ALLOW_COERCIBLE_CONV 2
39
#define MY_COLL_ALLOW_CONV 3
40
#define MY_COLL_DISALLOW_NONE 4
41
#define MY_COLL_CMP_CONV 7
45
const CHARSET_INFO *collation;
46
enum Derivation derivation;
49
void set_repertoire_from_charset(const CHARSET_INFO * const cs)
51
repertoire= cs->state & MY_CS_PUREASCII ?
52
MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
56
collation= &my_charset_bin;
57
derivation= DERIVATION_NONE;
58
repertoire= MY_REPERTOIRE_UNICODE30;
60
DTCollation(const CHARSET_INFO * const collation_arg, Derivation derivation_arg)
62
collation= collation_arg;
63
derivation= derivation_arg;
64
set_repertoire_from_charset(collation_arg);
66
void set(DTCollation &dt)
68
collation= dt.collation;
69
derivation= dt.derivation;
70
repertoire= dt.repertoire;
72
void set(const CHARSET_INFO * const collation_arg, Derivation derivation_arg)
74
collation= collation_arg;
75
derivation= derivation_arg;
76
set_repertoire_from_charset(collation_arg);
78
void set(const CHARSET_INFO * const collation_arg,
79
Derivation derivation_arg,
82
collation= collation_arg;
83
derivation= derivation_arg;
84
repertoire= repertoire_arg;
86
void set(const CHARSET_INFO * const collation_arg)
88
collation= collation_arg;
89
set_repertoire_from_charset(collation_arg);
91
void set(Derivation derivation_arg)
92
{ derivation= derivation_arg; }
93
bool aggregate(DTCollation &dt, uint flags= 0);
94
bool set(DTCollation &dt1, DTCollation &dt2, uint flags= 0)
95
{ set(dt1); return aggregate(dt2, flags); }
96
const char *derivation_name() const
100
case DERIVATION_IGNORABLE: return "IGNORABLE";
101
case DERIVATION_COERCIBLE: return "COERCIBLE";
102
case DERIVATION_IMPLICIT: return "IMPLICIT";
103
case DERIVATION_SYSCONST: return "SYSCONST";
104
case DERIVATION_EXPLICIT: return "EXPLICIT";
105
case DERIVATION_NONE: return "NONE";
106
default: return "UNKNOWN";
111
/*************************************************************************/
113
A framework to easily handle different return types for hybrid items
114
(hybrid item is an item whose operand can be of any type, e.g. integer,
118
struct Hybrid_type_traits;
126
Use two decimal buffers interchangeably to speed up += operation
127
which has no native support in decimal library.
128
Hybrid_type+= arg is implemented as dec_buf[1]= dec_buf[0] + arg.
129
The third decimal is used as a handy temporary storage.
131
my_decimal dec_buf[3];
135
Traits moved to a separate class to
136
a) be able to easily change object traits in runtime
137
b) they work as a differentiator for the union above
139
const Hybrid_type_traits *traits;
142
/* XXX: add traits->copy() when needed */
143
Hybrid_type(const Hybrid_type &rhs) :traits(rhs.traits) {}
147
/* Hybryd_type_traits interface + default implementation for REAL_RESULT */
149
struct Hybrid_type_traits
151
virtual Item_result type() const { return REAL_RESULT; }
154
fix_length_and_dec(Item *item, Item *arg) const;
156
/* Hybrid_type operations. */
157
virtual void set_zero(Hybrid_type *val) const { val->real= 0.0; }
158
virtual void add(Hybrid_type *val, Field *f) const
159
{ val->real+= f->val_real(); }
160
virtual void div(Hybrid_type *val, uint64_t u) const
161
{ val->real/= uint64_t2double(u); }
163
virtual int64_t val_int(Hybrid_type *val,
164
bool unsigned_flag __attribute__((unused))) const
165
{ return (int64_t) rint(val->real); }
166
virtual double val_real(Hybrid_type *val) const { return val->real; }
167
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const;
168
virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
169
static const Hybrid_type_traits *instance();
170
Hybrid_type_traits() {}
171
virtual ~Hybrid_type_traits() {}
175
struct Hybrid_type_traits_decimal: public Hybrid_type_traits
177
virtual Item_result type() const { return DECIMAL_RESULT; }
180
fix_length_and_dec(Item *arg, Item *item) const;
182
/* Hybrid_type operations. */
183
virtual void set_zero(Hybrid_type *val) const;
184
virtual void add(Hybrid_type *val, Field *f) const;
185
virtual void div(Hybrid_type *val, uint64_t u) const;
187
virtual int64_t val_int(Hybrid_type *val, bool unsigned_flag) const;
188
virtual double val_real(Hybrid_type *val) const;
189
virtual my_decimal *val_decimal(Hybrid_type *val,
190
my_decimal *buf __attribute__((unused))) const
191
{ return &val->dec_buf[val->used_dec_buf_no]; }
192
virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
193
static const Hybrid_type_traits_decimal *instance();
194
Hybrid_type_traits_decimal() {};
198
struct Hybrid_type_traits_integer: public Hybrid_type_traits
200
virtual Item_result type() const { return INT_RESULT; }
203
fix_length_and_dec(Item *arg, Item *item) const;
205
/* Hybrid_type operations. */
206
virtual void set_zero(Hybrid_type *val) const
208
virtual void add(Hybrid_type *val, Field *f) const
209
{ val->integer+= f->val_int(); }
210
virtual void div(Hybrid_type *val, uint64_t u) const
211
{ val->integer/= (int64_t) u; }
213
virtual int64_t val_int(Hybrid_type *val,
214
bool unsigned_flag __attribute__((unused))) const
215
{ return val->integer; }
216
virtual double val_real(Hybrid_type *val) const
217
{ return (double) val->integer; }
218
virtual my_decimal *val_decimal(Hybrid_type *val,
219
my_decimal *buf __attribute__((unused))) const
221
int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
222
return &val->dec_buf[2];
224
virtual String *val_str(Hybrid_type *val, String *buf,
225
uint8_t decimals __attribute__((unused))) const
226
{ buf->set(val->integer, &my_charset_bin); return buf;}
227
static const Hybrid_type_traits_integer *instance();
228
Hybrid_type_traits_integer() {};
232
void dummy_error_processor(THD *thd, void *data);
234
void view_error_processor(THD *thd, void *data);
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
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
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.
251
struct Name_resolution_context: Sql_alloc
254
The name resolution context to search in when an Item cannot be
255
resolved in this context (the context of an outer select)
257
Name_resolution_context *outer_context;
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.
267
TableList *table_list;
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
275
TableList *first_name_resolution_table;
277
Last table to search in the list of leaf table references that begins
278
with first_name_resolution_table.
280
TableList *last_name_resolution_table;
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
287
st_select_lex *select_lex;
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
294
void (*error_processor)(THD *, void *);
295
void *error_processor_data;
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.
302
bool resolve_in_select_list;
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.
308
Security_context *security_ctx;
310
Name_resolution_context()
311
:outer_context(0), table_list(0), select_lex(0),
312
error_processor_data(0),
318
resolve_in_select_list= false;
319
error_processor= &dummy_error_processor;
320
first_name_resolution_table= NULL;
321
last_name_resolution_table= NULL;
324
void resolve_in_table_list_only(TableList *tables)
326
table_list= first_name_resolution_table= tables;
327
resolve_in_select_list= false;
330
void process_error(THD *thd)
332
(*error_processor)(thd, error_processor_data);
338
Store and restore the current state of a name resolution context.
341
class Name_resolution_context_state
344
TableList *save_table_list;
345
TableList *save_first_name_resolution_table;
346
TableList *save_next_name_resolution_table;
347
bool save_resolve_in_select_list;
348
TableList *save_next_local;
351
Name_resolution_context_state() {} /* Remove gcc warning */
354
/* Save the state of a name resolution context. */
355
void save_state(Name_resolution_context *context, TableList *table_list)
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;
364
/* Restore a name resolution context from saved state. */
365
void restore_state(Name_resolution_context *context, TableList *table_list)
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;
374
TableList *get_first_name_resolution_table()
376
return save_first_name_resolution_table;
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:
389
[signed] int64_t F(field1, field2, ...) {
390
put values of field_i into table record buffer;
391
return item->val_int();
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.
402
typedef enum monotonicity_info
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;
409
/*************************************************************************/
410
typedef bool (Item::*Item_processor) (uchar *arg);
62
414
argp in/out IN: Analysis parameter
63
415
OUT: Parameter to be passed to the transformer
66
418
true Invoke the transformer
70
typedef bool (Item::*Item_analyzer) (unsigned char **argp);
71
typedef Item* (Item::*Item_transformer) (unsigned char *arg);
422
typedef bool (Item::*Item_analyzer) (uchar **argp);
423
typedef Item* (Item::*Item_transformer) (uchar *arg);
72
424
typedef void (*Cond_traverser) (const Item *item, void *arg);
73
typedef bool (Item::*Item_processor) (unsigned char *arg);
76
* The Item class is the base class for all items in the parsed
77
* statement "tree" or Lex. Each item represents something in the
80
class Item: public memory::SqlAlloc
82
/* Prevent use of these */
429
Item(const Item &); /* Prevent use of these */
84
430
void operator=(Item &);
86
431
/* Cache of the result of is_expensive(). */
87
432
int8_t is_expensive_cache;
88
virtual bool is_expensive_processor(unsigned char *arg);
433
virtual bool is_expensive_processor(uchar *arg __attribute__((unused)))
112
ROW_ITEM, CACHE_ITEM,
131
* str_values's main purpose is to be used to cache the value in
437
static void *operator new(size_t size)
438
{ return sql_alloc(size); }
439
static void *operator new(size_t size, MEM_ROOT *mem_root)
440
{ return alloc_root(mem_root, size); }
441
static void operator delete(void *ptr __attribute__((unused)),
442
size_t size __attribute__((unused)))
443
{ TRASH(ptr, size); }
444
static void operator delete(void *ptr __attribute__((unused)),
445
MEM_ROOT *mem_root __attribute__((unused)))
448
enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM,
449
INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM,
450
COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM,
451
PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
452
FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
453
SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
454
PARAM_ITEM, DECIMAL_ITEM,
457
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
459
enum traverse_order { POSTFIX, PREFIX };
461
/* Reuse size, only used by SP local variable assignment, otherwize 0 */
465
str_values's main purpose is to be used to cache the value in
134
468
String str_value;
136
/** Name from select */
138
/** Length of name */
139
uint32_t name_length;
141
/** Original item name (if it was renamed) */
469
char * name; /* Name from select */
470
/* Original item name (if it was renamed)*/
144
473
uint32_t max_length;
474
uint name_length; /* Length of name */
147
476
uint8_t decimals;
148
bool fixed; /**< If item fixed with fix_fields */
149
bool maybe_null; /**< True if item may be null */
150
bool null_value; /**< True if item is null */
477
bool maybe_null; /* If item may be null */
478
bool null_value; /* if item is null */
151
479
bool unsigned_flag;
152
480
bool with_sum_func;
153
bool is_autogenerated_name; /**< indicates whether name of this Item was autogenerated or set by user */
155
* If this item is a subselect or some of its arguments is or contains a
156
* subselect. Computed by fix_fields.
481
bool fixed; /* If item fixed with fix_fields */
482
bool is_autogenerated_name; /* indicate was name of this Item
483
autogenerated or set by user */
159
484
DTCollation collation;
160
Item_result cmp_context; /**< Comparison context */
166
* Alloc & destruct is done as start of select using memory::sql_alloc
485
bool with_subselect; /* If this item is a subselect or some
486
of its arguments is or contains a
487
subselect. Computed by fix_fields. */
488
Item_result cmp_context; /* Comparison context */
489
// alloc & destruct is done as start of select using sql_alloc
170
* Constructor used by Item_field, Item_ref & aggregate (sum) functions.
172
* Used for duplicating lists in processing queries with temporary
175
* Also it used for Item_cond_and/Item_cond_or for creating
176
* top AND/OR structure of WHERE clause to protect it of
177
* optimisation changes in prepared statements
179
Item(Session *session, Item *item);
492
Constructor used by Item_field, Item_ref & aggregate (sum) functions.
493
Used for duplicating lists in processing queries with temporary
495
Also it used for Item_cond_and/Item_cond_or for creating
496
top AND/OR structure of WHERE clause to protect it of
497
optimisation changes in prepared statements
499
Item(THD *thd, Item *item);
182
502
#ifdef EXTRA_DEBUG
187
void set_name(const std::string &arg)
189
set_name(arg.c_str(), arg.length(), system_charset_info);
192
void set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs= system_charset_info);
194
* Renames item (used for views, cleanup() return original name).
196
* @param new_name new name of item;
506
void set_name(const char *str, uint length, const CHARSET_INFO * const cs);
198
507
void rename(char *new_name);
199
void init_make_field(SendField *tmp_field,enum enum_field_types type);
508
void init_make_field(Send_field *tmp_field,enum enum_field_types type);
200
509
virtual void cleanup();
201
virtual void make_field(SendField *field);
203
Create a field to hold a string value from an item.
205
If max_length > CONVERT_IF_BIGGER_TO_BLOB create a blob @n
206
If max_length > 0 create a varchar @n
207
If max_length == 0 create a CHAR(0)
209
@param table Table for which the field is created
510
virtual void make_field(Send_field *field);
211
511
Field *make_string_field(Table *table);
212
virtual bool fix_fields(Session *, Item **);
215
* Fix after some tables has been pulled out. Basically re-calculate all
216
* attributes that are dependent on the tables.
218
virtual void fix_after_pullout(Select_Lex *new_parent, Item **ref);
221
* Should be used in case where we are sure that we do not need
222
* complete fix_fields() procedure.
224
inline void quick_fix_field()
512
virtual bool fix_fields(THD *, Item **);
514
Fix after some tables has been pulled out. Basically re-calculate all
515
attributes that are dependent on the tables.
517
virtual void fix_after_pullout(st_select_lex *new_parent __attribute__((unused)),
518
Item **ref __attribute__((unused))) {};
521
should be used in case where we are sure that we do not need
522
complete fix_fields() procedure.
524
inline void quick_fix_field() { fixed= 1; }
525
/* Function returns 1 on overflow and -1 on fatal errors */
526
int save_in_field_no_warnings(Field *field, bool no_conversions);
229
527
virtual int save_in_field(Field *field, bool no_conversions);
230
528
virtual void save_org_in_field(Field *field)
232
(void) save_in_field(field, true);
529
{ (void) save_in_field(field, 1); }
234
530
virtual int save_safe_in_field(Field *field)
236
return save_in_field(field, true);
239
* This is only called from items that is not of type item_field.
241
virtual bool send(plugin::Client *client, String *str);
243
Compares this Item to another Item, returning true if Item's
244
are functionally equal.
248
This function is called when:
249
- Comparing items in the WHERE clause (when doing where optimization)
250
- When trying to find an order_st BY/GROUP BY item in the SELECT part
531
{ return save_in_field(field, 1); }
532
virtual bool send(Protocol *protocol, String *str);
252
533
virtual bool eq(const Item *, bool binary_cmp) const;
253
virtual Item_result result_type() const
257
virtual Item_result cast_to_int_type() const
259
return result_type();
534
virtual Item_result result_type() const { return REAL_RESULT; }
535
virtual Item_result cast_to_int_type() const { return result_type(); }
261
536
virtual enum_field_types string_field_type() const;
262
537
virtual enum_field_types field_type() const;
263
538
virtual enum Type type() const =0;
267
* "func_arg $CMP$ const" half-interval
269
* "FUNC(func_arg) $CMP2$ const2"
273
* left_endp false <=> The interval is "x < const" or "x <= const"
274
* true <=> The interval is "x > const" or "x >= const"
276
* incl_endp IN true <=> the comparison is '<' or '>'
277
* false <=> the comparison is '<=' or '>='
278
* OUT The same but for the "F(x) $CMP$ F(const)" comparison
280
* This function is defined only for unary monotonic functions. The caller
281
* supplies the source half-interval
285
* The value of const is supplied implicitly as the value this item's
286
* argument, the form of $CMP$ comparison is specified through the
287
* function's arguments. The calle returns the result interval
289
* F(x) $CMP2$ F(const)
291
* passing back F(const) as the return value, and the form of $CMP2$
292
* through the out parameter. NULL values are assumed to be comparable and
293
* be less than any non-NULL values.
297
* The output range bound, which equal to the value of val_int()
298
* - If the value of the function is NULL then the bound is the
299
* smallest possible value of INT64_MIN
301
virtual int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
541
Return information about function monotonicity. See comment for
542
enum_monotonicity_info for details. This function can only be called
543
after fix_fields() call.
545
virtual enum_monotonicity_info get_monotonicity_info() const
546
{ return NON_MONOTONIC; }
549
Convert "func_arg $CMP$ const" half-interval into "FUNC(func_arg) $CMP2$ const2"
553
left_endp false <=> The interval is "x < const" or "x <= const"
554
true <=> The interval is "x > const" or "x >= const"
556
incl_endp IN true <=> the comparison is '<' or '>'
557
false <=> the comparison is '<=' or '>='
558
OUT The same but for the "F(x) $CMP$ F(const)" comparison
561
This function is defined only for unary monotonic functions. The caller
562
supplies the source half-interval
566
The value of const is supplied implicitly as the value this item's
567
argument, the form of $CMP$ comparison is specified through the
568
function's arguments. The calle returns the result interval
572
passing back F(const) as the return value, and the form of $CMP2$
573
through the out parameter. NULL values are assumed to be comparable and
574
be less than any non-NULL values.
577
The output range bound, which equal to the value of val_int()
578
- If the value of the function is NULL then the bound is the
579
smallest possible value of INT64_MIN
581
virtual int64_t val_int_endpoint(bool left_endp __attribute__((unused)),
582
bool *incl_endp __attribute__((unused)))
583
{ assert(0); return 0; }
303
586
/* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */
305
* Returns double precision floating point representation of item.
309
* In case of NULL value return 0.0 and set null_value flag to true.
310
* If value is not null null_value flag will be reset to false.
588
Return double precision floating point representation of item.
594
In case of NULL value return 0.0 and set null_value flag to true.
595
If value is not null null_value flag will be reset to false.
312
597
virtual double val_real()=0;
314
* Returns integer representation of item.
318
* In case of NULL value return 0 and set null_value flag to true.
319
* If value is not null null_value flag will be reset to false.
599
Return integer representation of item.
605
In case of NULL value return 0 and set null_value flag to true.
606
If value is not null null_value flag will be reset to false.
321
608
virtual int64_t val_int()=0;
323
* This is just a shortcut to avoid the cast. You should still use
324
* unsigned_flag to check the sign of the item.
326
inline uint64_t val_uint()
328
return (uint64_t) val_int();
331
* Return string representation of this item object.
333
* @param an allocated buffer this or any nested Item object can use to
334
* store return value of this method.
338
* Buffer passed via argument should only be used if the item itself
339
* doesn't have an own String buffer. In case when the item maintains
340
* it's own string buffer, it's preferable to return it instead to
341
* minimize number of mallocs/memcpys.
343
* The caller of this method can modify returned string, but only in case
344
* when it was allocated on heap, (is_alloced() is true). This allows
345
* the caller to efficiently use a buffer allocated by a child without
346
* having to allocate a buffer of it's own. The buffer, given to
347
* val_str() as argument, belongs to the caller and is later used by the
348
* caller at it's own choosing.
350
* A few implications from the above:
351
* - unless you return a string object which only points to your buffer
352
* but doesn't manages it you should be ready that it will be
354
* - even for not allocated strings (is_alloced() == false) the caller
355
* can change charset (see Item_func_{typecast/binary}. XXX: is this
357
* - still you should try to minimize data copying and return internal
358
* object whenever possible.
361
* In case of NULL value return 0 (NULL pointer) and set null_value flag
363
* If value is not null null_value flag will be reset to false.
610
This is just a shortcut to avoid the cast. You should still use
611
unsigned_flag to check the sign of the item.
613
inline uint64_t val_uint() { return (uint64_t) val_int(); }
615
Return string representation of this item object.
619
str an allocated buffer this or any nested Item object can use to
620
store return value of this method.
623
Buffer passed via argument should only be used if the item itself
624
doesn't have an own String buffer. In case when the item maintains
625
it's own string buffer, it's preferable to return it instead to
626
minimize number of mallocs/memcpys.
627
The caller of this method can modify returned string, but only in case
628
when it was allocated on heap, (is_alloced() is true). This allows
629
the caller to efficiently use a buffer allocated by a child without
630
having to allocate a buffer of it's own. The buffer, given to
631
val_str() as argument, belongs to the caller and is later used by the
632
caller at it's own choosing.
633
A few implications from the above:
634
- unless you return a string object which only points to your buffer
635
but doesn't manages it you should be ready that it will be
637
- even for not allocated strings (is_alloced() == false) the caller
638
can change charset (see Item_func_{typecast/binary}. XXX: is this
640
- still you should try to minimize data copying and return internal
641
object whenever possible.
644
In case of NULL value return 0 (NULL pointer) and set null_value flag
646
If value is not null null_value flag will be reset to false.
365
648
virtual String *val_str(String *str)=0;
367
* Return decimal representation of item with fixed point.
369
* @param buffer which can be used by Item for returning value
374
* Returned value should not be changed if it is not the same which was
375
* passed via argument.
379
* Return pointer on my_decimal (it can be other then passed via argument)
380
* if value is not NULL (null_value flag will be reset to false).
381
* In case of NULL value it return 0 pointer and set null_value flag
650
Return decimal representation of item with fixed point.
654
decimal_buffer buffer which can be used by Item for returning value
658
Returned value should not be changed if it is not the same which was
662
Return pointer on my_decimal (it can be other then passed via argument)
663
if value is not NULL (null_value flag will be reset to false).
664
In case of NULL value it return 0 pointer and set null_value flag
384
667
virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
386
* Return boolean value of item.
390
* false value is false or NULL
391
* true value is true (not equal to 0)
669
Return boolean value of item.
672
false value is false or NULL
673
true value is true (not equal to 0)
393
675
virtual bool val_bool();
676
virtual String *val_nodeset(String*) { return 0; }
394
677
/* Helper functions, see item_sum.cc */
395
678
String *val_string_from_real(String *str);
396
679
String *val_string_from_int(String *str);
529
759
query and why they should be generated from the Item-tree, @see
530
760
mysql_register_view().
532
virtual void print(String *str, enum_query_type query_type);
762
virtual inline void print(String *str,
763
enum_query_type query_type __attribute__((unused)))
765
str->append(full_name());
534
768
void print_item_w_name(String *, enum_query_type query_type);
535
769
virtual void update_used_tables() {}
536
virtual void split_sum_func(Session *session,
537
Item **ref_pointer_array,
540
Move SUM items out from item tree and replace with reference.
542
@param session Thread handler
543
@param ref_pointer_array Pointer to array of reference fields
544
@param fields All fields in select
545
@param ref Pointer to item
546
@param skip_registered <=> function be must skipped for registered
550
This is from split_sum_func() for items that should be split
552
All found SUM items are added FIRST in the fields list and
553
we replace the item with a reference.
555
session->fatal_error() may be called if we are out of memory
557
void split_sum_func(Session *session,
558
Item **ref_pointer_array,
561
bool skip_registered);
564
Get the value of the function as a DRIZZLE_TIME structure.
565
As a extra convenience the time structure is reset on error!
567
virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
569
Get time of first argument.
571
As a extra convenience the time structure is reset on error!
770
virtual void split_sum_func(THD *thd __attribute__((unused)),
771
Item **ref_pointer_array __attribute__((unused)),
772
List<Item> &fields __attribute__((unused))) {}
773
/* Called for items that really have to be split */
774
void split_sum_func2(THD *thd, Item **ref_pointer_array, List<Item> &fields,
775
Item **ref, bool skip_registered);
776
virtual bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
573
777
virtual bool get_time(DRIZZLE_TIME *ltime);
574
virtual bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
577
The method allows to determine nullness of a complex expression
578
without fully evaluating it, instead of calling val/result*() then
778
virtual bool get_date_result(DRIZZLE_TIME *ltime,uint fuzzydate)
779
{ return get_date(ltime,fuzzydate); }
781
The method allows to determine nullness of a complex expression
782
without fully evaluating it, instead of calling val/result*() then
579
783
checking null_value. Used in Item_func_isnull/Item_func_isnotnull
580
784
and Item_sum_count/Item_sum_count_distinct.
581
785
Any new item which can be NULL must implement this method.
583
virtual bool is_null();
585
/** Make sure the null_value member has a correct value. */
586
virtual void update_null_value ();
787
virtual bool is_null() { return 0; }
790
Make sure the null_value member has a correct value.
792
virtual void update_null_value () { (void) val_int(); }
589
795
Inform the item that there will be no distinction between its result
590
796
being false or NULL.
594
799
This function will be called for eg. Items that are top-level AND-parts
595
800
of the WHERE clause. Items implementing this function (currently
596
801
Item_cond_and and subquery-related item) enable special optimizations
597
802
when they are "top level".
599
virtual void top_level_item(void);
601
* Sets field of temporary table for Item which can be switched on temporary
602
* table during query processing (grouping and so on)
604
virtual void set_result_field(Field *field);
605
virtual bool is_result_field(void);
606
virtual bool is_bool_func(void);
607
virtual void save_in_result_field(bool no_conversions);
610
* Sets value of aggregate function in case of no rows for grouping were found
612
virtual void no_rows_in_result(void);
613
virtual Item *copy_or_same(Session *session);
615
virtual Item *copy_andor_structure(Session *session);
617
virtual Item *real_item(void);
618
virtual const Item *real_item(void) const;
619
virtual Item *get_tmp_table_item(Session *session);
804
virtual void top_level_item(void) {}
806
set field of temporary table for Item which can be switched on temporary
807
table during query processing (grouping and so on)
809
virtual void set_result_field(Field *field __attribute__((unused))) {}
810
virtual bool is_result_field(void) { return 0; }
811
virtual bool is_bool_func(void) { return 0; }
812
virtual void save_in_result_field(bool no_conversions __attribute__((unused)))
815
set value of aggregate function in case of no rows for grouping were found
817
virtual void no_rows_in_result(void) {}
818
virtual Item *copy_or_same(THD *thd __attribute__((unused)))
820
virtual Item *copy_andor_structure(THD *thd __attribute__((unused)))
822
virtual Item *real_item(void) { return this; }
823
virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
621
825
static const CHARSET_INFO *default_charset();
622
virtual const CHARSET_INFO *compare_collation();
624
virtual bool walk(Item_processor processor,
629
Traverse item tree possibly transforming it (replacing items).
631
If you don't need to transform an item tree, but only traverse
632
it, please use Item::walk() instead.
634
@param transformer functor that performs transformation of a subtree
635
@param arg opaque argument passed to the functor
638
Returns pointer to the new subtree root. Session::change_item_tree()
639
should be called for it if transformation took place, i.e. if a
640
pointer to newly allocated item is returned.
642
virtual Item* transform(Item_transformer transformer, unsigned char *arg);
826
virtual const CHARSET_INFO *compare_collation() { return NULL; }
828
virtual bool walk(Item_processor processor __attribute__((unused)),
829
bool walk_subquery __attribute__((unused)),
832
return (this->*processor)(arg);
835
virtual Item* transform(Item_transformer transformer, uchar *arg);
645
838
This function performs a generic "compilation" of the Item tree.
646
The process of compilation is assumed to go as follows:
839
The process of compilation is assumed to go as follows:
651
843
if (this->*some_analyzer(...))
653
845
compile children if any;
654
846
this->*some_transformer(...);
659
850
i.e. analysis is performed top-down while transformation is done
662
virtual Item* compile(Item_analyzer analyzer,
663
unsigned char **arg_p,
664
Item_transformer transformer,
665
unsigned char *arg_t);
667
virtual void traverse_cond(Cond_traverser traverser,
669
traverse_order order);
671
virtual bool remove_dependence_processor(unsigned char * arg);
672
virtual bool remove_fixed(unsigned char * arg);
673
virtual bool collect_item_field_processor(unsigned char * arg);
674
virtual bool find_item_in_field_list_processor(unsigned char *arg);
675
virtual bool change_context_processor(unsigned char *context);
676
virtual bool register_field_in_read_map(unsigned char *arg);
677
virtual bool subst_argument_checker(unsigned char **arg);
679
virtual bool cache_const_expr_analyzer(unsigned char **arg);
680
virtual Item* cache_const_expr_transformer(unsigned char *arg);
682
virtual Item *equal_fields_propagator(unsigned char * arg);
683
virtual bool set_no_const_sub(unsigned char *arg);
684
virtual Item *replace_equal_field(unsigned char * arg);
853
virtual Item* compile(Item_analyzer analyzer, uchar **arg_p,
854
Item_transformer transformer, uchar *arg_t)
856
if ((this->*analyzer) (arg_p))
857
return ((this->*transformer) (arg_t));
861
virtual void traverse_cond(Cond_traverser traverser __attribute__((unused)),
863
traverse_order order __attribute__((unused)))
865
(*traverser)(this, arg);
868
virtual bool remove_dependence_processor(uchar * arg __attribute__((unused)))
870
virtual bool remove_fixed(uchar * arg __attribute__((unused)))
875
virtual bool cleanup_processor(uchar *arg __attribute__((unused)));
876
virtual bool collect_item_field_processor(uchar * arg __attribute__((unused)))
878
virtual bool find_item_in_field_list_processor(uchar *arg __attribute__((unused)))
880
virtual bool change_context_processor(uchar *context __attribute__((unused)))
882
virtual bool reset_query_id_processor(uchar *query_id_arg __attribute__((unused)))
884
virtual bool register_field_in_read_map(uchar *arg __attribute__((unused)))
886
virtual bool subst_argument_checker(uchar **arg)
893
virtual Item *equal_fields_propagator(uchar * arg __attribute__((unused))) { return this; }
894
virtual bool set_no_const_sub(uchar *arg __attribute__((unused))) { return false; }
895
virtual Item *replace_equal_field(uchar * arg __attribute__((unused))) { return this; }
898
For SP local variable returns pointer to Item representing its
899
current value and pointer to current Item otherwise.
901
virtual Item *this_item(void) { return this; }
902
virtual const Item *this_item(void) const { return this; }
905
For SP local variable returns address of pointer to Item representing its
906
current value and pointer passed via parameter otherwise.
908
virtual Item **this_item_addr(THD *thd __attribute__((unused)), Item **addr_arg) { return addr_arg; }
687
virtual uint32_t cols();
688
virtual Item* element_index(uint32_t i);
689
virtual Item** addr(uint32_t i);
690
virtual bool check_cols(uint32_t c);
911
virtual uint cols() { return 1; }
912
virtual Item* element_index(uint i __attribute__((unused))) { return this; }
913
virtual Item** addr(uint i __attribute__((unused))) { return 0; }
914
virtual bool check_cols(uint c);
691
915
// It is not row => null inside is impossible
692
virtual bool null_inside();
916
virtual bool null_inside() { return 0; }
693
917
// used in row subselects to get value of elements
694
virtual void bring_value();
697
Create a field based on field_type of argument.
699
For now, this is only used to create a field for
700
IFNULL(x,something) and time functions
918
virtual void bring_value() {}
707
920
Field *tmp_table_field_from_field_type(Table *table, bool fixed_length);
921
virtual Item_field *filed_for_view_update() { return 0; }
709
virtual Item *neg_transformer(Session *session);
710
virtual Item *update_value_transformer(unsigned char *select_arg);
923
virtual Item *neg_transformer(THD *thd __attribute__((unused))) { return NULL; }
924
virtual Item *update_value_transformer(uchar *select_arg __attribute__((unused))) { return this; }
711
925
virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
715
* Returns true for Items representing DATE/TIME functions and DATE/TIME table fields.
716
* Those Items have result_type()==STRING_RESULT (and not INT_RESULT), but
717
* their values should be compared as integers (because the integer
718
* representation is more precise than the string one).
720
virtual bool result_as_int64_t();
933
result_as_int64_t() must return true for Items representing DATE/TIME
934
functions and DATE/TIME table fields.
935
Those Items have result_type()==STRING_RESULT (and not INT_RESULT), but
936
their values should be compared as integers (because the integer
937
representation is more precise than the string one).
939
virtual bool result_as_int64_t() { return false; }
721
940
bool is_datetime();
724
* Tests whether an expression is expensive to compute. Used during
725
* optimization to avoid computing expensive expressions during this
726
* phase. Also used to force temp tables when sorting on expensive
731
* Normally we should have a method:
732
* cost Item::execution_cost(),
733
* where 'cost' is either 'double' or some structure of various cost
736
virtual bool is_expensive();
943
Test whether an expression is expensive to compute. Used during
944
optimization to avoid computing expensive expressions during this
945
phase. Also used to force temp tables when sorting on expensive
948
Normally we should have a method:
949
cost Item::execution_cost(),
950
where 'cost' is either 'double' or some structure of various cost
953
virtual bool is_expensive()
955
if (is_expensive_cache < 0)
956
is_expensive_cache= walk(&Item::is_expensive_processor, 0, (uchar*)0);
957
return test(is_expensive_cache);
738
959
String *check_well_formed_result(String *str, bool send_error= 0);
740
* Compares two items using a given collation
744
* This method works exactly as Item::eq if the collation cs coincides with
745
* the collation of the compared objects. Otherwise, first the collations that
746
* differ from cs are replaced for cs and then the items are compared by
747
* Item::eq. After the comparison the original collations of items are
750
* @param Pointer to the item to compare with
751
* @param Compare as binary?
752
* @param Pointer to the collation to use when comparing strings
755
* true if compared items has been detected as equal
759
bool eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs);
762
} /* namespace drizzled */
764
/** @TODO Why is this in the middle? */
765
#include <drizzled/item/ident.h>
771
Mark item and Select_Lexs as dependent if item was resolved in
774
@param session thread handler
775
@param last select from which current item depend
776
@param current current select
777
@param resolved_item item which was resolved in outer SELECT(for warning)
778
@param mark_item item which should be marked (can be differ in case of
781
void mark_as_dependent(Session *session,
784
Item_ident *resolved_item,
785
Item_ident *mark_item);
788
Resolve a column reference in a sub-select.
790
Resolve a column reference (usually inside a HAVING clause) against the
791
SELECT and GROUP BY clauses of the query described by 'select'. The name
792
resolution algorithm searches both the SELECT and GROUP BY clauses, and in
793
case of a name conflict prefers GROUP BY column names over SELECT names. If
794
both clauses contain different fields with the same names, a warning is
795
issued that name of 'ref' is ambiguous. We extend ANSI SQL in that when no
796
GROUP BY column is found, then a HAVING name is resolved as a possibly
797
derived SELECT column. This extension is allowed only if the
798
MODE_ONLY_FULL_GROUP_BY sql mode isn't enabled.
800
@param session current thread
801
@param ref column reference being resolved
802
@param select the select that ref is resolved against
805
The resolution procedure is:
806
- Search for a column or derived column named col_ref_i [in table T_j]
807
in the SELECT clause of Q.
808
- Search for a column named col_ref_i [in table T_j]
809
in the GROUP BY clause of Q.
810
- If found different columns with the same name in GROUP BY and SELECT
811
- issue a warning and return the GROUP BY column,
813
- if the MODE_ONLY_FULL_GROUP_BY mode is enabled return error
814
- else return the found SELECT column.
818
- NULL - there was an error, and the error was already reported
819
- not_found_item - the item was not resolved, no error was reported
820
- resolved item - if the item was resolved
822
Item** resolve_ref_in_select_and_group(Session *session, Item_ident *ref, Select_Lex *select);
825
Mark range of selects and resolved identifier (field/reference)
828
@param session thread handler
829
@param last_select select where resolved_item was resolved
830
@param current_sel current select (select where resolved_item was placed)
831
@param found_field field which was found during resolving
832
@param found_item Item which was found during resolving (if resolved
833
identifier belongs to VIEW)
834
@param resolved_item Identifier which was resolved
837
We have to mark all items between current_sel (including) and
838
last_select (excluding) as dependend (select before last_select should
839
be marked with actual table mask used by resolved item, all other with
840
OUTER_REF_TABLE_BIT) and also write dependence information to Item of
843
void mark_select_range_as_dependent(Session *session,
844
Select_Lex *last_select,
845
Select_Lex *current_sel,
960
bool eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs);
964
class Item_basic_constant :public Item
967
/* to prevent drop fixed flag (no need parent cleanup call) */
971
Restore the original field name as it might not have been allocated
972
in the statement memory. If the name is auto generated, it must be
973
done again between subsequent executions of a prepared statement.
980
bool agg_item_collations(DTCollation &c, const char *name,
981
Item **items, uint nitems, uint flags, int item_sep);
982
bool agg_item_collations_for_comparison(DTCollation &c, const char *name,
983
Item **items, uint nitems, uint flags);
984
bool agg_item_charsets(DTCollation &c, const char *name,
985
Item **items, uint nitems, uint flags, int item_sep);
988
class Item_num: public Item_basic_constant
991
Item_num() {} /* Remove gcc warning */
992
virtual Item_num *neg()= 0;
993
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
996
#define NO_CACHED_FIELD_INDEX ((uint)(-1))
999
class Item_ident :public Item
1003
We have to store initial values of db_name, table_name and field_name
1004
to be able to restore them during cleanup() because they can be
1005
updated during fix_fields() to values from Field object and life-time
1006
of those is shorter than life-time of Item_field.
1008
const char *orig_db_name;
1009
const char *orig_table_name;
1010
const char *orig_field_name;
1013
Name_resolution_context *context;
1014
const char *db_name;
1015
const char *table_name;
1016
const char *field_name;
1017
bool alias_name_used; /* true if item was resolved against alias */
1019
Cached value of index for this field in table->field array, used by prep.
1020
stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX
1021
if index value is not known.
1023
uint cached_field_index;
1025
Cached pointer to table which contains this field, used for the same reason
1026
by prep. stmt. too in case then we have not-fully qualified field.
1027
0 - means no cached value.
1029
TableList *cached_table;
1030
st_select_lex *depended_from;
1031
Item_ident(Name_resolution_context *context_arg,
1032
const char *db_name_arg, const char *table_name_arg,
1033
const char *field_name_arg);
1034
Item_ident(THD *thd, Item_ident *item);
1035
const char *full_name() const;
1037
bool remove_dependence_processor(uchar * arg);
1038
virtual void print(String *str, enum_query_type query_type);
1039
virtual bool change_context_processor(uchar *cntx)
1040
{ context= (Name_resolution_context *)cntx; return false; }
1041
friend bool insert_fields(THD *thd, Name_resolution_context *context,
1042
const char *db_name,
1043
const char *table_name, List_iterator<Item> *it,
1044
bool any_privileges);
1048
class Item_ident_for_show :public Item
1052
const char *db_name;
1053
const char *table_name;
1055
Item_ident_for_show(Field *par_field, const char *db_arg,
1056
const char *table_name_arg)
1057
:field(par_field), db_name(db_arg), table_name(table_name_arg)
1060
enum Type type() const { return FIELD_ITEM; }
1061
double val_real() { return field->val_real(); }
1062
int64_t val_int() { return field->val_int(); }
1063
String *val_str(String *str) { return field->val_str(str); }
1064
my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); }
1065
void make_field(Send_field *tmp_field);
1072
class Item_field :public Item_ident
1075
void set_field(Field *field);
1077
Field *field,*result_field;
1078
Item_equal *item_equal;
1079
bool no_const_subst;
1081
if any_privileges set to true then here real effective privileges will
1084
uint have_privileges;
1085
/* field need any privileges (for VIEW creation) */
1086
bool any_privileges;
1087
Item_field(Name_resolution_context *context_arg,
1088
const char *db_arg,const char *table_name_arg,
1089
const char *field_name_arg);
1091
Constructor needed to process subselect with temporary tables (see Item)
1093
Item_field(THD *thd, Item_field *item);
1095
Constructor used inside setup_wild(), ensures that field, table,
1096
and database names will live as long as Item_field (this is important
1097
in prepared statements).
1099
Item_field(THD *thd, Name_resolution_context *context_arg, Field *field);
1101
If this constructor is used, fix_fields() won't work, because
1102
db_name, table_name and column_name are unknown. It's necessary to call
1103
reset_field() before fix_fields() for all fields created this way.
1105
Item_field(Field *field);
1106
enum Type type() const { return FIELD_ITEM; }
1107
bool eq(const Item *item, bool binary_cmp) const;
1110
my_decimal *val_decimal(my_decimal *);
1111
String *val_str(String*);
1112
double val_result();
1113
int64_t val_int_result();
1114
String *str_result(String* tmp);
1115
my_decimal *val_decimal_result(my_decimal *);
1116
bool val_bool_result();
1117
bool send(Protocol *protocol, String *str_arg);
1118
void reset_field(Field *f);
1119
bool fix_fields(THD *, Item **);
1120
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
1121
void make_field(Send_field *tmp_field);
1122
int save_in_field(Field *field,bool no_conversions);
1123
void save_org_in_field(Field *field);
1124
table_map used_tables() const;
1125
enum Item_result result_type () const
1127
return field->result_type();
1129
Item_result cast_to_int_type() const
1131
return field->cast_to_int_type();
1133
enum_field_types field_type() const
1135
return field->type();
1137
enum_monotonicity_info get_monotonicity_info() const
1139
return MONOTONIC_STRICT_INCREASING;
1141
int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
1142
Field *get_tmp_table_field() { return result_field; }
1143
Field *tmp_table_field(Table *t_arg __attribute__((unused))) { return result_field; }
1144
bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
1145
bool get_date_result(DRIZZLE_TIME *ltime,uint fuzzydate);
1146
bool get_time(DRIZZLE_TIME *ltime);
1147
bool is_null() { return field->is_null(); }
1148
void update_null_value();
1149
Item *get_tmp_table_item(THD *thd);
1150
bool collect_item_field_processor(uchar * arg);
1151
bool find_item_in_field_list_processor(uchar *arg);
1152
bool register_field_in_read_map(uchar *arg);
1154
bool result_as_int64_t()
1156
return field->can_be_compared_as_int64_t();
1158
Item_equal *find_item_equal(COND_EQUAL *cond_equal);
1159
bool subst_argument_checker(uchar **arg);
1160
Item *equal_fields_propagator(uchar *arg);
1161
bool set_no_const_sub(uchar *arg);
1162
Item *replace_equal_field(uchar *arg);
1163
inline uint32_t max_disp_length() { return field->max_display_length(); }
1164
Item_field *filed_for_view_update() { return this; }
1165
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1166
int fix_outer_field(THD *thd, Field **field, Item **reference);
1167
virtual Item *update_value_transformer(uchar *select_arg);
1168
virtual void print(String *str, enum_query_type query_type);
1170
friend class Item_default_value;
1171
friend class Item_insert_value;
1172
friend class st_select_lex_unit;
1175
class Item_null :public Item_basic_constant
1178
Item_null(char *name_par=0)
1180
maybe_null= null_value= true;
1182
name= name_par ? name_par : (char*) "NULL";
1184
collation.set(&my_charset_bin, DERIVATION_IGNORABLE);
1186
enum Type type() const { return NULL_ITEM; }
1187
bool eq(const Item *item, bool binary_cmp) const;
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 DRIZZLE_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; }
1201
virtual inline void print(String *str,
1202
enum_query_type query_type __attribute__((unused)))
1204
str->append(STRING_WITH_LEN("NULL"));
1207
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1210
class Item_null_result :public Item_null
1213
Field *result_field;
1214
Item_null_result() : Item_null(), result_field(0) {}
1215
bool is_result_field() { return result_field != 0; }
1216
void save_in_result_field(bool no_conversions)
1218
save_in_field(result_field, no_conversions);
1222
/* Item represents one placeholder ('?') of prepared statement */
1224
class Item_param :public Item
1226
char cnvbuf[MAX_FIELD_WIDTH];
1231
enum enum_item_param_state
1233
NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE,
1234
STRING_VALUE, TIME_VALUE, LONG_DATA_VALUE,
1239
A buffer for string and long data values. Historically all allocated
1240
values returned from val_str() were treated as eligible to
1241
modification. I. e. in some cases Item_func_concat can append it's
1242
second argument to return value of the first one. Because of that we
1243
can't return the original buffer holding string data from val_str(),
1244
and have to have one buffer for data and another just pointing to
1245
the data. This is the latter one and it's returned from val_str().
1246
Can not be declared inside the union as it's not a POD type.
1248
String str_value_ptr;
1249
my_decimal decimal_value;
1255
Character sets conversion info for string values.
1256
Character sets of client and connection defined at bind time are used
1257
for all conversions, even if one of them is later changed (i.e.
1258
between subsequent calls to mysql_stmt_execute).
1260
struct CONVERSION_INFO
1262
const CHARSET_INFO *character_set_client;
1263
const CHARSET_INFO *character_set_of_placeholder;
1265
This points at character set of connection if conversion
1266
to it is required (i. e. if placeholder typecode is not BLOB).
1267
Otherwise it's equal to character_set_client (to simplify
1268
check in convert_str_value()).
1270
const CHARSET_INFO *final_character_set_of_str_value;
1275
/* Cached values for virtual methods to save us one switch. */
1276
enum Item_result item_result_type;
1277
enum Type item_type;
1280
Used when this item is used in a temporary table.
1281
This is NOT placeholder metadata sent to client, as this value
1282
is assigned after sending metadata (in setup_one_conversion_function).
1283
For example in case of 'SELECT ?' you'll get DRIZZLE_TYPE_STRING both
1284
in result set and placeholders metadata, no matter what type you will
1285
supply for this placeholder in mysql_stmt_execute.
1287
enum enum_field_types param_type;
1289
Offset of placeholder inside statement text. Used to create
1290
no-placeholders version of this statement for the binary log.
1294
Item_param(uint pos_in_query_arg);
1296
enum Item_result result_type () const { return item_result_type; }
1297
enum Type type() const { return item_type; }
1298
enum_field_types field_type() const { return param_type; }
1302
my_decimal *val_decimal(my_decimal*);
1303
String *val_str(String*);
1304
bool get_time(DRIZZLE_TIME *tm);
1305
bool get_date(DRIZZLE_TIME *tm, uint fuzzydate);
1306
int save_in_field(Field *field, bool no_conversions);
1309
void set_int(int64_t i, uint32_t max_length_arg);
1310
void set_double(double i);
1311
void set_decimal(char *str, ulong length);
1312
bool set_str(const char *str, ulong length);
1313
bool set_longdata(const char *str, ulong length);
1314
void set_time(DRIZZLE_TIME *tm, timestamp_type type, uint32_t max_length_arg);
1315
bool set_from_user_var(THD *thd, const user_var_entry *entry);
1318
Assign placeholder value from bind data.
1319
Note, that 'len' has different semantics in embedded library (as we
1320
don't need to check that packet is not broken there). See
1321
sql_prepare.cc for details.
1323
void (*set_param_func)(Item_param *param, uchar **pos, ulong len);
1325
const String *query_val_str(String *str) const;
1327
bool convert_str_value(THD *thd);
1330
If value for parameter was not set we treat it as non-const
1331
so noone will use parameters value in fix_fields still
1332
parameter is constant during execution.
1334
virtual table_map used_tables() const
1335
{ return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; }
1336
virtual void print(String *str, enum_query_type query_type);
1338
{ assert(state != NO_VALUE); return state == NULL_VALUE; }
1339
bool basic_const_item() const;
1341
This method is used to make a copy of a basic constant item when
1342
propagating constants in the optimizer. The reason to create a new
1343
item and not use the existing one is not precisely known (2005/04/16).
1344
Probably we are trying to preserve tree structure of items, in other
1345
words, avoid pointing at one item from two different nodes of the tree.
1346
Return a new basic constant item if parameter value is a basic
1347
constant, assert otherwise. This method is called only if
1348
basic_const_item returned true.
1350
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1353
Implement by-value equality evaluation if parameter value
1354
is set and is a basic constant (integer, real or string).
1355
Otherwise return false.
1357
bool eq(const Item *item, bool binary_cmp) const;
1358
/** Item is a argument to a limit clause. */
1359
bool limit_clause_param;
1363
class Item_int :public Item_num
1367
Item_int(int32_t i,uint length= MY_INT32_NUM_DECIMAL_DIGITS)
1369
{ max_length=length; fixed= 1; }
1370
Item_int(int64_t i,uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1372
{ max_length=length; fixed= 1; }
1373
Item_int(uint64_t i, uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1375
{ max_length=length; fixed= 1; unsigned_flag= 1; }
1376
Item_int(const char *str_arg,int64_t i,uint length) :value(i)
1377
{ max_length=length; name=(char*) str_arg; fixed= 1; }
1378
Item_int(const char *str_arg, uint length=64);
1379
enum Type type() const { return INT_ITEM; }
1380
enum Item_result result_type () const { return INT_RESULT; }
1381
enum_field_types field_type() const { return DRIZZLE_TYPE_LONGLONG; }
1382
int64_t val_int() { assert(fixed == 1); return value; }
1383
double val_real() { assert(fixed == 1); return (double) value; }
1384
my_decimal *val_decimal(my_decimal *);
1385
String *val_str(String*);
1386
int save_in_field(Field *field, bool no_conversions);
1387
bool basic_const_item() const { return 1; }
1388
Item *clone_item() { return new Item_int(name,value,max_length); }
1389
virtual void print(String *str, enum_query_type query_type);
1390
Item_num *neg() { value= -value; return this; }
1391
uint decimal_precision() const
1392
{ return (uint)(max_length - test(value < 0)); }
1393
bool eq(const Item *, bool binary_cmp) const;
1397
class Item_uint :public Item_int
1400
Item_uint(const char *str_arg, uint length);
1401
Item_uint(uint64_t i) :Item_int((uint64_t) i, 10) {}
1402
Item_uint(const char *str_arg, int64_t i, uint length);
1404
{ assert(fixed == 1); return uint64_t2double((uint64_t)value); }
1405
String *val_str(String*);
1406
Item *clone_item() { return new Item_uint(name, value, max_length); }
1407
int save_in_field(Field *field, bool no_conversions);
1408
virtual void print(String *str, enum_query_type query_type);
1410
uint decimal_precision() const { return max_length; }
1414
/* decimal (fixed point) constant */
1415
class Item_decimal :public Item_num
1418
my_decimal decimal_value;
1420
Item_decimal(const char *str_arg, uint length, const CHARSET_INFO * const charset);
1421
Item_decimal(const char *str, const my_decimal *val_arg,
1422
uint decimal_par, uint length);
1423
Item_decimal(my_decimal *value_par);
1424
Item_decimal(int64_t val, bool unsig);
1425
Item_decimal(double val, int precision, int scale);
1426
Item_decimal(const uchar *bin, int precision, int scale);
1428
enum Type type() const { return DECIMAL_ITEM; }
1429
enum Item_result result_type () const { return DECIMAL_RESULT; }
1430
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDECIMAL; }
1433
String *val_str(String*);
1434
my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
1435
{ return &decimal_value; }
1436
int save_in_field(Field *field, bool no_conversions);
1437
bool basic_const_item() const { return 1; }
1440
return new Item_decimal(name, &decimal_value, decimals, max_length);
1442
virtual void print(String *str, enum_query_type query_type);
1445
my_decimal_neg(&decimal_value);
1446
unsigned_flag= !decimal_value.sign();
1449
uint decimal_precision() const { return decimal_value.precision(); }
1450
bool eq(const Item *, bool binary_cmp) const;
1451
void set_decimal_value(my_decimal *value_par);
1455
class Item_float :public Item_num
1460
// Item_real() :value(0) {}
1461
Item_float(const char *str_arg, uint length);
1462
Item_float(const char *str,double val_arg,uint decimal_par,uint length)
1465
presentation= name=(char*) str;
1466
decimals=(uint8_t) decimal_par;
1470
Item_float(double value_par, uint decimal_par) :presentation(0), value(value_par)
1472
decimals= (uint8_t) decimal_par;
1475
int save_in_field(Field *field, bool no_conversions);
1476
enum Type type() const { return REAL_ITEM; }
1477
enum_field_types field_type() const { return DRIZZLE_TYPE_DOUBLE; }
1478
double val_real() { assert(fixed == 1); return value; }
1482
if (value <= (double) INT64_MIN)
1486
else if (value >= (double) (uint64_t) INT64_MAX)
1490
return (int64_t) rint(value);
1492
String *val_str(String*);
1493
my_decimal *val_decimal(my_decimal *);
1494
bool basic_const_item() const { return 1; }
1496
{ return new Item_float(name, value, decimals, max_length); }
1497
Item_num *neg() { value= -value; return this; }
1498
virtual void print(String *str, enum_query_type query_type);
1499
bool eq(const Item *, bool binary_cmp) const;
1503
class Item_static_float_func :public Item_float
1505
const char *func_name;
1507
Item_static_float_func(const char *str, double val_arg, uint decimal_par,
1509
:Item_float(NullS, val_arg, decimal_par, length), func_name(str)
1512
virtual inline void print(String *str,
1513
enum_query_type query_type __attribute__((unused)))
1515
str->append(func_name);
1518
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1522
class Item_string :public Item_basic_constant
1525
Item_string(const char *str,uint length,
1526
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE,
1527
uint repertoire= MY_REPERTOIRE_UNICODE30)
1528
: m_cs_specified(false)
1530
str_value.set_or_copy_aligned(str, length, cs);
1531
collation.set(cs, dv, repertoire);
1533
We have to have a different max_length than 'length' here to
1534
ensure that we get the right length if we do use the item
1535
to create a new table. In this case max_length must be the maximum
1536
number of chars for a string of this type because we in Create_field::
1537
divide the max_length with mbmaxlen).
1539
max_length= str_value.numchars()*cs->mbmaxlen;
1540
set_name(str, length, cs);
1541
decimals=NOT_FIXED_DEC;
1542
// it is constant => can be used without fix_fields (and frequently used)
1545
/* Just create an item and do not fill string representation */
1546
Item_string(const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
1547
: m_cs_specified(false)
1549
collation.set(cs, dv);
1551
set_name(NULL, 0, cs);
1552
decimals= NOT_FIXED_DEC;
1555
Item_string(const char *name_par, const char *str, uint length,
1556
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE,
1557
uint repertoire= MY_REPERTOIRE_UNICODE30)
1558
: m_cs_specified(false)
1560
str_value.set_or_copy_aligned(str, length, cs);
1561
collation.set(cs, dv, repertoire);
1562
max_length= str_value.numchars()*cs->mbmaxlen;
1563
set_name(name_par, 0, cs);
1564
decimals=NOT_FIXED_DEC;
1565
// it is constant => can be used without fix_fields (and frequently used)
1569
This is used in stored procedures to avoid memory leaks and
1570
does a deep copy of its argument.
1572
void set_str_with_copy(const char *str_arg, uint length_arg)
1574
str_value.copy(str_arg, length_arg, collation.collation);
1575
max_length= str_value.numchars() * collation.collation->mbmaxlen;
1577
void set_repertoire_from_value()
1579
collation.repertoire= my_string_repertoire(str_value.charset(),
1581
str_value.length());
1583
enum Type type() const { return STRING_ITEM; }
1586
String *val_str(String*)
1589
return (String*) &str_value;
1591
my_decimal *val_decimal(my_decimal *);
1592
int save_in_field(Field *field, bool no_conversions);
1593
enum Item_result result_type () const { return STRING_RESULT; }
1594
enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
1595
bool basic_const_item() const { return 1; }
1596
bool eq(const Item *item, bool binary_cmp) const;
1599
return new Item_string(name, str_value.ptr(),
1600
str_value.length(), collation.collation);
1602
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1603
inline void append(char *str, uint length)
1605
str_value.append(str, length);
1606
max_length= str_value.numchars() * collation.collation->mbmaxlen;
1608
virtual void print(String *str, enum_query_type query_type);
1611
Return true if character-set-introducer was explicitly specified in the
1612
original query for this item (text literal).
1614
This operation is to be called from Item_string::print(). The idea is
1615
that when a query is generated (re-constructed) from the Item-tree,
1616
character-set-introducers should appear only for those literals, where
1617
they were explicitly specified by the user. Otherwise, that may lead to
1618
loss collation information (character set introducers implies default
1619
collation for the literal).
1621
Basically, that makes sense only for views and hopefully will be gone
1622
one day when we start using original query as a view definition.
1624
@return This operation returns the value of m_cs_specified attribute.
1625
@retval true if character set introducer was explicitly specified in
1627
@retval false otherwise.
1629
inline bool is_cs_specified() const
1631
return m_cs_specified;
1635
Set the value of m_cs_specified attribute.
1637
m_cs_specified attribute shows whether character-set-introducer was
1638
explicitly specified in the original query for this text literal or
1639
not. The attribute makes sense (is used) only for views.
1641
This operation is to be called from the parser during parsing an input
1644
inline void set_cs_specified(bool cs_specified)
1646
m_cs_specified= cs_specified;
1650
bool m_cs_specified;
1654
class Item_static_string_func :public Item_string
1656
const char *func_name;
1658
Item_static_string_func(const char *name_par, const char *str, uint length,
1659
const CHARSET_INFO * const cs,
1660
Derivation dv= DERIVATION_COERCIBLE)
1661
:Item_string(NullS, str, length, cs, dv), func_name(name_par)
1663
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1665
virtual inline void print(String *str,
1666
enum_query_type query_type __attribute__((unused)))
1668
str->append(func_name);
1673
/* for show tables */
1674
class Item_return_date_time :public Item_string
1676
enum_field_types date_time_field_type;
1678
Item_return_date_time(const char *name_arg, enum_field_types field_type_arg)
1679
:Item_string(name_arg, 0, &my_charset_bin),
1680
date_time_field_type(field_type_arg)
1682
enum_field_types field_type() const { return date_time_field_type; }
1686
class Item_blob :public Item_string
1689
Item_blob(const char *name, uint length) :
1690
Item_string(name, length, &my_charset_bin)
1691
{ max_length= length; }
1692
enum Type type() const { return TYPE_HOLDER; }
1693
enum_field_types field_type() const { return DRIZZLE_TYPE_BLOB; }
1698
Item_empty_string -- is a utility class to put an item into List<Item>
1699
which is then used in protocol.send_fields() when sending SHOW output to
1703
class Item_empty_string :public Item_string
1706
Item_empty_string(const char *header,uint length, const CHARSET_INFO * cs= NULL) :
1707
Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
1708
{ name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
1709
void make_field(Send_field *field);
1713
class Item_return_int :public Item_int
1715
enum_field_types int_field_type;
1717
Item_return_int(const char *name_arg, uint length,
1718
enum_field_types field_type_arg, int64_t value= 0)
1719
:Item_int(name_arg, value, length), int_field_type(field_type_arg)
1723
enum_field_types field_type() const { return int_field_type; }
1727
class Item_hex_string: public Item_basic_constant
1730
Item_hex_string() {}
1731
Item_hex_string(const char *str,uint str_length);
1732
enum Type type() const { return VARBIN_ITEM; }
1736
return (double) (uint64_t) Item_hex_string::val_int();
1739
bool basic_const_item() const { return 1; }
1740
String *val_str(String*) { assert(fixed == 1); return &str_value; }
1741
my_decimal *val_decimal(my_decimal *);
1742
int save_in_field(Field *field, bool no_conversions);
1743
enum Item_result result_type () const { return STRING_RESULT; }
1744
enum Item_result cast_to_int_type() const { return INT_RESULT; }
1745
enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
1746
virtual void print(String *str, enum_query_type query_type);
1747
bool eq(const Item *item, bool binary_cmp) const;
1748
virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1752
class Item_bin_string: public Item_hex_string
1755
Item_bin_string(const char *str,uint str_length);
1758
class Item_result_field :public Item /* Item with result field */
1761
Field *result_field; /* Save result here */
1762
Item_result_field() :result_field(0) {}
1763
// Constructor used for Item_sum/Item_cond_and/or (see Item comment)
1764
Item_result_field(THD *thd, Item_result_field *item):
1765
Item(thd, item), result_field(item->result_field)
1767
~Item_result_field() {} /* Required with gcc 2.95 */
1768
Field *get_tmp_table_field() { return result_field; }
1769
Field *tmp_table_field(Table *t_arg __attribute__((unused)))
1770
{ return result_field; }
1771
table_map used_tables() const { return 1; }
1772
virtual void fix_length_and_dec()=0;
1773
void set_result_field(Field *field) { result_field= field; }
1774
bool is_result_field() { return 1; }
1775
void save_in_result_field(bool no_conversions)
1777
save_in_field(result_field, no_conversions);
1783
class Item_ref :public Item_ident
1786
void set_properties();
1788
enum Ref_Type { REF, DIRECT_REF, VIEW_REF, OUTER_REF };
1789
Field *result_field; /* Save result here */
1791
Item_ref(Name_resolution_context *context_arg,
1792
const char *db_arg, const char *table_name_arg,
1793
const char *field_name_arg)
1794
:Item_ident(context_arg, db_arg, table_name_arg, field_name_arg),
1795
result_field(0), ref(0) {}
1797
This constructor is used in two scenarios:
1799
No initialization is performed, fix_fields() call will be necessary.
1801
B) *item points to an Item this Item_ref will refer to. This is
1802
used for GROUP BY. fix_fields() will not be called in this case,
1803
so we call set_properties to make this item "fixed". set_properties
1804
performs a subset of action Item_ref::fix_fields does, and this subset
1805
is enough for Item_ref's used in GROUP BY.
1807
TODO we probably fix a superset of problems like in BUG#6658. Check this
1808
with Bar, and if we have a more broader set of problems like this.
1810
Item_ref(Name_resolution_context *context_arg, Item **item,
1811
const char *table_name_arg, const char *field_name_arg,
1812
bool alias_name_used_arg= false);
1814
/* Constructor need to process subselect with temporary tables (see Item) */
1815
Item_ref(THD *thd, Item_ref *item)
1816
:Item_ident(thd, item), result_field(item->result_field), ref(item->ref) {}
1817
enum Type type() const { return REF_ITEM; }
1818
bool eq(const Item *item, bool binary_cmp) const
1820
Item *it= ((Item *) item)->real_item();
1821
return ref && (*ref)->eq(it, binary_cmp);
1825
my_decimal *val_decimal(my_decimal *);
1827
String *val_str(String* tmp);
1829
bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
1830
double val_result();
1831
int64_t val_int_result();
1832
String *str_result(String* tmp);
1833
my_decimal *val_decimal_result(my_decimal *);
1834
bool val_bool_result();
1835
bool send(Protocol *prot, String *tmp);
1836
void make_field(Send_field *field);
1837
bool fix_fields(THD *, Item **);
1838
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
1839
int save_in_field(Field *field, bool no_conversions);
1840
void save_org_in_field(Field *field);
1841
enum Item_result result_type () const { return (*ref)->result_type(); }
1842
enum_field_types field_type() const { return (*ref)->field_type(); }
1843
Field *get_tmp_table_field()
1844
{ return result_field ? result_field : (*ref)->get_tmp_table_field(); }
1845
Item *get_tmp_table_item(THD *thd);
1846
table_map used_tables() const
1848
return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
1850
void update_used_tables()
1853
(*ref)->update_used_tables();
1855
table_map not_null_tables() const { return (*ref)->not_null_tables(); }
1856
void set_result_field(Field *field) { result_field= field; }
1857
bool is_result_field() { return 1; }
1858
void save_in_result_field(bool no_conversions)
1860
(*ref)->save_in_field(result_field, no_conversions);
1864
return ref ? (*ref)->real_item() : this;
1866
bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
1867
{ return (*ref)->walk(processor, walk_subquery, arg); }
1868
virtual void print(String *str, enum_query_type query_type);
1869
bool result_as_int64_t()
1871
return (*ref)->result_as_int64_t();
1874
Item_field *filed_for_view_update()
1875
{ return (*ref)->filed_for_view_update(); }
1876
virtual Ref_Type ref_type() { return REF; }
1878
// Row emulation: forwarding of ROW-related calls to ref
1881
return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
1883
Item* element_index(uint i)
1885
return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
1889
return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
1891
bool check_cols(uint c)
1893
return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
1894
: Item::check_cols(c);
1898
return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
1902
if (ref && result_type() == ROW_RESULT)
1903
(*ref)->bring_value();
1910
The same as Item_ref, but get value from val_* family of method to get
1911
value of item on which it referred instead of result* family.
1913
class Item_direct_ref :public Item_ref
1916
Item_direct_ref(Name_resolution_context *context_arg, Item **item,
1917
const char *table_name_arg,
1918
const char *field_name_arg,
1919
bool alias_name_used_arg= false)
1920
:Item_ref(context_arg, item, table_name_arg,
1921
field_name_arg, alias_name_used_arg)
1923
/* Constructor need to process subselect with temporary tables (see Item) */
1924
Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
1928
String *val_str(String* tmp);
1929
my_decimal *val_decimal(my_decimal *);
1932
bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
1933
virtual Ref_Type ref_type() { return DIRECT_REF; }
1937
Class for view fields, the same as Item_direct_ref, but call fix_fields
1938
of reference if it is not called yet
1940
class Item_direct_view_ref :public Item_direct_ref
1943
Item_direct_view_ref(Name_resolution_context *context_arg, Item **item,
1944
const char *table_name_arg,
1945
const char *field_name_arg)
1946
:Item_direct_ref(context_arg, item, table_name_arg, field_name_arg) {}
1947
/* Constructor need to process subselect with temporary tables (see Item) */
1948
Item_direct_view_ref(THD *thd, Item_direct_ref *item)
1949
:Item_direct_ref(thd, item) {}
1951
bool fix_fields(THD *, Item **);
1952
bool eq(const Item *item, bool binary_cmp) const;
1953
Item *get_tmp_table_item(THD *thd)
1955
Item *item= Item_ref::get_tmp_table_item(thd);
1959
virtual Ref_Type ref_type() { return VIEW_REF; }
1964
Class for outer fields.
1965
An object of this class is created when the select where the outer field was
1966
resolved is a grouping one. After it has been fixed the ref field will point
1967
to either an Item_ref or an Item_direct_ref object which will be used to
1969
See also comments for the fix_inner_refs() and the
1970
Item_field::fix_outer_field() functions.
1974
class Item_outer_ref :public Item_direct_ref
1978
/* The aggregate function under which this outer ref is used, if any. */
1979
Item_sum *in_sum_func;
1981
true <=> that the outer_ref is already present in the select list
1982
of the outer select.
1984
bool found_in_select_list;
1985
Item_outer_ref(Name_resolution_context *context_arg,
1986
Item_field *outer_field_arg)
1987
:Item_direct_ref(context_arg, 0, outer_field_arg->table_name,
1988
outer_field_arg->field_name),
1989
outer_ref(outer_field_arg), in_sum_func(0),
1990
found_in_select_list(0)
1996
Item_outer_ref(Name_resolution_context *context_arg, Item **item,
1997
const char *table_name_arg, const char *field_name_arg,
1998
bool alias_name_used_arg)
1999
:Item_direct_ref(context_arg, item, table_name_arg, field_name_arg,
2000
alias_name_used_arg),
2001
outer_ref(0), in_sum_func(0), found_in_select_list(1)
2003
void save_in_result_field(bool no_conversions __attribute__((unused)))
2005
outer_ref->save_org_in_field(result_field);
2007
bool fix_fields(THD *, Item **);
2008
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
2009
table_map used_tables() const
2011
return (*ref)->const_item() ? 0 : OUTER_REF_TABLE_BIT;
2013
virtual Ref_Type ref_type() { return OUTER_REF; }
2017
class Item_in_subselect;
2021
An object of this class:
2022
- Converts val_XXX() calls to ref->val_XXX_result() calls, like Item_ref.
2023
- Sets owner->was_null=true if it has returned a NULL value from any
2024
val_XXX() function. This allows to inject an Item_ref_null_helper
2025
object into subquery and then check if the subquery has produced a row
2029
class Item_ref_null_helper: public Item_ref
2032
Item_in_subselect* owner;
2034
Item_ref_null_helper(Name_resolution_context *context_arg,
2035
Item_in_subselect* master, Item **item,
2036
const char *table_name_arg, const char *field_name_arg)
2037
:Item_ref(context_arg, item, table_name_arg, field_name_arg),
2041
String* val_str(String* s);
2042
my_decimal *val_decimal(my_decimal *);
2044
bool get_date(DRIZZLE_TIME *ltime, uint fuzzydate);
2045
virtual void print(String *str, enum_query_type query_type);
2047
we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
2049
table_map used_tables() const
2051
return (depended_from ?
2052
OUTER_REF_TABLE_BIT :
2053
(*ref)->used_tables() | RAND_TABLE_BIT);
2058
The following class is used to optimize comparing of date and bigint columns
2059
We need to save the original item ('ref') to be able to call
2060
ref->save_in_field(). This is used to create index search keys.
2062
An instance of Item_int_with_ref may have signed or unsigned integer value.
2066
class Item_int_with_ref :public Item_int
2070
Item_int_with_ref(int64_t i, Item *ref_arg, bool unsigned_arg) :
2071
Item_int(i), ref(ref_arg)
2073
unsigned_flag= unsigned_arg;
2075
int save_in_field(Field *field, bool no_conversions)
2077
return ref->save_in_field(field, no_conversions);
2080
virtual Item *real_item() { return ref; }
2083
#ifdef DRIZZLE_SERVER
2084
#include "item_sum.h"
2085
#include "item_func.h"
2086
#include "item_row.h"
2087
#include "item_cmpfunc.h"
2088
#include "item_strfunc.h"
2089
#include "item_timefunc.h"
2090
#include "item_subselect.h"
2093
class Item_copy_string :public Item
2095
enum enum_field_types cached_field_type;
2098
Item_copy_string(Item *i) :item(i)
2100
null_value= maybe_null= item->maybe_null;
2101
decimals=item->decimals;
2102
max_length=item->max_length;
2104
cached_field_type= item->field_type();
2106
enum Type type() const { return COPY_STR_ITEM; }
2107
enum Item_result result_type () const { return STRING_RESULT; }
2108
enum_field_types field_type() const { return cached_field_type; }
2113
return (null_value ? 0.0 :
2114
my_strntod(str_value.charset(), (char*) str_value.ptr(),
2115
str_value.length(), &end_not_used, &err_not_used));
2120
return null_value ? 0LL : my_strntoll(str_value.charset(),str_value.ptr(),
2121
str_value.length(),10, (char**) 0,
2124
String *val_str(String*);
2125
my_decimal *val_decimal(my_decimal *);
2126
void make_field(Send_field *field) { item->make_field(field); }
2128
int save_in_field(Field *field,
2129
bool no_conversions __attribute__((unused)))
2131
return save_str_value_in_field(field, &str_value);
2133
table_map used_tables() const { return (table_map) 1L; }
2134
bool const_item() const { return 0; }
2135
bool is_null() { return null_value; }
2139
class Cached_item :public Sql_alloc
2143
Cached_item() :null_value(0) {}
2144
virtual bool cmp(void)=0;
2145
virtual ~Cached_item(); /*line -e1509 */
2148
class Cached_item_str :public Cached_item
2151
String value,tmp_value;
2153
Cached_item_str(THD *thd, Item *arg);
2155
~Cached_item_str(); // Deallocate String:s
2159
class Cached_item_real :public Cached_item
2164
Cached_item_real(Item *item_par) :item(item_par),value(0.0) {}
2168
class Cached_item_int :public Cached_item
2173
Cached_item_int(Item *item_par) :item(item_par),value(0) {}
2178
class Cached_item_decimal :public Cached_item
2183
Cached_item_decimal(Item *item_par);
2187
class Cached_item_field :public Cached_item
2194
Cached_item_field(Field *arg_field) : field(arg_field)
2197
/* TODO: take the memory allocation below out of the constructor. */
2198
buff= (uchar*) sql_calloc(length=field->pack_length());
2203
class Item_default_value : public Item_field
2207
Item_default_value(Name_resolution_context *context_arg)
2208
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
2209
(const char *)NULL),
2211
Item_default_value(Name_resolution_context *context_arg, Item *a)
2212
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
2213
(const char *)NULL),
2215
enum Type type() const { return DEFAULT_VALUE_ITEM; }
2216
bool eq(const Item *item, bool binary_cmp) const;
2217
bool fix_fields(THD *, Item **);
2218
virtual void print(String *str, enum_query_type query_type);
2219
int save_in_field(Field *field_arg, bool no_conversions);
2220
table_map used_tables() const { return (table_map)0L; }
2222
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2224
return arg->walk(processor, walk_subquery, args) ||
2225
(this->*processor)(args);
2228
Item *transform(Item_transformer transformer, uchar *args);
2232
Item_insert_value -- an implementation of VALUES() function.
2233
You can use the VALUES(col_name) function in the UPDATE clause
2234
to refer to column values from the INSERT portion of the INSERT
2235
... UPDATE statement. In other words, VALUES(col_name) in the
2236
UPDATE clause refers to the value of col_name that would be
2237
inserted, had no duplicate-key conflict occurred.
2238
In all other places this function returns NULL.
2241
class Item_insert_value : public Item_field
2245
Item_insert_value(Name_resolution_context *context_arg, Item *a)
2246
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
2247
(const char *)NULL),
2249
bool eq(const Item *item, bool binary_cmp) const;
2250
bool fix_fields(THD *, Item **);
2251
virtual void print(String *str, enum_query_type query_type);
2252
int save_in_field(Field *field_arg, bool no_conversions)
2254
return Item_field::save_in_field(field_arg, no_conversions);
2257
We use RAND_TABLE_BIT to prevent Item_insert_value from
2258
being treated as a constant and precalculated before execution
2260
table_map used_tables() const { return RAND_TABLE_BIT; }
2262
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2264
return arg->walk(processor, walk_subquery, args) ||
2265
(this->*processor)(args);
2270
class Item_cache: public Item_basic_constant
2274
table_map used_table_map;
2276
Field that this object will get value from. This is set/used by
2277
index-based subquery engines to detect and remove the equality injected
2278
by IN->EXISTS transformation.
2279
For all other uses of Item_cache, cached_field doesn't matter.
2281
Field *cached_field;
2282
enum enum_field_types cached_field_type;
2285
example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR)
2290
Item_cache(enum_field_types field_type_arg):
2291
example(0), used_table_map(0), cached_field(0), cached_field_type(field_type_arg)
2297
void set_used_tables(table_map map) { used_table_map= map; }
2299
virtual bool allocate(uint i __attribute__((unused)))
2301
virtual bool setup(Item *item)
2304
max_length= item->max_length;
2305
decimals= item->decimals;
2306
collation.set(item->collation);
2307
unsigned_flag= item->unsigned_flag;
2308
if (item->type() == FIELD_ITEM)
2309
cached_field= ((Item_field *)item)->field;
2312
virtual void store(Item *)= 0;
2313
enum Type type() const { return CACHE_ITEM; }
2314
enum_field_types field_type() const { return cached_field_type; }
2315
static Item_cache* get_cache(const Item *item);
2316
table_map used_tables() const { return used_table_map; }
2317
virtual void keep_array() {}
2318
virtual void print(String *str, enum_query_type query_type);
2319
bool eq_def(Field *field)
2321
return cached_field ? cached_field->eq_def (field) : false;
2323
bool eq(const Item *item,
2324
bool binary_cmp __attribute__((unused))) const
2326
return this == item;
2331
class Item_cache_int: public Item_cache
2336
Item_cache_int(): Item_cache(), value(0) {}
2337
Item_cache_int(enum_field_types field_type_arg):
2338
Item_cache(field_type_arg), value(0) {}
2340
void store(Item *item);
2341
void store(Item *item, int64_t val_arg);
2342
double val_real() { assert(fixed == 1); return (double) value; }
2343
int64_t val_int() { assert(fixed == 1); return value; }
2344
String* val_str(String *str);
2345
my_decimal *val_decimal(my_decimal *);
2346
enum Item_result result_type() const { return INT_RESULT; }
2347
bool result_as_int64_t() { return true; }
2351
class Item_cache_real: public Item_cache
2355
Item_cache_real(): Item_cache(), value(0) {}
2357
void store(Item *item);
2358
double val_real() { assert(fixed == 1); return value; }
2360
String* val_str(String *str);
2361
my_decimal *val_decimal(my_decimal *);
2362
enum Item_result result_type() const { return REAL_RESULT; }
2366
class Item_cache_decimal: public Item_cache
2369
my_decimal decimal_value;
2371
Item_cache_decimal(): Item_cache() {}
2373
void store(Item *item);
2376
String* val_str(String *str);
2377
my_decimal *val_decimal(my_decimal *);
2378
enum Item_result result_type() const { return DECIMAL_RESULT; }
2382
class Item_cache_str: public Item_cache
2384
char buffer[STRING_BUFFER_USUAL_SIZE];
2385
String *value, value_buff;
2389
Item_cache_str(const Item *item) :
2390
Item_cache(), value(0),
2391
is_varbinary(item->type() == FIELD_ITEM &&
2392
((const Item_field *) item)->field->type() ==
2393
DRIZZLE_TYPE_VARCHAR &&
2394
!((const Item_field *) item)->field->has_charset())
2396
void store(Item *item);
2399
String* val_str(String *) { assert(fixed == 1); return value; }
2400
my_decimal *val_decimal(my_decimal *);
2401
enum Item_result result_type() const { return STRING_RESULT; }
2402
const CHARSET_INFO *charset() const { return value->charset(); };
2403
int save_in_field(Field *field, bool no_conversions);
2406
class Item_cache_row: public Item_cache
2408
Item_cache **values;
2413
:Item_cache(), values(0), item_count(2), save_array(0) {}
2416
'allocate' used only in row transformer, to preallocate space for row
2419
bool allocate(uint num);
2421
'setup' is needed only by row => it not called by simple row subselect
2422
(only by IN subselect (in subselect optimizer))
2424
bool setup(Item *item);
2425
void store(Item *item);
2426
void illegal_method_call(const char *);
2427
void make_field(Send_field *)
2429
illegal_method_call((const char*)"make_field");
2433
illegal_method_call((const char*)"val");
2438
illegal_method_call((const char*)"val_int");
2441
String *val_str(String *)
2443
illegal_method_call((const char*)"val_str");
2446
my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
2448
illegal_method_call((const char*)"val_decimal");
2452
enum Item_result result_type() const { return ROW_RESULT; }
2454
uint cols() { return item_count; }
2455
Item *element_index(uint i) { return values[i]; }
2456
Item **addr(uint i) { return (Item **) (values + i); }
2457
bool check_cols(uint c);
2460
void keep_array() { save_array= 1; }
2463
Item_cache::cleanup();
2465
memset(values, 0, item_count*sizeof(Item**));
2474
Item_type_holder used to store type. name, length of Item for UNIONS &
2477
Item_type_holder do not need cleanup() because its time of live limited by
2478
single SP/PS execution.
2480
class Item_type_holder: public Item
2483
TYPELIB *enum_set_typelib;
2484
enum_field_types fld_type;
2486
void get_full_info(Item *item);
2488
/* It is used to count decimal precision in join_types */
2489
int prev_decimal_int_part;
2491
Item_type_holder(THD*, Item*);
2493
Item_result result_type() const;
2494
enum_field_types field_type() const { return fld_type; };
2495
enum Type type() const { return TYPE_HOLDER; }
2498
my_decimal *val_decimal(my_decimal *);
2499
String *val_str(String*);
2500
bool join_types(THD *thd, Item *);
2501
Field *make_field_by_type(Table *table);
2502
static uint32_t display_length(Item *item);
2503
static enum_field_types get_real_type(Item *);
2507
class st_select_lex;
2508
void mark_select_range_as_dependent(THD *thd,
2509
st_select_lex *last_select,
2510
st_select_lex *current_sel,
846
2511
Field *found_field, Item *found_item,
847
2512
Item_ident *resolved_item);
849
extern void resolve_const_item(Session *session, Item **ref, Item *cmp_item);
851
Return true if the value stored in the field is equal to the const
854
We need to use this on the range optimizer because in some cases
855
we can't store the value in the field without some precision/character loss.
2514
extern Cached_item *new_Cached_item(THD *thd, Item *item,
2515
bool use_result_field);
2516
extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
857
2517
extern bool field_is_equal_to_item(Field *field,Item *item);
860
Create field for temporary table.
864
This is here for now because it needs the Item::Type. It should live
865
in Field or Table once item.h is clean enough to actually include
867
@param session Thread handler
868
@param table Temporary table
869
@param item Item to create a field for
870
@param type Type of item (normally item->type)
871
@param copy_func If set and item is a function, store copy of item
873
@param from_field if field will be created using other field as example,
874
pointer example field will be written here
875
@param default_field If field has a default value field, store it here
876
@param group 1 if we are going to do a relative group by on result
877
@param modify_item 1 if item->result_field should point to new item.
878
This is relevent for how fill_record() is going to
880
If modify_item is 1 then fill_record() will update
881
the record in the original table.
882
If modify_item is 0 then fill_record() will update
884
@param convert_blob_length If >0 create a varstring(convert_blob_length)
885
field instead of blob.
892
Field *create_tmp_field(Session *session,
901
bool make_copy_field,
902
uint32_t convert_blob_length);
904
} /* namespace drizzled */
906
#endif /* DRIZZLED_ITEM_H */