17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#ifndef DRIZZLED_ITEM_H
23
#define DRIZZLED_ITEM_H
25
#include <drizzled/dtcollation.h>
26
#include <drizzled/global_charset_info.h>
27
#include <drizzled/item_result.h>
28
#include <drizzled/memory/sql_alloc.h>
29
#include <drizzled/sql_list.h>
30
#include <drizzled/sql_string.h>
32
#include <drizzled/visibility.h>
20
#ifndef drizzled_item_h
21
#define drizzled_item_h
25
void item_init(void); /* Init item functions */
41
class Item_in_subselect;
48
namespace plugin { class Client; }
49
namespace type { class Time; }
50
namespace type { class Decimal; }
53
Dummy error processor used by default by Name_resolution_context.
58
void dummy_error_processor(Session *session, void *data);
29
"Declared Type Collation"
30
A combination of collation and its derivation.
32
Flags for collation aggregation modes:
33
MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
34
MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
36
MY_COLL_ALLOW_CONV - allow any kind of conversion
37
(combination of the above two)
38
MY_COLL_DISALLOW_NONE - don't allow return DERIVATION_NONE
39
(e.g. when aggregating for comparison)
40
MY_COLL_CMP_CONV - combination of MY_COLL_ALLOW_CONV
41
and MY_COLL_DISALLOW_NONE
44
#define MY_COLL_ALLOW_SUPERSET_CONV 1
45
#define MY_COLL_ALLOW_COERCIBLE_CONV 2
46
#define MY_COLL_ALLOW_CONV 3
47
#define MY_COLL_DISALLOW_NONE 4
48
#define MY_COLL_CMP_CONV 7
52
const CHARSET_INFO *collation;
53
enum Derivation derivation;
56
void set_repertoire_from_charset(const CHARSET_INFO * const cs)
58
repertoire= cs->state & MY_CS_PUREASCII ?
59
MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
63
collation= &my_charset_bin;
64
derivation= DERIVATION_NONE;
65
repertoire= MY_REPERTOIRE_UNICODE30;
67
DTCollation(const CHARSET_INFO * const collation_arg, Derivation derivation_arg)
69
collation= collation_arg;
70
derivation= derivation_arg;
71
set_repertoire_from_charset(collation_arg);
73
void set(DTCollation &dt)
75
collation= dt.collation;
76
derivation= dt.derivation;
77
repertoire= dt.repertoire;
79
void set(const CHARSET_INFO * const collation_arg, Derivation derivation_arg)
81
collation= collation_arg;
82
derivation= derivation_arg;
83
set_repertoire_from_charset(collation_arg);
85
void set(const CHARSET_INFO * const collation_arg,
86
Derivation derivation_arg,
87
uint32_t repertoire_arg)
89
collation= collation_arg;
90
derivation= derivation_arg;
91
repertoire= repertoire_arg;
93
void set(const CHARSET_INFO * const collation_arg)
95
collation= collation_arg;
96
set_repertoire_from_charset(collation_arg);
98
void set(Derivation derivation_arg)
99
{ derivation= derivation_arg; }
100
bool aggregate(DTCollation &dt, uint32_t flags= 0);
101
bool set(DTCollation &dt1, DTCollation &dt2, uint32_t flags= 0)
102
{ set(dt1); return aggregate(dt2, flags); }
103
const char *derivation_name() const
107
case DERIVATION_IGNORABLE: return "IGNORABLE";
108
case DERIVATION_COERCIBLE: return "COERCIBLE";
109
case DERIVATION_IMPLICIT: return "IMPLICIT";
110
case DERIVATION_SYSCONST: return "SYSCONST";
111
case DERIVATION_EXPLICIT: return "EXPLICIT";
112
case DERIVATION_NONE: return "NONE";
113
default: return "UNKNOWN";
118
/*************************************************************************/
120
A framework to easily handle different return types for hybrid items
121
(hybrid item is an item whose operand can be of any type, e.g. integer,
125
struct Hybrid_type_traits;
133
Use two decimal buffers interchangeably to speed up += operation
134
which has no native support in decimal library.
135
Hybrid_type+= arg is implemented as dec_buf[1]= dec_buf[0] + arg.
136
The third decimal is used as a handy temporary storage.
138
my_decimal dec_buf[3];
142
Traits moved to a separate class to
143
a) be able to easily change object traits in runtime
144
b) they work as a differentiator for the union above
146
const Hybrid_type_traits *traits;
149
/* XXX: add traits->copy() when needed */
150
Hybrid_type(const Hybrid_type &rhs) :traits(rhs.traits) {}
154
/* Hybryd_type_traits interface + default implementation for REAL_RESULT */
156
struct Hybrid_type_traits
158
virtual Item_result type() const { return REAL_RESULT; }
161
fix_length_and_dec(Item *item, Item *arg) const;
163
/* Hybrid_type operations. */
164
virtual void set_zero(Hybrid_type *val) const { val->real= 0.0; }
165
virtual void add(Hybrid_type *val, Field *f) const
166
{ val->real+= f->val_real(); }
167
virtual void div(Hybrid_type *val, uint64_t u) const
168
{ val->real/= uint64_t2double(u); }
170
virtual int64_t val_int(Hybrid_type *val,
171
bool unsigned_flag __attribute__((unused))) const
172
{ return (int64_t) rint(val->real); }
173
virtual double val_real(Hybrid_type *val) const { return val->real; }
174
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const;
175
virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
176
static const Hybrid_type_traits *instance();
177
Hybrid_type_traits() {}
178
virtual ~Hybrid_type_traits() {}
182
struct Hybrid_type_traits_decimal: public Hybrid_type_traits
184
virtual Item_result type() const { return DECIMAL_RESULT; }
187
fix_length_and_dec(Item *arg, Item *item) const;
189
/* Hybrid_type operations. */
190
virtual void set_zero(Hybrid_type *val) const;
191
virtual void add(Hybrid_type *val, Field *f) const;
192
virtual void div(Hybrid_type *val, uint64_t u) const;
194
virtual int64_t val_int(Hybrid_type *val, bool unsigned_flag) const;
195
virtual double val_real(Hybrid_type *val) const;
196
virtual my_decimal *val_decimal(Hybrid_type *val,
197
my_decimal *buf __attribute__((unused))) const
198
{ return &val->dec_buf[val->used_dec_buf_no]; }
199
virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
200
static const Hybrid_type_traits_decimal *instance();
201
Hybrid_type_traits_decimal() {};
205
struct Hybrid_type_traits_integer: public Hybrid_type_traits
207
virtual Item_result type() const { return INT_RESULT; }
210
fix_length_and_dec(Item *arg, Item *item) const;
212
/* Hybrid_type operations. */
213
virtual void set_zero(Hybrid_type *val) const
215
virtual void add(Hybrid_type *val, Field *f) const
216
{ val->integer+= f->val_int(); }
217
virtual void div(Hybrid_type *val, uint64_t u) const
218
{ val->integer/= (int64_t) u; }
220
virtual int64_t val_int(Hybrid_type *val,
221
bool unsigned_flag __attribute__((unused))) const
222
{ return val->integer; }
223
virtual double val_real(Hybrid_type *val) const
224
{ return (double) val->integer; }
225
virtual my_decimal *val_decimal(Hybrid_type *val,
226
my_decimal *buf __attribute__((unused))) const
228
int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
229
return &val->dec_buf[2];
231
virtual String *val_str(Hybrid_type *val, String *buf,
232
uint8_t decimals __attribute__((unused))) const
233
{ buf->set(val->integer, &my_charset_bin); return buf;}
234
static const Hybrid_type_traits_integer *instance();
235
Hybrid_type_traits_integer() {};
239
void dummy_error_processor(THD *thd, void *data);
241
void view_error_processor(THD *thd, void *data);
244
Instances of Name_resolution_context store the information necesary for
245
name resolution of Items and other context analysis of a query made in
248
This structure is a part of SELECT_LEX, a pointer to this structure is
249
assigned when an item is created (which happens mostly during parsing
250
(sql_yacc.yy)), but the structure itself will be initialized after parsing
253
TODO: move subquery of INSERT ... SELECT and CREATE ... SELECT to
254
separate SELECT_LEX which allow to remove tricks of changing this
255
structure before and after INSERT/CREATE and its SELECT to make correct
256
field name resolution.
258
struct Name_resolution_context: Sql_alloc
261
The name resolution context to search in when an Item cannot be
262
resolved in this context (the context of an outer select)
264
Name_resolution_context *outer_context;
267
List of tables used to resolve the items of this context. Usually these
268
are tables from the FROM clause of SELECT statement. The exceptions are
269
INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
270
subquery is not moved to a separate SELECT_LEX. For these types of
271
statements we have to change this member dynamically to ensure correct
272
name resolution of different parts of the statement.
274
TableList *table_list;
276
In most cases the two table references below replace 'table_list' above
277
for the purpose of name resolution. The first and last name resolution
278
table references allow us to search only in a sub-tree of the nested
279
join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
282
TableList *first_name_resolution_table;
284
Last table to search in the list of leaf table references that begins
285
with first_name_resolution_table.
287
TableList *last_name_resolution_table;
290
SELECT_LEX item belong to, in case of merged VIEW it can differ from
291
SELECT_LEX where item was created, so we can't use table_list/field_list
294
st_select_lex *select_lex;
297
Processor of errors caused during Item name resolving, now used only to
298
hide underlying tables in errors about views (i.e. it substitute some
301
void (*error_processor)(THD *, void *);
302
void *error_processor_data;
305
When true items are resolved in this context both against the
306
SELECT list and this->table_list. If false, items are resolved
307
only against this->table_list.
309
bool resolve_in_select_list;
312
Security context of this name resolution context. It's used for views
313
and is non-zero only if the view is defined with SQL SECURITY DEFINER.
315
Security_context *security_ctx;
317
Name_resolution_context()
318
:outer_context(0), table_list(0), select_lex(0),
319
error_processor_data(0),
325
resolve_in_select_list= false;
326
error_processor= &dummy_error_processor;
327
first_name_resolution_table= NULL;
328
last_name_resolution_table= NULL;
331
void resolve_in_table_list_only(TableList *tables)
333
table_list= first_name_resolution_table= tables;
334
resolve_in_select_list= false;
337
void process_error(THD *thd)
339
(*error_processor)(thd, error_processor_data);
345
Store and restore the current state of a name resolution context.
348
class Name_resolution_context_state
351
TableList *save_table_list;
352
TableList *save_first_name_resolution_table;
353
TableList *save_next_name_resolution_table;
354
bool save_resolve_in_select_list;
355
TableList *save_next_local;
358
Name_resolution_context_state() {} /* Remove gcc warning */
361
/* Save the state of a name resolution context. */
362
void save_state(Name_resolution_context *context, TableList *table_list)
364
save_table_list= context->table_list;
365
save_first_name_resolution_table= context->first_name_resolution_table;
366
save_resolve_in_select_list= context->resolve_in_select_list;
367
save_next_local= table_list->next_local;
368
save_next_name_resolution_table= table_list->next_name_resolution_table;
371
/* Restore a name resolution context from saved state. */
372
void restore_state(Name_resolution_context *context, TableList *table_list)
374
table_list->next_local= save_next_local;
375
table_list->next_name_resolution_table= save_next_name_resolution_table;
376
context->table_list= save_table_list;
377
context->first_name_resolution_table= save_first_name_resolution_table;
378
context->resolve_in_select_list= save_resolve_in_select_list;
381
TableList *get_first_name_resolution_table()
383
return save_first_name_resolution_table;
389
This enum is used to report information about monotonicity of function
390
represented by Item* tree.
391
Monotonicity is defined only for Item* trees that represent table
392
partitioning expressions (i.e. have no subselects/user vars/PS parameters
393
etc etc). An Item* tree is assumed to have the same monotonicity properties
394
as its correspoinding function F:
396
[signed] int64_t F(field1, field2, ...) {
397
put values of field_i into table record buffer;
398
return item->val_int();
402
At the moment function monotonicity is not well defined (and so may be
403
incorrect) for Item trees with parameters/return types that are different
404
from INT_RESULT, may be NULL, or are unsigned.
405
It will be possible to address this issue once the related partitioning bugs
406
(BUG#16002, BUG#15447, BUG#13436) are fixed.
409
typedef enum monotonicity_info
411
NON_MONOTONIC, /* none of the below holds */
412
MONOTONIC_INCREASING, /* F() is unary and (x < y) => (F(x) <= F(y)) */
413
MONOTONIC_STRICT_INCREASING /* F() is unary and (x < y) => (F(x) < F(y)) */
414
} enum_monotonicity_info;
416
/*************************************************************************/
417
typedef bool (Item::*Item_processor) (unsigned char *arg);
63
421
argp in/out IN: Analysis parameter
64
422
OUT: Parameter to be passed to the transformer
67
425
true Invoke the transformer
71
429
typedef bool (Item::*Item_analyzer) (unsigned char **argp);
72
430
typedef Item* (Item::*Item_transformer) (unsigned char *arg);
73
431
typedef void (*Cond_traverser) (const Item *item, void *arg);
74
typedef bool (Item::*Item_processor) (unsigned char *arg);
77
* The Item class is the base class for all items in the parsed
78
* statement "tree" or Lex. Each item represents something in the
81
class DRIZZLED_API Item : public memory::SqlAlloc
83
/* Prevent use of these */
436
Item(const Item &); /* Prevent use of these */
85
437
void operator=(Item &);
87
438
/* Cache of the result of is_expensive(). */
88
439
int8_t is_expensive_cache;
89
virtual bool is_expensive_processor(unsigned char *arg);
440
virtual bool is_expensive_processor(unsigned char *arg __attribute__((unused)))
113
ROW_ITEM, CACHE_ITEM,
133
* str_values's main purpose is to be used to cache the value in
444
static void *operator new(size_t size)
445
{ return sql_alloc(size); }
446
static void *operator new(size_t size, MEM_ROOT *mem_root)
447
{ return alloc_root(mem_root, size); }
448
static void operator delete(void *ptr __attribute__((unused)),
449
size_t size __attribute__((unused)))
450
{ TRASH(ptr, size); }
451
static void operator delete(void *ptr __attribute__((unused)),
452
MEM_ROOT *mem_root __attribute__((unused)))
455
enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM,
456
INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM,
457
COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM,
458
PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
459
FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
460
SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
461
PARAM_ITEM, DECIMAL_ITEM,
464
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
466
enum traverse_order { POSTFIX, PREFIX };
468
/* Reuse size, only used by SP local variable assignment, otherwize 0 */
472
str_values's main purpose is to be used to cache the value in
136
475
String str_value;
138
/** Name from select */
141
/** Length of name */
142
uint32_t name_length;
144
/** Original item name (if it was renamed) */
476
char * name; /* Name from select */
477
/* Original item name (if it was renamed)*/
147
480
uint32_t max_length;
481
uint32_t name_length; /* Length of name */
150
483
uint8_t decimals;
151
bool fixed; /**< If item fixed with fix_fields */
152
bool maybe_null; /**< True if item may be null */
153
bool null_value; /**< True if item is null */
484
bool maybe_null; /* If item may be null */
485
bool null_value; /* if item is null */
154
486
bool unsigned_flag;
156
bool is_unsigned() const
158
return unsigned_flag;
161
virtual bool negative() const
166
487
bool with_sum_func;
167
bool is_autogenerated_name; /**< indicates whether name of this Item was autogenerated or set by user */
170
* If this item is a subselect or some of its arguments is or contains a
171
* subselect. Computed by fix_fields.
488
bool fixed; /* If item fixed with fix_fields */
489
bool is_autogenerated_name; /* indicate was name of this Item
490
autogenerated or set by user */
174
491
DTCollation collation;
175
Item_result cmp_context; /**< Comparison context */
182
* Alloc & destruct is done as start of select using memory::sql_alloc
492
bool with_subselect; /* If this item is a subselect or some
493
of its arguments is or contains a
494
subselect. Computed by fix_fields. */
495
Item_result cmp_context; /* Comparison context */
496
// alloc & destruct is done as start of select using sql_alloc
187
* Constructor used by Item_field, Item_ref & aggregate (sum) functions.
189
* Used for duplicating lists in processing queries with temporary
192
* Also it used for Item_cond_and/Item_cond_or for creating
193
* top AND/OR structure of WHERE clause to protect it of
194
* optimisation changes in prepared statements
196
Item(Session *session, Item *item);
499
Constructor used by Item_field, Item_ref & aggregate (sum) functions.
500
Used for duplicating lists in processing queries with temporary
502
Also it used for Item_cond_and/Item_cond_or for creating
503
top AND/OR structure of WHERE clause to protect it of
504
optimisation changes in prepared statements
506
Item(THD *thd, Item *item);
200
509
#ifdef EXTRA_DEBUG
205
void set_name(const std::string &arg)
207
set_name(arg.c_str(), arg.length(), system_charset_info);
210
void set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs= system_charset_info);
212
* Renames item (used for views, cleanup() return original name).
214
* @param new_name new name of item;
513
void set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs);
216
514
void rename(char *new_name);
217
void init_make_field(SendField *tmp_field,enum enum_field_types type);
515
void init_make_field(Send_field *tmp_field,enum enum_field_types type);
218
516
virtual void cleanup();
219
virtual void make_field(SendField *field);
221
Create a field to hold a string value from an item.
223
If max_length > CONVERT_IF_BIGGER_TO_BLOB create a blob @n
224
If max_length > 0 create a varchar @n
225
If max_length == 0 create a CHAR(0)
227
@param table Table for which the field is created
517
virtual void make_field(Send_field *field);
229
518
Field *make_string_field(Table *table);
230
virtual bool fix_fields(Session *, Item **);
233
* Fix after some tables has been pulled out. Basically re-calculate all
234
* attributes that are dependent on the tables.
236
virtual void fix_after_pullout(Select_Lex *new_parent, Item **ref);
239
* Should be used in case where we are sure that we do not need
240
* complete fix_fields() procedure.
242
inline void quick_fix_field()
519
virtual bool fix_fields(THD *, Item **);
521
Fix after some tables has been pulled out. Basically re-calculate all
522
attributes that are dependent on the tables.
524
virtual void fix_after_pullout(st_select_lex *new_parent __attribute__((unused)),
525
Item **ref __attribute__((unused))) {};
528
should be used in case where we are sure that we do not need
529
complete fix_fields() procedure.
531
inline void quick_fix_field() { fixed= 1; }
532
/* Function returns 1 on overflow and -1 on fatal errors */
533
int save_in_field_no_warnings(Field *field, bool no_conversions);
247
534
virtual int save_in_field(Field *field, bool no_conversions);
248
535
virtual void save_org_in_field(Field *field)
250
(void) save_in_field(field, true);
536
{ (void) save_in_field(field, 1); }
252
537
virtual int save_safe_in_field(Field *field)
254
return save_in_field(field, true);
257
* This is only called from items that is not of type item_field.
259
virtual bool send(plugin::Client *client, String *str);
261
Compares this Item to another Item, returning true if Item's
262
are functionally equal.
266
This function is called when:
267
- Comparing items in the WHERE clause (when doing where optimization)
268
- When trying to find an order_st BY/GROUP BY item in the SELECT part
538
{ return save_in_field(field, 1); }
539
virtual bool send(Protocol *protocol, String *str);
270
540
virtual bool eq(const Item *, bool binary_cmp) const;
271
virtual Item_result result_type() const
275
virtual Item_result cast_to_int_type() const
277
return result_type();
541
virtual Item_result result_type() const { return REAL_RESULT; }
542
virtual Item_result cast_to_int_type() const { return result_type(); }
279
543
virtual enum_field_types string_field_type() const;
280
544
virtual enum_field_types field_type() const;
281
545
virtual enum Type type() const =0;
285
* "func_arg $CMP$ const" half-interval
287
* "FUNC(func_arg) $CMP2$ const2"
291
* left_endp false <=> The interval is "x < const" or "x <= const"
292
* true <=> The interval is "x > const" or "x >= const"
294
* incl_endp IN true <=> the comparison is '<' or '>'
295
* false <=> the comparison is '<=' or '>='
296
* OUT The same but for the "F(x) $CMP$ F(const)" comparison
298
* This function is defined only for unary monotonic functions. The caller
299
* supplies the source half-interval
303
* The value of const is supplied implicitly as the value this item's
304
* argument, the form of $CMP$ comparison is specified through the
305
* function's arguments. The calle returns the result interval
307
* F(x) $CMP2$ F(const)
309
* passing back F(const) as the return value, and the form of $CMP2$
310
* through the out parameter. NULL values are assumed to be comparable and
311
* be less than any non-NULL values.
315
* The output range bound, which equal to the value of val_int()
316
* - If the value of the function is NULL then the bound is the
317
* smallest possible value of INT64_MIN
319
virtual int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
548
Return information about function monotonicity. See comment for
549
enum_monotonicity_info for details. This function can only be called
550
after fix_fields() call.
552
virtual enum_monotonicity_info get_monotonicity_info() const
553
{ return NON_MONOTONIC; }
556
Convert "func_arg $CMP$ const" half-interval into "FUNC(func_arg) $CMP2$ const2"
560
left_endp false <=> The interval is "x < const" or "x <= const"
561
true <=> The interval is "x > const" or "x >= const"
563
incl_endp IN true <=> the comparison is '<' or '>'
564
false <=> the comparison is '<=' or '>='
565
OUT The same but for the "F(x) $CMP$ F(const)" comparison
568
This function is defined only for unary monotonic functions. The caller
569
supplies the source half-interval
573
The value of const is supplied implicitly as the value this item's
574
argument, the form of $CMP$ comparison is specified through the
575
function's arguments. The calle returns the result interval
579
passing back F(const) as the return value, and the form of $CMP2$
580
through the out parameter. NULL values are assumed to be comparable and
581
be less than any non-NULL values.
584
The output range bound, which equal to the value of val_int()
585
- If the value of the function is NULL then the bound is the
586
smallest possible value of INT64_MIN
588
virtual int64_t val_int_endpoint(bool left_endp __attribute__((unused)),
589
bool *incl_endp __attribute__((unused)))
590
{ assert(0); return 0; }
321
593
/* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */
323
* Returns double precision floating point representation of item.
327
* In case of NULL value return 0.0 and set null_value flag to true.
328
* If value is not null null_value flag will be reset to false.
595
Return double precision floating point representation of item.
601
In case of NULL value return 0.0 and set null_value flag to true.
602
If value is not null null_value flag will be reset to false.
330
604
virtual double val_real()=0;
332
* Returns integer representation of item.
336
* In case of NULL value return 0 and set null_value flag to true.
337
* If value is not null null_value flag will be reset to false.
606
Return integer representation of item.
612
In case of NULL value return 0 and set null_value flag to true.
613
If value is not null null_value flag will be reset to false.
339
615
virtual int64_t val_int()=0;
341
* This is just a shortcut to avoid the cast. You should still use
342
* unsigned_flag to check the sign of the item.
344
inline uint64_t val_uint()
346
return (uint64_t) val_int();
349
* Return string representation of this item object.
351
* @param an allocated buffer this or any nested Item object can use to
352
* store return value of this method.
356
* Buffer passed via argument should only be used if the item itself
357
* doesn't have an own String buffer. In case when the item maintains
358
* it's own string buffer, it's preferable to return it instead to
359
* minimize number of mallocs/memcpys.
361
* The caller of this method can modify returned string, but only in case
362
* when it was allocated on heap, (is_alloced() is true). This allows
363
* the caller to efficiently use a buffer allocated by a child without
364
* having to allocate a buffer of it's own. The buffer, given to
365
* val_str() as argument, belongs to the caller and is later used by the
366
* caller at it's own choosing.
368
* A few implications from the above:
369
* - unless you return a string object which only points to your buffer
370
* but doesn't manages it you should be ready that it will be
372
* - even for not allocated strings (is_alloced() == false) the caller
373
* can change charset (see Item_func_{typecast/binary}. XXX: is this
375
* - still you should try to minimize data copying and return internal
376
* object whenever possible.
379
* In case of NULL value return 0 (NULL pointer) and set null_value flag
381
* If value is not null null_value flag will be reset to false.
617
This is just a shortcut to avoid the cast. You should still use
618
unsigned_flag to check the sign of the item.
620
inline uint64_t val_uint() { return (uint64_t) val_int(); }
622
Return string representation of this item object.
626
str an allocated buffer this or any nested Item object can use to
627
store return value of this method.
630
Buffer passed via argument should only be used if the item itself
631
doesn't have an own String buffer. In case when the item maintains
632
it's own string buffer, it's preferable to return it instead to
633
minimize number of mallocs/memcpys.
634
The caller of this method can modify returned string, but only in case
635
when it was allocated on heap, (is_alloced() is true). This allows
636
the caller to efficiently use a buffer allocated by a child without
637
having to allocate a buffer of it's own. The buffer, given to
638
val_str() as argument, belongs to the caller and is later used by the
639
caller at it's own choosing.
640
A few implications from the above:
641
- unless you return a string object which only points to your buffer
642
but doesn't manages it you should be ready that it will be
644
- even for not allocated strings (is_alloced() == false) the caller
645
can change charset (see Item_func_{typecast/binary}. XXX: is this
647
- still you should try to minimize data copying and return internal
648
object whenever possible.
651
In case of NULL value return 0 (NULL pointer) and set null_value flag
653
If value is not null null_value flag will be reset to false.
383
655
virtual String *val_str(String *str)=0;
386
* Return decimal representation of item with fixed point.
388
* @param buffer which can be used by Item for returning value
393
* Returned value should not be changed if it is not the same which was
394
* passed via argument.
398
* Return pointer on type::Decimal (it can be other then passed via argument)
399
* if value is not NULL (null_value flag will be reset to false).
400
* In case of NULL value it return 0 pointer and set null_value flag
403
virtual type::Decimal *val_decimal(type::Decimal *decimal_buffer)= 0;
406
* Return boolean value of item.
410
* false value is false or NULL
411
* true value is true (not equal to 0)
657
Return decimal representation of item with fixed point.
661
decimal_buffer buffer which can be used by Item for returning value
665
Returned value should not be changed if it is not the same which was
669
Return pointer on my_decimal (it can be other then passed via argument)
670
if value is not NULL (null_value flag will be reset to false).
671
In case of NULL value it return 0 pointer and set null_value flag
674
virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
676
Return boolean value of item.
679
false value is false or NULL
680
true value is true (not equal to 0)
413
682
virtual bool val_bool();
683
virtual String *val_nodeset(String*) { return 0; }
415
684
/* Helper functions, see item_sum.cc */
416
685
String *val_string_from_real(String *str);
417
686
String *val_string_from_int(String *str);
418
687
String *val_string_from_decimal(String *str);
419
type::Decimal *val_decimal_from_real(type::Decimal *decimal_value);
420
type::Decimal *val_decimal_from_int(type::Decimal *decimal_value);
421
type::Decimal *val_decimal_from_string(type::Decimal *decimal_value);
422
type::Decimal *val_decimal_from_date(type::Decimal *decimal_value);
423
type::Decimal *val_decimal_from_time(type::Decimal *decimal_value);
688
my_decimal *val_decimal_from_real(my_decimal *decimal_value);
689
my_decimal *val_decimal_from_int(my_decimal *decimal_value);
690
my_decimal *val_decimal_from_string(my_decimal *decimal_value);
691
my_decimal *val_decimal_from_date(my_decimal *decimal_value);
692
my_decimal *val_decimal_from_time(my_decimal *decimal_value);
424
693
int64_t val_int_from_decimal();
425
694
double val_real_from_decimal();
427
bool save_time_in_field(Field *field);
428
bool save_date_in_field(Field *field);
431
* Stores a string value in field directly
435
* The method is used by Item_*::save_in_field implementations
436
* when we don't need to calculate the value to store
438
* @see Item_string::save_in_field() implementation for example
440
* @param Pointer to field where to store
441
* @param Pointer to the string value to be stored
444
* Nonzero value if error
696
int save_time_in_field(Field *field);
697
int save_date_in_field(Field *field);
447
698
int save_str_value_in_field(Field *field, String *result);
449
virtual Field *get_tmp_table_field(void)
700
virtual Field *get_tmp_table_field(void) { return 0; }
453
701
/* This is also used to create fields in CREATE ... SELECT: */
454
virtual Field *tmp_table_field(Table *t_arg);
455
virtual const char *full_name(void) const;
702
virtual Field *tmp_table_field(Table *t_arg __attribute__((unused)))
704
virtual const char *full_name(void) const { return name ? name : "???"; }
458
707
*result* family of methods is analog of *val* family (see above) but
550
765
For more information about view definition query, INFORMATION_SCHEMA
551
766
query and why they should be generated from the Item-tree, @see
767
mysql_register_view().
554
virtual void print(String *str, enum_query_type query_type);
769
virtual inline void print(String *str,
770
enum_query_type query_type __attribute__((unused)))
772
str->append(full_name());
556
775
void print_item_w_name(String *, enum_query_type query_type);
557
776
virtual void update_used_tables() {}
558
virtual void split_sum_func(Session *session,
559
Item **ref_pointer_array,
562
Move SUM items out from item tree and replace with reference.
564
@param session Thread handler
565
@param ref_pointer_array Pointer to array of reference fields
566
@param fields All fields in select
567
@param ref Pointer to item
568
@param skip_registered <=> function be must skipped for registered
572
This is from split_sum_func() for items that should be split
574
All found SUM items are added FIRST in the fields list and
575
we replace the item with a reference.
577
session->fatal_error() may be called if we are out of memory
579
void split_sum_func(Session *session,
580
Item **ref_pointer_array,
583
bool skip_registered);
586
Get the value of the function as a type::Time structure.
587
As a extra convenience the time structure is reset on error!
589
virtual bool get_date(type::Time <ime, uint32_t fuzzydate);
591
Get time of first argument.
593
As a extra convenience the time structure is reset on error!
595
virtual bool get_time(type::Time <ime);
596
virtual bool get_date_result(type::Time <ime,uint32_t fuzzydate);
599
The method allows to determine nullness of a complex expression
600
without fully evaluating it, instead of calling val/result*() then
777
virtual void split_sum_func(THD *thd __attribute__((unused)),
778
Item **ref_pointer_array __attribute__((unused)),
779
List<Item> &fields __attribute__((unused))) {}
780
/* Called for items that really have to be split */
781
void split_sum_func2(THD *thd, Item **ref_pointer_array, List<Item> &fields,
782
Item **ref, bool skip_registered);
783
virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
784
virtual bool get_time(DRIZZLE_TIME *ltime);
785
virtual bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
786
{ return get_date(ltime,fuzzydate); }
788
The method allows to determine nullness of a complex expression
789
without fully evaluating it, instead of calling val/result*() then
601
790
checking null_value. Used in Item_func_isnull/Item_func_isnotnull
602
791
and Item_sum_count/Item_sum_count_distinct.
603
792
Any new item which can be NULL must implement this method.
605
virtual bool is_null();
607
/** Make sure the null_value member has a correct value. */
608
virtual void update_null_value ();
794
virtual bool is_null() { return 0; }
797
Make sure the null_value member has a correct value.
799
virtual void update_null_value () { (void) val_int(); }
611
802
Inform the item that there will be no distinction between its result
612
803
being false or NULL.
616
806
This function will be called for eg. Items that are top-level AND-parts
617
807
of the WHERE clause. Items implementing this function (currently
618
808
Item_cond_and and subquery-related item) enable special optimizations
619
809
when they are "top level".
621
virtual void top_level_item(void);
623
* Sets field of temporary table for Item which can be switched on temporary
624
* table during query processing (grouping and so on)
626
virtual void set_result_field(Field *field);
627
virtual bool is_result_field(void);
628
virtual bool is_bool_func(void);
629
virtual void save_in_result_field(bool no_conversions);
632
* Sets value of aggregate function in case of no rows for grouping were found
634
virtual void no_rows_in_result(void);
635
virtual Item *copy_or_same(Session *session);
637
virtual Item *copy_andor_structure(Session *session);
639
virtual Item *real_item(void);
640
virtual const Item *real_item(void) const;
641
virtual Item *get_tmp_table_item(Session *session);
811
virtual void top_level_item(void) {}
813
set field of temporary table for Item which can be switched on temporary
814
table during query processing (grouping and so on)
816
virtual void set_result_field(Field *field __attribute__((unused))) {}
817
virtual bool is_result_field(void) { return 0; }
818
virtual bool is_bool_func(void) { return 0; }
819
virtual void save_in_result_field(bool no_conversions __attribute__((unused)))
822
set value of aggregate function in case of no rows for grouping were found
824
virtual void no_rows_in_result(void) {}
825
virtual Item *copy_or_same(THD *thd __attribute__((unused)))
827
virtual Item *copy_andor_structure(THD *thd __attribute__((unused)))
829
virtual Item *real_item(void) { return this; }
830
virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
643
832
static const CHARSET_INFO *default_charset();
644
virtual const CHARSET_INFO *compare_collation();
646
virtual bool walk(Item_processor processor,
651
Traverse item tree possibly transforming it (replacing items).
653
If you don't need to transform an item tree, but only traverse
654
it, please use Item::walk() instead.
656
@param transformer functor that performs transformation of a subtree
657
@param arg opaque argument passed to the functor
660
Returns pointer to the new subtree root. Session::change_item_tree()
661
should be called for it if transformation took place, i.e. if a
662
pointer to newly allocated item is returned.
833
virtual const CHARSET_INFO *compare_collation() { return NULL; }
835
virtual bool walk(Item_processor processor __attribute__((unused)),
836
bool walk_subquery __attribute__((unused)),
839
return (this->*processor)(arg);
664
842
virtual Item* transform(Item_transformer transformer, unsigned char *arg);
667
845
This function performs a generic "compilation" of the Item tree.
668
The process of compilation is assumed to go as follows:
846
The process of compilation is assumed to go as follows:
673
850
if (this->*some_analyzer(...))
675
852
compile children if any;
676
853
this->*some_transformer(...);
681
857
i.e. analysis is performed top-down while transformation is done
684
virtual Item* compile(Item_analyzer analyzer,
685
unsigned char **arg_p,
686
Item_transformer transformer,
687
unsigned char *arg_t);
689
virtual void traverse_cond(Cond_traverser traverser,
691
traverse_order order);
693
virtual bool remove_dependence_processor(unsigned char * arg);
694
virtual bool remove_fixed(unsigned char * arg);
695
virtual bool collect_item_field_processor(unsigned char * arg);
696
virtual bool find_item_in_field_list_processor(unsigned char *arg);
697
virtual bool change_context_processor(unsigned char *context);
698
virtual bool register_field_in_read_map(unsigned char *arg);
699
virtual bool subst_argument_checker(unsigned char **arg);
701
virtual bool cache_const_expr_analyzer(unsigned char **arg);
702
virtual Item* cache_const_expr_transformer(unsigned char *arg);
704
virtual Item *equal_fields_propagator(unsigned char * arg);
705
virtual bool set_no_const_sub(unsigned char *arg);
706
virtual Item *replace_equal_field(unsigned char * arg);
860
virtual Item* compile(Item_analyzer analyzer, unsigned char **arg_p,
861
Item_transformer transformer, unsigned char *arg_t)
863
if ((this->*analyzer) (arg_p))
864
return ((this->*transformer) (arg_t));
868
virtual void traverse_cond(Cond_traverser traverser __attribute__((unused)),
870
traverse_order order __attribute__((unused)))
872
(*traverser)(this, arg);
875
virtual bool remove_dependence_processor(unsigned char * arg __attribute__((unused)))
877
virtual bool remove_fixed(unsigned char * arg __attribute__((unused)))
882
virtual bool cleanup_processor(unsigned char *arg __attribute__((unused)));
883
virtual bool collect_item_field_processor(unsigned char * arg __attribute__((unused)))
885
virtual bool find_item_in_field_list_processor(unsigned char *arg __attribute__((unused)))
887
virtual bool change_context_processor(unsigned char *context __attribute__((unused)))
889
virtual bool reset_query_id_processor(unsigned char *query_id_arg __attribute__((unused)))
891
virtual bool register_field_in_read_map(unsigned char *arg __attribute__((unused)))
894
The next function differs from the previous one that a bitmap to be updated
895
is passed as unsigned char *arg.
897
virtual bool register_field_in_bitmap(unsigned char *arg __attribute__((unused)))
899
virtual bool subst_argument_checker(unsigned char **arg)
907
Check if an expression/function is allowed for a virtual column
909
check_vcol_func_processor()
912
TRUE Function not accepted
913
FALSE Function accepted
915
virtual bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
918
virtual Item *equal_fields_propagator(unsigned char * arg __attribute__((unused))) { return this; }
919
virtual bool set_no_const_sub(unsigned char *arg __attribute__((unused))) { return false; }
920
virtual Item *replace_equal_field(unsigned char * arg __attribute__((unused))) { return this; }
924
For SP local variable returns pointer to Item representing its
925
current value and pointer to current Item otherwise.
927
virtual Item *this_item(void) { return this; }
928
virtual const Item *this_item(void) const { return this; }
931
For SP local variable returns address of pointer to Item representing its
932
current value and pointer passed via parameter otherwise.
934
virtual Item **this_item_addr(THD *thd __attribute__((unused)), Item **addr_arg) { return addr_arg; }
709
virtual uint32_t cols();
710
virtual Item* element_index(uint32_t i);
711
virtual Item** addr(uint32_t i);
937
virtual uint32_t cols() { return 1; }
938
virtual Item* element_index(uint32_t i __attribute__((unused))) { return this; }
939
virtual Item** addr(uint32_t i __attribute__((unused))) { return 0; }
712
940
virtual bool check_cols(uint32_t c);
713
941
// It is not row => null inside is impossible
714
virtual bool null_inside();
942
virtual bool null_inside() { return 0; }
715
943
// used in row subselects to get value of elements
716
virtual void bring_value();
719
Create a field based on field_type of argument.
721
For now, this is only used to create a field for
722
IFNULL(x,something) and time functions
944
virtual void bring_value() {}
729
946
Field *tmp_table_field_from_field_type(Table *table, bool fixed_length);
947
virtual Item_field *filed_for_view_update() { return 0; }
731
virtual Item *neg_transformer(Session *session);
732
virtual Item *update_value_transformer(unsigned char *select_arg);
949
virtual Item *neg_transformer(THD *thd __attribute__((unused))) { return NULL; }
950
virtual Item *update_value_transformer(unsigned char *select_arg __attribute__((unused))) { return this; }
733
951
virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
737
* Returns true for Items representing DATE/TIME functions and DATE/TIME table fields.
738
* Those Items have result_type()==STRING_RESULT (and not INT_RESULT), but
739
* their values should be compared as integers (because the integer
740
* representation is more precise than the string one).
742
virtual bool result_as_int64_t();
959
result_as_int64_t() must return true for Items representing DATE/TIME
960
functions and DATE/TIME table fields.
961
Those Items have result_type()==STRING_RESULT (and not INT_RESULT), but
962
their values should be compared as integers (because the integer
963
representation is more precise than the string one).
965
virtual bool result_as_int64_t() { return false; }
743
966
bool is_datetime();
746
* Tests whether an expression is expensive to compute. Used during
747
* optimization to avoid computing expensive expressions during this
748
* phase. Also used to force temp tables when sorting on expensive
753
* Normally we should have a method:
754
* cost Item::execution_cost(),
755
* where 'cost' is either 'double' or some structure of various cost
759
* This function is now used to prevent evaluation of materialized IN
760
* subquery predicates before it is allowed. grep for
761
* DontEvaluateMaterializedSubqueryTooEarly to see the uses.
763
virtual bool is_expensive();
969
Test whether an expression is expensive to compute. Used during
970
optimization to avoid computing expensive expressions during this
971
phase. Also used to force temp tables when sorting on expensive
974
Normally we should have a method:
975
cost Item::execution_cost(),
976
where 'cost' is either 'double' or some structure of various cost
979
virtual bool is_expensive()
981
if (is_expensive_cache < 0)
982
is_expensive_cache= walk(&Item::is_expensive_processor, 0, (unsigned char*)0);
983
return test(is_expensive_cache);
765
985
String *check_well_formed_result(String *str, bool send_error= 0);
767
* Compares two items using a given collation
771
* This method works exactly as Item::eq if the collation cs coincides with
772
* the collation of the compared objects. Otherwise, first the collations that
773
* differ from cs are replaced for cs and then the items are compared by
774
* Item::eq. After the comparison the original collations of items are
777
* @param Pointer to the item to compare with
778
* @param Compare as binary?
779
* @param Pointer to the collation to use when comparing strings
782
* true if compared items has been detected as equal
786
bool eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs);
788
inline uint32_t char_to_byte_length_safe(uint32_t char_length_arg, uint32_t mbmaxlen_arg)
790
uint64_t tmp= ((uint64_t) char_length_arg) * mbmaxlen_arg;
791
return (tmp > UINT32_MAX) ? (uint32_t) UINT32_MAX : (uint32_t) tmp;
794
uint32_t max_char_length() const;
796
void fix_length_and_charset(uint32_t max_char_length_arg, CHARSET_INFO *cs);
797
void fix_char_length(uint32_t max_char_length_arg);
798
void fix_char_length_uint64_t(uint64_t max_char_length_arg);
799
void fix_length_and_charset_datetime(uint32_t max_char_length_arg);
802
Session &getSession()
986
bool eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs);
990
class Item_basic_constant :public Item
993
/* to prevent drop fixed flag (no need parent cleanup call) */
997
Restore the original field name as it might not have been allocated
998
in the statement memory. If the name is auto generated, it must be
999
done again between subsequent executions of a prepared statement.
1006
bool agg_item_collations(DTCollation &c, const char *name,
1007
Item **items, uint32_t nitems, uint32_t flags, int item_sep);
1008
bool agg_item_collations_for_comparison(DTCollation &c, const char *name,
1009
Item **items, uint32_t nitems, uint32_t flags);
1010
bool agg_item_charsets(DTCollation &c, const char *name,
1011
Item **items, uint32_t nitems, uint32_t flags, int item_sep);
1014
class Item_num: public Item_basic_constant
1017
Item_num() {} /* Remove gcc warning */
1018
virtual Item_num *neg()= 0;
1019
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1022
#define NO_CACHED_FIELD_INDEX ((uint)(-1))
1024
class st_select_lex;
1025
class Item_ident :public Item
1029
We have to store initial values of db_name, table_name and field_name
1030
to be able to restore them during cleanup() because they can be
1031
updated during fix_fields() to values from Field object and life-time
1032
of those is shorter than life-time of Item_field.
1034
const char *orig_db_name;
1035
const char *orig_table_name;
1036
const char *orig_field_name;
1039
Name_resolution_context *context;
1040
const char *db_name;
1041
const char *table_name;
1042
const char *field_name;
1043
bool alias_name_used; /* true if item was resolved against alias */
1045
Cached value of index for this field in table->field array, used by prep.
1046
stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX
1047
if index value is not known.
1049
uint32_t cached_field_index;
1051
Cached pointer to table which contains this field, used for the same reason
1052
by prep. stmt. too in case then we have not-fully qualified field.
1053
0 - means no cached value.
1055
TableList *cached_table;
1056
st_select_lex *depended_from;
1057
Item_ident(Name_resolution_context *context_arg,
1058
const char *db_name_arg, const char *table_name_arg,
1059
const char *field_name_arg);
1060
Item_ident(THD *thd, Item_ident *item);
1061
const char *full_name() const;
1063
bool remove_dependence_processor(unsigned char * arg);
1064
virtual void print(String *str, enum_query_type query_type);
1065
virtual bool change_context_processor(unsigned char *cntx)
1066
{ context= (Name_resolution_context *)cntx; return false; }
1067
friend bool insert_fields(THD *thd, Name_resolution_context *context,
1068
const char *db_name,
1069
const char *table_name, List_iterator<Item> *it,
1070
bool any_privileges);
1074
class Item_ident_for_show :public Item
1078
const char *db_name;
1079
const char *table_name;
1081
Item_ident_for_show(Field *par_field, const char *db_arg,
1082
const char *table_name_arg)
1083
:field(par_field), db_name(db_arg), table_name(table_name_arg)
1086
enum Type type() const { return FIELD_ITEM; }
1087
double val_real() { return field->val_real(); }
1088
int64_t val_int() { return field->val_int(); }
1089
String *val_str(String *str) { return field->val_str(str); }
1090
my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); }
1091
void make_field(Send_field *tmp_field);
1098
class Item_field :public Item_ident
1101
void set_field(Field *field);
1103
Field *field,*result_field;
1104
Item_equal *item_equal;
1105
bool no_const_subst;
1107
if any_privileges set to true then here real effective privileges will
1110
uint32_t have_privileges;
1111
/* field need any privileges (for VIEW creation) */
1112
bool any_privileges;
1113
Item_field(Name_resolution_context *context_arg,
1114
const char *db_arg,const char *table_name_arg,
1115
const char *field_name_arg);
1117
Constructor needed to process subselect with temporary tables (see Item)
1119
Item_field(THD *thd, Item_field *item);
1121
Constructor used inside setup_wild(), ensures that field, table,
1122
and database names will live as long as Item_field (this is important
1123
in prepared statements).
1125
Item_field(THD *thd, Name_resolution_context *context_arg, Field *field);
1127
If this constructor is used, fix_fields() won't work, because
1128
db_name, table_name and column_name are unknown. It's necessary to call
1129
reset_field() before fix_fields() for all fields created this way.
1131
Item_field(Field *field);
1132
enum Type type() const { return FIELD_ITEM; }
1133
bool eq(const Item *item, bool binary_cmp) const;
1136
my_decimal *val_decimal(my_decimal *);
1137
String *val_str(String*);
1138
double val_result();
1139
int64_t val_int_result();
1140
String *str_result(String* tmp);
1141
my_decimal *val_decimal_result(my_decimal *);
1142
bool val_bool_result();
1143
bool send(Protocol *protocol, String *str_arg);
1144
void reset_field(Field *f);
1145
bool fix_fields(THD *, Item **);
1146
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
1147
void make_field(Send_field *tmp_field);
1148
int save_in_field(Field *field,bool no_conversions);
1149
void save_org_in_field(Field *field);
1150
table_map used_tables() const;
1151
enum Item_result result_type () const
1153
return field->result_type();
1155
Item_result cast_to_int_type() const
1157
return field->cast_to_int_type();
1159
enum_field_types field_type() const
1161
return field->type();
1163
enum_monotonicity_info get_monotonicity_info() const
1165
return MONOTONIC_STRICT_INCREASING;
1167
int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
1168
Field *get_tmp_table_field() { return result_field; }
1169
Field *tmp_table_field(Table *t_arg __attribute__((unused))) { return result_field; }
1170
bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
1171
bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
1172
bool get_time(DRIZZLE_TIME *ltime);
1173
bool is_null() { return field->is_null(); }
1174
void update_null_value();
1175
Item *get_tmp_table_item(THD *thd);
1176
bool collect_item_field_processor(unsigned char * arg);
1177
bool find_item_in_field_list_processor(unsigned char *arg);
1178
bool register_field_in_read_map(unsigned char *arg);
1179
bool register_field_in_bitmap(unsigned char *arg);
1180
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1183
bool result_as_int64_t()
1185
return field->can_be_compared_as_int64_t();
1187
Item_equal *find_item_equal(COND_EQUAL *cond_equal);
1188
bool subst_argument_checker(unsigned char **arg);
1189
Item *equal_fields_propagator(unsigned char *arg);
1190
bool set_no_const_sub(unsigned char *arg);
1191
Item *replace_equal_field(unsigned char *arg);
1192
inline uint32_t max_disp_length() { return field->max_display_length(); }
1193
Item_field *filed_for_view_update() { return this; }
1194
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1195
int fix_outer_field(THD *thd, Field **field, Item **reference);
1196
virtual Item *update_value_transformer(unsigned char *select_arg);
1197
virtual void print(String *str, enum_query_type query_type);
1199
friend class Item_default_value;
1200
friend class Item_insert_value;
1201
friend class st_select_lex_unit;
1204
class Item_null :public Item_basic_constant
1207
Item_null(char *name_par=0)
1209
maybe_null= null_value= true;
1211
name= name_par ? name_par : (char*) "NULL";
1213
collation.set(&my_charset_bin, DERIVATION_IGNORABLE);
1215
enum Type type() const { return NULL_ITEM; }
1216
bool eq(const Item *item, bool binary_cmp) const;
1219
String *val_str(String *str);
1220
my_decimal *val_decimal(my_decimal *);
1221
int save_in_field(Field *field, bool no_conversions);
1222
int save_safe_in_field(Field *field);
1223
bool send(Protocol *protocol, String *str);
1224
enum Item_result result_type () const { return STRING_RESULT; }
1225
enum_field_types field_type() const { return DRIZZLE_TYPE_NULL; }
1226
bool basic_const_item() const { return 1; }
1227
Item *clone_item() { return new Item_null(name); }
1228
bool is_null() { return 1; }
1230
virtual inline void print(String *str,
1231
enum_query_type query_type __attribute__((unused)))
1233
str->append(STRING_WITH_LEN("NULL"));
1236
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1237
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1241
class Item_null_result :public Item_null
1244
Field *result_field;
1245
Item_null_result() : Item_null(), result_field(0) {}
1246
bool is_result_field() { return result_field != 0; }
1247
void save_in_result_field(bool no_conversions)
1249
save_in_field(result_field, no_conversions);
1251
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1255
/* Item represents one placeholder ('?') of prepared statement */
1257
class Item_param :public Item
1259
char cnvbuf[MAX_FIELD_WIDTH];
1264
enum enum_item_param_state
1266
NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE,
1267
STRING_VALUE, TIME_VALUE, LONG_DATA_VALUE,
1272
A buffer for string and long data values. Historically all allocated
1273
values returned from val_str() were treated as eligible to
1274
modification. I. e. in some cases Item_func_concat can append it's
1275
second argument to return value of the first one. Because of that we
1276
can't return the original buffer holding string data from val_str(),
1277
and have to have one buffer for data and another just pointing to
1278
the data. This is the latter one and it's returned from val_str().
1279
Can not be declared inside the union as it's not a POD type.
1281
String str_value_ptr;
1282
my_decimal decimal_value;
1288
Character sets conversion info for string values.
1289
Character sets of client and connection defined at bind time are used
1290
for all conversions, even if one of them is later changed (i.e.
1291
between subsequent calls to mysql_stmt_execute).
1293
struct CONVERSION_INFO
1295
const CHARSET_INFO *character_set_client;
1296
const CHARSET_INFO *character_set_of_placeholder;
1298
This points at character set of connection if conversion
1299
to it is required (i. e. if placeholder typecode is not BLOB).
1300
Otherwise it's equal to character_set_client (to simplify
1301
check in convert_str_value()).
1303
const CHARSET_INFO *final_character_set_of_str_value;
1308
/* Cached values for virtual methods to save us one switch. */
1309
enum Item_result item_result_type;
1310
enum Type item_type;
1313
Used when this item is used in a temporary table.
1314
This is NOT placeholder metadata sent to client, as this value
1315
is assigned after sending metadata (in setup_one_conversion_function).
1316
For example in case of 'SELECT ?' you'll get DRIZZLE_TYPE_STRING both
1317
in result set and placeholders metadata, no matter what type you will
1318
supply for this placeholder in mysql_stmt_execute.
1320
enum enum_field_types param_type;
1322
Offset of placeholder inside statement text. Used to create
1323
no-placeholders version of this statement for the binary log.
1325
uint32_t pos_in_query;
1327
Item_param(uint32_t pos_in_query_arg);
1329
enum Item_result result_type () const { return item_result_type; }
1330
enum Type type() const { return item_type; }
1331
enum_field_types field_type() const { return param_type; }
1335
my_decimal *val_decimal(my_decimal*);
1336
String *val_str(String*);
1337
bool get_time(DRIZZLE_TIME *tm);
1338
bool get_date(DRIZZLE_TIME *tm, uint32_t fuzzydate);
1339
int save_in_field(Field *field, bool no_conversions);
1342
void set_int(int64_t i, uint32_t max_length_arg);
1343
void set_double(double i);
1344
void set_decimal(char *str, ulong length);
1345
bool set_str(const char *str, ulong length);
1346
bool set_longdata(const char *str, ulong length);
1347
void set_time(DRIZZLE_TIME *tm, enum enum_drizzle_timestamp_type type,
1348
uint32_t max_length_arg);
1349
bool set_from_user_var(THD *thd, const user_var_entry *entry);
1352
Assign placeholder value from bind data.
1353
Note, that 'len' has different semantics in embedded library (as we
1354
don't need to check that packet is not broken there). See
1355
sql_prepare.cc for details.
1357
void (*set_param_func)(Item_param *param, unsigned char **pos, ulong len);
1359
const String *query_val_str(String *str) const;
1361
bool convert_str_value(THD *thd);
1364
If value for parameter was not set we treat it as non-const
1365
so noone will use parameters value in fix_fields still
1366
parameter is constant during execution.
1368
virtual table_map used_tables() const
1369
{ return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; }
1370
virtual void print(String *str, enum_query_type query_type);
1372
{ assert(state != NO_VALUE); return state == NULL_VALUE; }
1373
bool basic_const_item() const;
1375
This method is used to make a copy of a basic constant item when
1376
propagating constants in the optimizer. The reason to create a new
1377
item and not use the existing one is not precisely known (2005/04/16).
1378
Probably we are trying to preserve tree structure of items, in other
1379
words, avoid pointing at one item from two different nodes of the tree.
1380
Return a new basic constant item if parameter value is a basic
1381
constant, assert otherwise. This method is called only if
1382
basic_const_item returned true.
1384
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1387
Implement by-value equality evaluation if parameter value
1388
is set and is a basic constant (integer, real or string).
1389
Otherwise return false.
1391
bool eq(const Item *item, bool binary_cmp) const;
1392
/** Item is a argument to a limit clause. */
1393
bool limit_clause_param;
1397
class Item_int :public Item_num
1401
Item_int(int32_t i,uint32_t length= MY_INT32_NUM_DECIMAL_DIGITS)
1403
{ max_length=length; fixed= 1; }
1404
Item_int(int64_t i,uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
1406
{ max_length=length; fixed= 1; }
1407
Item_int(uint64_t i, uint32_t length= MY_INT64_NUM_DECIMAL_DIGITS)
1409
{ max_length=length; fixed= 1; unsigned_flag= 1; }
1410
Item_int(const char *str_arg,int64_t i,uint32_t length) :value(i)
1411
{ max_length=length; name=(char*) str_arg; fixed= 1; }
1412
Item_int(const char *str_arg, uint32_t length=64);
1413
enum Type type() const { return INT_ITEM; }
1414
enum Item_result result_type () const { return INT_RESULT; }
1415
enum_field_types field_type() const { return DRIZZLE_TYPE_LONGLONG; }
1416
int64_t val_int() { assert(fixed == 1); return value; }
1417
double val_real() { assert(fixed == 1); return (double) value; }
1418
my_decimal *val_decimal(my_decimal *);
1419
String *val_str(String*);
1420
int save_in_field(Field *field, bool no_conversions);
1421
bool basic_const_item() const { return 1; }
1422
Item *clone_item() { return new Item_int(name,value,max_length); }
1423
virtual void print(String *str, enum_query_type query_type);
1424
Item_num *neg() { value= -value; return this; }
1425
uint32_t decimal_precision() const
1426
{ return (uint)(max_length - test(value < 0)); }
1427
bool eq(const Item *, bool binary_cmp) const;
1428
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1433
class Item_uint :public Item_int
1436
Item_uint(const char *str_arg, uint32_t length);
1437
Item_uint(uint64_t i) :Item_int((uint64_t) i, 10) {}
1438
Item_uint(const char *str_arg, int64_t i, uint32_t length);
1440
{ assert(fixed == 1); return uint64_t2double((uint64_t)value); }
1441
String *val_str(String*);
1442
Item *clone_item() { return new Item_uint(name, value, max_length); }
1443
int save_in_field(Field *field, bool no_conversions);
1444
virtual void print(String *str, enum_query_type query_type);
1446
uint32_t decimal_precision() const { return max_length; }
1447
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1452
/* decimal (fixed point) constant */
1453
class Item_decimal :public Item_num
1456
my_decimal decimal_value;
1458
Item_decimal(const char *str_arg, uint32_t length, const CHARSET_INFO * const charset);
1459
Item_decimal(const char *str, const my_decimal *val_arg,
1460
uint32_t decimal_par, uint32_t length);
1461
Item_decimal(my_decimal *value_par);
1462
Item_decimal(int64_t val, bool unsig);
1463
Item_decimal(double val, int precision, int scale);
1464
Item_decimal(const unsigned char *bin, int precision, int scale);
1466
enum Type type() const { return DECIMAL_ITEM; }
1467
enum Item_result result_type () const { return DECIMAL_RESULT; }
1468
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDECIMAL; }
1471
String *val_str(String*);
1472
my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
1473
{ return &decimal_value; }
1474
int save_in_field(Field *field, bool no_conversions);
1475
bool basic_const_item() const { return 1; }
1478
return new Item_decimal(name, &decimal_value, decimals, max_length);
1480
virtual void print(String *str, enum_query_type query_type);
1483
my_decimal_neg(&decimal_value);
1484
unsigned_flag= !decimal_value.sign();
1487
uint32_t decimal_precision() const { return decimal_value.precision(); }
1488
bool eq(const Item *, bool binary_cmp) const;
1489
void set_decimal_value(my_decimal *value_par);
1490
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1495
class Item_float :public Item_num
1500
// Item_real() :value(0) {}
1501
Item_float(const char *str_arg, uint32_t length);
1502
Item_float(const char *str,double val_arg,uint32_t decimal_par,uint32_t length)
1505
presentation= name=(char*) str;
1506
decimals=(uint8_t) decimal_par;
1510
Item_float(double value_par, uint32_t decimal_par) :presentation(0), value(value_par)
1512
decimals= (uint8_t) decimal_par;
1515
int save_in_field(Field *field, bool no_conversions);
1516
enum Type type() const { return REAL_ITEM; }
1517
enum_field_types field_type() const { return DRIZZLE_TYPE_DOUBLE; }
1518
double val_real() { assert(fixed == 1); return value; }
1522
if (value <= (double) INT64_MIN)
1526
else if (value >= (double) (uint64_t) INT64_MAX)
1530
return (int64_t) rint(value);
1532
String *val_str(String*);
1533
my_decimal *val_decimal(my_decimal *);
1534
bool basic_const_item() const { return 1; }
1536
{ return new Item_float(name, value, decimals, max_length); }
1537
Item_num *neg() { value= -value; return this; }
1538
virtual void print(String *str, enum_query_type query_type);
1539
bool eq(const Item *, bool binary_cmp) const;
1543
class Item_static_float_func :public Item_float
1545
const char *func_name;
1547
Item_static_float_func(const char *str, double val_arg, uint32_t decimal_par,
1549
:Item_float(NULL, val_arg, decimal_par, length), func_name(str)
1552
virtual inline void print(String *str,
1553
enum_query_type query_type __attribute__((unused)))
1555
str->append(func_name);
1558
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1559
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1564
class Item_string :public Item_basic_constant
1567
Item_string(const char *str,uint32_t length,
1568
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE,
1569
uint32_t repertoire= MY_REPERTOIRE_UNICODE30)
1570
: m_cs_specified(false)
1572
str_value.set_or_copy_aligned(str, length, cs);
1573
collation.set(cs, dv, repertoire);
1575
We have to have a different max_length than 'length' here to
1576
ensure that we get the right length if we do use the item
1577
to create a new table. In this case max_length must be the maximum
1578
number of chars for a string of this type because we in Create_field::
1579
divide the max_length with mbmaxlen).
1581
max_length= str_value.numchars()*cs->mbmaxlen;
1582
set_name(str, length, cs);
1583
decimals=NOT_FIXED_DEC;
1584
// it is constant => can be used without fix_fields (and frequently used)
1587
/* Just create an item and do not fill string representation */
1588
Item_string(const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
1589
: m_cs_specified(false)
1591
collation.set(cs, dv);
1593
set_name(NULL, 0, cs);
1594
decimals= NOT_FIXED_DEC;
1597
Item_string(const char *name_par, const char *str, uint32_t length,
1598
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE,
1599
uint32_t repertoire= MY_REPERTOIRE_UNICODE30)
1600
: m_cs_specified(false)
1602
str_value.set_or_copy_aligned(str, length, cs);
1603
collation.set(cs, dv, repertoire);
1604
max_length= str_value.numchars()*cs->mbmaxlen;
1605
set_name(name_par, 0, cs);
1606
decimals=NOT_FIXED_DEC;
1607
// it is constant => can be used without fix_fields (and frequently used)
1611
This is used in stored procedures to avoid memory leaks and
1612
does a deep copy of its argument.
1614
void set_str_with_copy(const char *str_arg, uint32_t length_arg)
1616
str_value.copy(str_arg, length_arg, collation.collation);
1617
max_length= str_value.numchars() * collation.collation->mbmaxlen;
1619
void set_repertoire_from_value()
1621
collation.repertoire= my_string_repertoire(str_value.charset(),
1623
str_value.length());
1625
enum Type type() const { return STRING_ITEM; }
1628
String *val_str(String*)
1631
return (String*) &str_value;
1633
my_decimal *val_decimal(my_decimal *);
1634
int save_in_field(Field *field, bool no_conversions);
1635
enum Item_result result_type () const { return STRING_RESULT; }
1636
enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
1637
bool basic_const_item() const { return 1; }
1638
bool eq(const Item *item, bool binary_cmp) const;
1641
return new Item_string(name, str_value.ptr(),
1642
str_value.length(), collation.collation);
1644
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1645
inline void append(char *str, uint32_t length)
1647
str_value.append(str, length);
1648
max_length= str_value.numchars() * collation.collation->mbmaxlen;
1650
virtual void print(String *str, enum_query_type query_type);
1653
Return true if character-set-introducer was explicitly specified in the
1654
original query for this item (text literal).
1656
This operation is to be called from Item_string::print(). The idea is
1657
that when a query is generated (re-constructed) from the Item-tree,
1658
character-set-introducers should appear only for those literals, where
1659
they were explicitly specified by the user. Otherwise, that may lead to
1660
loss collation information (character set introducers implies default
1661
collation for the literal).
1663
Basically, that makes sense only for views and hopefully will be gone
1664
one day when we start using original query as a view definition.
1666
@return This operation returns the value of m_cs_specified attribute.
1667
@retval true if character set introducer was explicitly specified in
1669
@retval false otherwise.
1671
inline bool is_cs_specified() const
1673
return m_cs_specified;
1677
Set the value of m_cs_specified attribute.
1679
m_cs_specified attribute shows whether character-set-introducer was
1680
explicitly specified in the original query for this text literal or
1681
not. The attribute makes sense (is used) only for views.
1683
This operation is to be called from the parser during parsing an input
1686
inline void set_cs_specified(bool cs_specified)
1688
m_cs_specified= cs_specified;
1690
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
812
const std::string &type(Item::Type type);
813
} /* namespace display */
815
std::ostream& operator<<(std::ostream& output, const Item &item);
817
} /* namespace drizzled */
819
/** @TODO Why is this in the middle? */
820
#include <drizzled/item/ident.h>
826
Mark item and Select_Lexs as dependent if item was resolved in
829
@param session thread handler
830
@param last select from which current item depend
831
@param current current select
832
@param resolved_item item which was resolved in outer SELECT(for warning)
833
@param mark_item item which should be marked (can be differ in case of
836
void mark_as_dependent(Session *session,
839
Item_ident *resolved_item,
840
Item_ident *mark_item);
843
Resolve a column reference in a sub-select.
845
Resolve a column reference (usually inside a HAVING clause) against the
846
SELECT and GROUP BY clauses of the query described by 'select'. The name
847
resolution algorithm searches both the SELECT and GROUP BY clauses, and in
848
case of a name conflict prefers GROUP BY column names over SELECT names. If
849
both clauses contain different fields with the same names, a warning is
850
issued that name of 'ref' is ambiguous. We extend ANSI SQL in that when no
851
GROUP BY column is found, then a HAVING name is resolved as a possibly
852
derived SELECT column. This extension is allowed only if the
853
MODE_ONLY_FULL_GROUP_BY sql mode isn't enabled.
855
@param session current thread
856
@param ref column reference being resolved
857
@param select the select that ref is resolved against
860
The resolution procedure is:
861
- Search for a column or derived column named col_ref_i [in table T_j]
862
in the SELECT clause of Q.
863
- Search for a column named col_ref_i [in table T_j]
864
in the GROUP BY clause of Q.
865
- If found different columns with the same name in GROUP BY and SELECT
866
- issue a warning and return the GROUP BY column,
868
- if the MODE_ONLY_FULL_GROUP_BY mode is enabled return error
869
- else return the found SELECT column.
873
- NULL - there was an error, and the error was already reported
874
- not_found_item - the item was not resolved, no error was reported
875
- resolved item - if the item was resolved
877
Item** resolve_ref_in_select_and_group(Session *session, Item_ident *ref, Select_Lex *select);
880
Mark range of selects and resolved identifier (field/reference)
883
@param session thread handler
884
@param last_select select where resolved_item was resolved
885
@param current_sel current select (select where resolved_item was placed)
886
@param found_field field which was found during resolving
887
@param found_item Item which was found during resolving (if resolved
888
identifier belongs to VIEW)
889
@param resolved_item Identifier which was resolved
892
We have to mark all items between current_sel (including) and
893
last_select (excluding) as dependend (select before last_select should
894
be marked with actual table mask used by resolved item, all other with
895
OUTER_REF_TABLE_BIT) and also write dependence information to Item of
898
void mark_select_range_as_dependent(Session *session,
899
Select_Lex *last_select,
900
Select_Lex *current_sel,
1694
bool m_cs_specified;
1698
class Item_static_string_func :public Item_string
1700
const char *func_name;
1702
Item_static_string_func(const char *name_par, const char *str, uint32_t length,
1703
const CHARSET_INFO * const cs,
1704
Derivation dv= DERIVATION_COERCIBLE)
1705
:Item_string(NULL, str, length, cs, dv), func_name(name_par)
1707
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1709
virtual inline void print(String *str,
1710
enum_query_type query_type __attribute__((unused)))
1712
str->append(func_name);
1714
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1719
/* for show tables */
1720
class Item_return_date_time :public Item_string
1722
enum_field_types date_time_field_type;
1724
Item_return_date_time(const char *name_arg, enum_field_types field_type_arg)
1725
:Item_string(name_arg, 0, &my_charset_bin),
1726
date_time_field_type(field_type_arg)
1728
enum_field_types field_type() const { return date_time_field_type; }
1732
class Item_blob :public Item_string
1735
Item_blob(const char *name, uint32_t length) :
1736
Item_string(name, length, &my_charset_bin)
1737
{ max_length= length; }
1738
enum Type type() const { return TYPE_HOLDER; }
1739
enum_field_types field_type() const { return DRIZZLE_TYPE_BLOB; }
1744
Item_empty_string -- is a utility class to put an item into List<Item>
1745
which is then used in protocol.send_fields() when sending SHOW output to
1749
class Item_empty_string :public Item_string
1752
Item_empty_string(const char *header,uint32_t length, const CHARSET_INFO * cs= NULL) :
1753
Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
1754
{ name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
1755
void make_field(Send_field *field);
1759
class Item_return_int :public Item_int
1761
enum_field_types int_field_type;
1763
Item_return_int(const char *name_arg, uint32_t length,
1764
enum_field_types field_type_arg, int64_t value= 0)
1765
:Item_int(name_arg, value, length), int_field_type(field_type_arg)
1769
enum_field_types field_type() const { return int_field_type; }
1773
class Item_hex_string: public Item_basic_constant
1776
Item_hex_string() {}
1777
Item_hex_string(const char *str,uint32_t str_length);
1778
enum Type type() const { return VARBIN_ITEM; }
1782
return (double) (uint64_t) Item_hex_string::val_int();
1785
bool basic_const_item() const { return 1; }
1786
String *val_str(String*) { assert(fixed == 1); return &str_value; }
1787
my_decimal *val_decimal(my_decimal *);
1788
int save_in_field(Field *field, bool no_conversions);
1789
enum Item_result result_type () const { return STRING_RESULT; }
1790
enum Item_result cast_to_int_type() const { return INT_RESULT; }
1791
enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
1792
virtual void print(String *str, enum_query_type query_type);
1793
bool eq(const Item *item, bool binary_cmp) const;
1794
virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1795
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1800
class Item_bin_string: public Item_hex_string
1803
Item_bin_string(const char *str,uint32_t str_length);
1806
class Item_result_field :public Item /* Item with result field */
1809
Field *result_field; /* Save result here */
1810
Item_result_field() :result_field(0) {}
1811
// Constructor used for Item_sum/Item_cond_and/or (see Item comment)
1812
Item_result_field(THD *thd, Item_result_field *item):
1813
Item(thd, item), result_field(item->result_field)
1815
~Item_result_field() {} /* Required with gcc 2.95 */
1816
Field *get_tmp_table_field() { return result_field; }
1817
Field *tmp_table_field(Table *t_arg __attribute__((unused)))
1818
{ return result_field; }
1819
table_map used_tables() const { return 1; }
1820
virtual void fix_length_and_dec()=0;
1821
void set_result_field(Field *field) { result_field= field; }
1822
bool is_result_field() { return 1; }
1823
void save_in_result_field(bool no_conversions)
1825
save_in_field(result_field, no_conversions);
1828
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
1833
class Item_ref :public Item_ident
1836
void set_properties();
1838
enum Ref_Type { REF, DIRECT_REF, VIEW_REF, OUTER_REF };
1839
Field *result_field; /* Save result here */
1841
Item_ref(Name_resolution_context *context_arg,
1842
const char *db_arg, const char *table_name_arg,
1843
const char *field_name_arg)
1844
:Item_ident(context_arg, db_arg, table_name_arg, field_name_arg),
1845
result_field(0), ref(0) {}
1847
This constructor is used in two scenarios:
1849
No initialization is performed, fix_fields() call will be necessary.
1851
B) *item points to an Item this Item_ref will refer to. This is
1852
used for GROUP BY. fix_fields() will not be called in this case,
1853
so we call set_properties to make this item "fixed". set_properties
1854
performs a subset of action Item_ref::fix_fields does, and this subset
1855
is enough for Item_ref's used in GROUP BY.
1857
TODO we probably fix a superset of problems like in BUG#6658. Check this
1858
with Bar, and if we have a more broader set of problems like this.
1860
Item_ref(Name_resolution_context *context_arg, Item **item,
1861
const char *table_name_arg, const char *field_name_arg,
1862
bool alias_name_used_arg= false);
1864
/* Constructor need to process subselect with temporary tables (see Item) */
1865
Item_ref(THD *thd, Item_ref *item)
1866
:Item_ident(thd, item), result_field(item->result_field), ref(item->ref) {}
1867
enum Type type() const { return REF_ITEM; }
1868
bool eq(const Item *item, bool binary_cmp) const
1870
Item *it= ((Item *) item)->real_item();
1871
return ref && (*ref)->eq(it, binary_cmp);
1875
my_decimal *val_decimal(my_decimal *);
1877
String *val_str(String* tmp);
1879
bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
1880
double val_result();
1881
int64_t val_int_result();
1882
String *str_result(String* tmp);
1883
my_decimal *val_decimal_result(my_decimal *);
1884
bool val_bool_result();
1885
bool send(Protocol *prot, String *tmp);
1886
void make_field(Send_field *field);
1887
bool fix_fields(THD *, Item **);
1888
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
1889
int save_in_field(Field *field, bool no_conversions);
1890
void save_org_in_field(Field *field);
1891
enum Item_result result_type () const { return (*ref)->result_type(); }
1892
enum_field_types field_type() const { return (*ref)->field_type(); }
1893
Field *get_tmp_table_field()
1894
{ return result_field ? result_field : (*ref)->get_tmp_table_field(); }
1895
Item *get_tmp_table_item(THD *thd);
1896
table_map used_tables() const
1898
return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
1900
void update_used_tables()
1903
(*ref)->update_used_tables();
1905
table_map not_null_tables() const { return (*ref)->not_null_tables(); }
1906
void set_result_field(Field *field) { result_field= field; }
1907
bool is_result_field() { return 1; }
1908
void save_in_result_field(bool no_conversions)
1910
(*ref)->save_in_field(result_field, no_conversions);
1914
return ref ? (*ref)->real_item() : this;
1916
bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
1917
{ return (*ref)->walk(processor, walk_subquery, arg); }
1918
virtual void print(String *str, enum_query_type query_type);
1919
bool result_as_int64_t()
1921
return (*ref)->result_as_int64_t();
1924
Item_field *filed_for_view_update()
1925
{ return (*ref)->filed_for_view_update(); }
1926
virtual Ref_Type ref_type() { return REF; }
1928
// Row emulation: forwarding of ROW-related calls to ref
1931
return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
1933
Item* element_index(uint32_t i)
1935
return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
1937
Item** addr(uint32_t i)
1939
return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
1941
bool check_cols(uint32_t c)
1943
return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
1944
: Item::check_cols(c);
1948
return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
1952
if (ref && result_type() == ROW_RESULT)
1953
(*ref)->bring_value();
1960
The same as Item_ref, but get value from val_* family of method to get
1961
value of item on which it referred instead of result* family.
1963
class Item_direct_ref :public Item_ref
1966
Item_direct_ref(Name_resolution_context *context_arg, Item **item,
1967
const char *table_name_arg,
1968
const char *field_name_arg,
1969
bool alias_name_used_arg= false)
1970
:Item_ref(context_arg, item, table_name_arg,
1971
field_name_arg, alias_name_used_arg)
1973
/* Constructor need to process subselect with temporary tables (see Item) */
1974
Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
1978
String *val_str(String* tmp);
1979
my_decimal *val_decimal(my_decimal *);
1982
bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
1983
virtual Ref_Type ref_type() { return DIRECT_REF; }
1987
Class for view fields, the same as Item_direct_ref, but call fix_fields
1988
of reference if it is not called yet
1990
class Item_direct_view_ref :public Item_direct_ref
1993
Item_direct_view_ref(Name_resolution_context *context_arg, Item **item,
1994
const char *table_name_arg,
1995
const char *field_name_arg)
1996
:Item_direct_ref(context_arg, item, table_name_arg, field_name_arg) {}
1997
/* Constructor need to process subselect with temporary tables (see Item) */
1998
Item_direct_view_ref(THD *thd, Item_direct_ref *item)
1999
:Item_direct_ref(thd, item) {}
2001
bool fix_fields(THD *, Item **);
2002
bool eq(const Item *item, bool binary_cmp) const;
2003
Item *get_tmp_table_item(THD *thd)
2005
Item *item= Item_ref::get_tmp_table_item(thd);
2009
virtual Ref_Type ref_type() { return VIEW_REF; }
2014
Class for outer fields.
2015
An object of this class is created when the select where the outer field was
2016
resolved is a grouping one. After it has been fixed the ref field will point
2017
to either an Item_ref or an Item_direct_ref object which will be used to
2019
See also comments for the fix_inner_refs() and the
2020
Item_field::fix_outer_field() functions.
2024
class Item_outer_ref :public Item_direct_ref
2028
/* The aggregate function under which this outer ref is used, if any. */
2029
Item_sum *in_sum_func;
2031
true <=> that the outer_ref is already present in the select list
2032
of the outer select.
2034
bool found_in_select_list;
2035
Item_outer_ref(Name_resolution_context *context_arg,
2036
Item_field *outer_field_arg)
2037
:Item_direct_ref(context_arg, 0, outer_field_arg->table_name,
2038
outer_field_arg->field_name),
2039
outer_ref(outer_field_arg), in_sum_func(0),
2040
found_in_select_list(0)
2046
Item_outer_ref(Name_resolution_context *context_arg, Item **item,
2047
const char *table_name_arg, const char *field_name_arg,
2048
bool alias_name_used_arg)
2049
:Item_direct_ref(context_arg, item, table_name_arg, field_name_arg,
2050
alias_name_used_arg),
2051
outer_ref(0), in_sum_func(0), found_in_select_list(1)
2053
void save_in_result_field(bool no_conversions __attribute__((unused)))
2055
outer_ref->save_org_in_field(result_field);
2057
bool fix_fields(THD *, Item **);
2058
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
2059
table_map used_tables() const
2061
return (*ref)->const_item() ? 0 : OUTER_REF_TABLE_BIT;
2063
virtual Ref_Type ref_type() { return OUTER_REF; }
2067
class Item_in_subselect;
2071
An object of this class:
2072
- Converts val_XXX() calls to ref->val_XXX_result() calls, like Item_ref.
2073
- Sets owner->was_null=true if it has returned a NULL value from any
2074
val_XXX() function. This allows to inject an Item_ref_null_helper
2075
object into subquery and then check if the subquery has produced a row
2079
class Item_ref_null_helper: public Item_ref
2082
Item_in_subselect* owner;
2084
Item_ref_null_helper(Name_resolution_context *context_arg,
2085
Item_in_subselect* master, Item **item,
2086
const char *table_name_arg, const char *field_name_arg)
2087
:Item_ref(context_arg, item, table_name_arg, field_name_arg),
2091
String* val_str(String* s);
2092
my_decimal *val_decimal(my_decimal *);
2094
bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate);
2095
virtual void print(String *str, enum_query_type query_type);
2097
we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
2099
table_map used_tables() const
2101
return (depended_from ?
2102
OUTER_REF_TABLE_BIT :
2103
(*ref)->used_tables() | RAND_TABLE_BIT);
2108
The following class is used to optimize comparing of date and bigint columns
2109
We need to save the original item ('ref') to be able to call
2110
ref->save_in_field(). This is used to create index search keys.
2112
An instance of Item_int_with_ref may have signed or unsigned integer value.
2116
class Item_int_with_ref :public Item_int
2120
Item_int_with_ref(int64_t i, Item *ref_arg, bool unsigned_arg) :
2121
Item_int(i), ref(ref_arg)
2123
unsigned_flag= unsigned_arg;
2125
int save_in_field(Field *field, bool no_conversions)
2127
return ref->save_in_field(field, no_conversions);
2130
virtual Item *real_item() { return ref; }
2133
#ifdef DRIZZLE_SERVER
2134
#include "item_sum.h"
2135
#include "item_func.h"
2136
#include "item_row.h"
2137
#include "item_cmpfunc.h"
2138
#include "item_strfunc.h"
2139
#include "item_timefunc.h"
2140
#include "item_subselect.h"
2143
class Item_copy_string :public Item
2145
enum enum_field_types cached_field_type;
2148
Item_copy_string(Item *i) :item(i)
2150
null_value= maybe_null= item->maybe_null;
2151
decimals=item->decimals;
2152
max_length=item->max_length;
2154
cached_field_type= item->field_type();
2156
enum Type type() const { return COPY_STR_ITEM; }
2157
enum Item_result result_type () const { return STRING_RESULT; }
2158
enum_field_types field_type() const { return cached_field_type; }
2163
return (null_value ? 0.0 :
2164
my_strntod(str_value.charset(), (char*) str_value.ptr(),
2165
str_value.length(), &end_not_used, &err_not_used));
2170
return null_value ? 0 : my_strntoll(str_value.charset(),str_value.ptr(),
2171
str_value.length(),10, (char**) 0,
2174
String *val_str(String*);
2175
my_decimal *val_decimal(my_decimal *);
2176
void make_field(Send_field *field) { item->make_field(field); }
2178
int save_in_field(Field *field,
2179
bool no_conversions __attribute__((unused)))
2181
return save_str_value_in_field(field, &str_value);
2183
table_map used_tables() const { return (table_map) 1L; }
2184
bool const_item() const { return 0; }
2185
bool is_null() { return null_value; }
2189
class Cached_item :public Sql_alloc
2193
Cached_item() :null_value(0) {}
2194
virtual bool cmp(void)=0;
2195
virtual ~Cached_item(); /*line -e1509 */
2198
class Cached_item_str :public Cached_item
2201
String value,tmp_value;
2203
Cached_item_str(THD *thd, Item *arg);
2205
~Cached_item_str(); // Deallocate String:s
2209
class Cached_item_real :public Cached_item
2214
Cached_item_real(Item *item_par) :item(item_par),value(0.0) {}
2218
class Cached_item_int :public Cached_item
2223
Cached_item_int(Item *item_par) :item(item_par),value(0) {}
2228
class Cached_item_decimal :public Cached_item
2233
Cached_item_decimal(Item *item_par);
2237
class Cached_item_field :public Cached_item
2239
unsigned char *buff;
2244
Cached_item_field(Field *arg_field) : field(arg_field)
2247
/* TODO: take the memory allocation below out of the constructor. */
2248
buff= (unsigned char*) sql_calloc(length=field->pack_length());
2253
class Item_default_value : public Item_field
2257
Item_default_value(Name_resolution_context *context_arg)
2258
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
2259
(const char *)NULL),
2261
Item_default_value(Name_resolution_context *context_arg, Item *a)
2262
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
2263
(const char *)NULL),
2265
enum Type type() const { return DEFAULT_VALUE_ITEM; }
2266
bool eq(const Item *item, bool binary_cmp) const;
2267
bool fix_fields(THD *, Item **);
2268
virtual void print(String *str, enum_query_type query_type);
2269
int save_in_field(Field *field_arg, bool no_conversions);
2270
table_map used_tables() const { return (table_map)0L; }
2272
bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
2274
return arg->walk(processor, walk_subquery, args) ||
2275
(this->*processor)(args);
2278
Item *transform(Item_transformer transformer, unsigned char *args);
2282
Item_insert_value -- an implementation of VALUES() function.
2283
You can use the VALUES(col_name) function in the UPDATE clause
2284
to refer to column values from the INSERT portion of the INSERT
2285
... UPDATE statement. In other words, VALUES(col_name) in the
2286
UPDATE clause refers to the value of col_name that would be
2287
inserted, had no duplicate-key conflict occurred.
2288
In all other places this function returns NULL.
2291
class Item_insert_value : public Item_field
2295
Item_insert_value(Name_resolution_context *context_arg, Item *a)
2296
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
2297
(const char *)NULL),
2299
bool eq(const Item *item, bool binary_cmp) const;
2300
bool fix_fields(THD *, Item **);
2301
virtual void print(String *str, enum_query_type query_type);
2302
int save_in_field(Field *field_arg, bool no_conversions)
2304
return Item_field::save_in_field(field_arg, no_conversions);
2307
We use RAND_TABLE_BIT to prevent Item_insert_value from
2308
being treated as a constant and precalculated before execution
2310
table_map used_tables() const { return RAND_TABLE_BIT; }
2312
bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
2314
return arg->walk(processor, walk_subquery, args) ||
2315
(this->*processor)(args);
2317
bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
2322
class Item_cache: public Item_basic_constant
2326
table_map used_table_map;
2328
Field that this object will get value from. This is set/used by
2329
index-based subquery engines to detect and remove the equality injected
2330
by IN->EXISTS transformation.
2331
For all other uses of Item_cache, cached_field doesn't matter.
2333
Field *cached_field;
2334
enum enum_field_types cached_field_type;
2337
example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR)
2342
Item_cache(enum_field_types field_type_arg):
2343
example(0), used_table_map(0), cached_field(0), cached_field_type(field_type_arg)
2349
void set_used_tables(table_map map) { used_table_map= map; }
2351
virtual bool allocate(uint32_t i __attribute__((unused)))
2353
virtual bool setup(Item *item)
2356
max_length= item->max_length;
2357
decimals= item->decimals;
2358
collation.set(item->collation);
2359
unsigned_flag= item->unsigned_flag;
2360
if (item->type() == FIELD_ITEM)
2361
cached_field= ((Item_field *)item)->field;
2364
virtual void store(Item *)= 0;
2365
enum Type type() const { return CACHE_ITEM; }
2366
enum_field_types field_type() const { return cached_field_type; }
2367
static Item_cache* get_cache(const Item *item);
2368
table_map used_tables() const { return used_table_map; }
2369
virtual void keep_array() {}
2370
virtual void print(String *str, enum_query_type query_type);
2371
bool eq_def(Field *field)
2373
return cached_field ? cached_field->eq_def (field) : false;
2375
bool eq(const Item *item,
2376
bool binary_cmp __attribute__((unused))) const
2378
return this == item;
2383
class Item_cache_int: public Item_cache
2388
Item_cache_int(): Item_cache(), value(0) {}
2389
Item_cache_int(enum_field_types field_type_arg):
2390
Item_cache(field_type_arg), value(0) {}
2392
void store(Item *item);
2393
void store(Item *item, int64_t val_arg);
2394
double val_real() { assert(fixed == 1); return (double) value; }
2395
int64_t val_int() { assert(fixed == 1); return value; }
2396
String* val_str(String *str);
2397
my_decimal *val_decimal(my_decimal *);
2398
enum Item_result result_type() const { return INT_RESULT; }
2399
bool result_as_int64_t() { return true; }
2403
class Item_cache_real: public Item_cache
2407
Item_cache_real(): Item_cache(), value(0) {}
2409
void store(Item *item);
2410
double val_real() { assert(fixed == 1); return value; }
2412
String* val_str(String *str);
2413
my_decimal *val_decimal(my_decimal *);
2414
enum Item_result result_type() const { return REAL_RESULT; }
2418
class Item_cache_decimal: public Item_cache
2421
my_decimal decimal_value;
2423
Item_cache_decimal(): Item_cache() {}
2425
void store(Item *item);
2428
String* val_str(String *str);
2429
my_decimal *val_decimal(my_decimal *);
2430
enum Item_result result_type() const { return DECIMAL_RESULT; }
2434
class Item_cache_str: public Item_cache
2436
char buffer[STRING_BUFFER_USUAL_SIZE];
2437
String *value, value_buff;
2441
Item_cache_str(const Item *item) :
2442
Item_cache(), value(0),
2443
is_varbinary(item->type() == FIELD_ITEM &&
2444
((const Item_field *) item)->field->type() ==
2445
DRIZZLE_TYPE_VARCHAR &&
2446
!((const Item_field *) item)->field->has_charset())
2448
void store(Item *item);
2451
String* val_str(String *) { assert(fixed == 1); return value; }
2452
my_decimal *val_decimal(my_decimal *);
2453
enum Item_result result_type() const { return STRING_RESULT; }
2454
const CHARSET_INFO *charset() const { return value->charset(); };
2455
int save_in_field(Field *field, bool no_conversions);
2458
class Item_cache_row: public Item_cache
2460
Item_cache **values;
2461
uint32_t item_count;
2465
:Item_cache(), values(0), item_count(2), save_array(0) {}
2468
'allocate' used only in row transformer, to preallocate space for row
2471
bool allocate(uint32_t num);
2473
'setup' is needed only by row => it not called by simple row subselect
2474
(only by IN subselect (in subselect optimizer))
2476
bool setup(Item *item);
2477
void store(Item *item);
2478
void illegal_method_call(const char *);
2479
void make_field(Send_field *)
2481
illegal_method_call((const char*)"make_field");
2485
illegal_method_call((const char*)"val");
2490
illegal_method_call((const char*)"val_int");
2493
String *val_str(String *)
2495
illegal_method_call((const char*)"val_str");
2498
my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
2500
illegal_method_call((const char*)"val_decimal");
2504
enum Item_result result_type() const { return ROW_RESULT; }
2506
uint32_t cols() { return item_count; }
2507
Item *element_index(uint32_t i) { return values[i]; }
2508
Item **addr(uint32_t i) { return (Item **) (values + i); }
2509
bool check_cols(uint32_t c);
2512
void keep_array() { save_array= 1; }
2515
Item_cache::cleanup();
2517
memset(values, 0, item_count*sizeof(Item**));
2526
Item_type_holder used to store type. name, length of Item for UNIONS &
2529
Item_type_holder do not need cleanup() because its time of live limited by
2530
single SP/PS execution.
2532
class Item_type_holder: public Item
2535
TYPELIB *enum_set_typelib;
2536
enum_field_types fld_type;
2538
void get_full_info(Item *item);
2540
/* It is used to count decimal precision in join_types */
2541
int prev_decimal_int_part;
2543
Item_type_holder(THD*, Item*);
2545
Item_result result_type() const;
2546
enum_field_types field_type() const { return fld_type; };
2547
enum Type type() const { return TYPE_HOLDER; }
2550
my_decimal *val_decimal(my_decimal *);
2551
String *val_str(String*);
2552
bool join_types(THD *thd, Item *);
2553
Field *make_field_by_type(Table *table);
2554
static uint32_t display_length(Item *item);
2555
static enum_field_types get_real_type(Item *);
2559
class st_select_lex;
2560
void mark_select_range_as_dependent(THD *thd,
2561
st_select_lex *last_select,
2562
st_select_lex *current_sel,
901
2563
Field *found_field, Item *found_item,
902
2564
Item_ident *resolved_item);
904
extern void resolve_const_item(Session *session, Item **ref, Item *cmp_item);
906
Return true if the value stored in the field is equal to the const
909
We need to use this on the range optimizer because in some cases
910
we can't store the value in the field without some precision/character loss.
2566
extern Cached_item *new_Cached_item(THD *thd, Item *item,
2567
bool use_result_field);
2568
extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
912
2569
extern bool field_is_equal_to_item(Field *field,Item *item);
915
Create field for temporary table.
919
This is here for now because it needs the Item::Type. It should live
920
in Field or Table once item.h is clean enough to actually include
922
@param session Thread handler
923
@param table Temporary table
924
@param item Item to create a field for
925
@param type Type of item (normally item->type)
926
@param copy_func If set and item is a function, store copy of item
928
@param from_field if field will be created using other field as example,
929
pointer example field will be written here
930
@param default_field If field has a default value field, store it here
931
@param group 1 if we are going to do a relative group by on result
932
@param modify_item 1 if item->result_field should point to new item.
933
This is relevent for how fill_record() is going to
935
If modify_item is 1 then fill_record() will update
936
the record in the original table.
937
If modify_item is 0 then fill_record() will update
939
@param convert_blob_length If >0 create a varstring(convert_blob_length)
940
field instead of blob.
947
Field *create_tmp_field(Session *session,
956
bool make_copy_field,
957
uint32_t convert_blob_length);
959
} /* namespace drizzled */
961
#endif /* DRIZZLED_ITEM_H */