1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
#ifdef USE_PRAGMA_INTERFACE
18
#pragma interface /* gcc class implementation */
23
void item_init(void); /* Init item functions */
27
"Declared Type Collation"
28
A combination of collation and its derivation.
30
Flags for collation aggregation modes:
31
MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
32
MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
34
MY_COLL_ALLOW_CONV - allow any kind of conversion
35
(combination of the above two)
36
MY_COLL_DISALLOW_NONE - don't allow return DERIVATION_NONE
37
(e.g. when aggregating for comparison)
38
MY_COLL_CMP_CONV - combination of MY_COLL_ALLOW_CONV
39
and MY_COLL_DISALLOW_NONE
42
#define MY_COLL_ALLOW_SUPERSET_CONV 1
43
#define MY_COLL_ALLOW_COERCIBLE_CONV 2
44
#define MY_COLL_ALLOW_CONV 3
45
#define MY_COLL_DISALLOW_NONE 4
46
#define MY_COLL_CMP_CONV 7
50
CHARSET_INFO *collation;
51
enum Derivation derivation;
54
void set_repertoire_from_charset(CHARSET_INFO *cs)
56
repertoire= cs->state & MY_CS_PUREASCII ?
57
MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
61
collation= &my_charset_bin;
62
derivation= DERIVATION_NONE;
63
repertoire= MY_REPERTOIRE_UNICODE30;
65
DTCollation(CHARSET_INFO *collation_arg, Derivation derivation_arg)
67
collation= collation_arg;
68
derivation= derivation_arg;
69
set_repertoire_from_charset(collation_arg);
71
void set(DTCollation &dt)
73
collation= dt.collation;
74
derivation= dt.derivation;
75
repertoire= dt.repertoire;
77
void set(CHARSET_INFO *collation_arg, Derivation derivation_arg)
79
collation= collation_arg;
80
derivation= derivation_arg;
81
set_repertoire_from_charset(collation_arg);
83
void set(CHARSET_INFO *collation_arg,
84
Derivation derivation_arg,
87
collation= collation_arg;
88
derivation= derivation_arg;
89
repertoire= repertoire_arg;
91
void set(CHARSET_INFO *collation_arg)
93
collation= collation_arg;
94
set_repertoire_from_charset(collation_arg);
96
void set(Derivation derivation_arg)
97
{ derivation= derivation_arg; }
98
bool aggregate(DTCollation &dt, uint flags= 0);
99
bool set(DTCollation &dt1, DTCollation &dt2, uint flags= 0)
100
{ set(dt1); return aggregate(dt2, flags); }
101
const char *derivation_name() const
105
case DERIVATION_IGNORABLE: return "IGNORABLE";
106
case DERIVATION_COERCIBLE: return "COERCIBLE";
107
case DERIVATION_IMPLICIT: return "IMPLICIT";
108
case DERIVATION_SYSCONST: return "SYSCONST";
109
case DERIVATION_EXPLICIT: return "EXPLICIT";
110
case DERIVATION_NONE: return "NONE";
111
default: return "UNKNOWN";
116
/*************************************************************************/
118
A framework to easily handle different return types for hybrid items
119
(hybrid item is an item whose operand can be of any type, e.g. integer,
123
struct Hybrid_type_traits;
131
Use two decimal buffers interchangeably to speed up += operation
132
which has no native support in decimal library.
133
Hybrid_type+= arg is implemented as dec_buf[1]= dec_buf[0] + arg.
134
The third decimal is used as a handy temporary storage.
136
my_decimal dec_buf[3];
140
Traits moved to a separate class to
141
a) be able to easily change object traits in runtime
142
b) they work as a differentiator for the union above
144
const Hybrid_type_traits *traits;
147
/* XXX: add traits->copy() when needed */
148
Hybrid_type(const Hybrid_type &rhs) :traits(rhs.traits) {}
152
/* Hybryd_type_traits interface + default implementation for REAL_RESULT */
154
struct Hybrid_type_traits
156
virtual Item_result type() const { return REAL_RESULT; }
159
fix_length_and_dec(Item *item, Item *arg) const;
161
/* Hybrid_type operations. */
162
virtual void set_zero(Hybrid_type *val) const { val->real= 0.0; }
163
virtual void add(Hybrid_type *val, Field *f) const
164
{ val->real+= f->val_real(); }
165
virtual void div(Hybrid_type *val, ulonglong u) const
166
{ val->real/= ulonglong2double(u); }
168
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const
169
{ return (longlong) rint(val->real); }
170
virtual double val_real(Hybrid_type *val) const { return val->real; }
171
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const;
172
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
173
static const Hybrid_type_traits *instance();
174
Hybrid_type_traits() {}
175
virtual ~Hybrid_type_traits() {}
179
struct Hybrid_type_traits_decimal: public Hybrid_type_traits
181
virtual Item_result type() const { return DECIMAL_RESULT; }
184
fix_length_and_dec(Item *arg, Item *item) const;
186
/* Hybrid_type operations. */
187
virtual void set_zero(Hybrid_type *val) const;
188
virtual void add(Hybrid_type *val, Field *f) const;
189
virtual void div(Hybrid_type *val, ulonglong u) const;
191
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const;
192
virtual double val_real(Hybrid_type *val) const;
193
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const
194
{ return &val->dec_buf[val->used_dec_buf_no]; }
195
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
196
static const Hybrid_type_traits_decimal *instance();
197
Hybrid_type_traits_decimal() {};
201
struct Hybrid_type_traits_integer: public Hybrid_type_traits
203
virtual Item_result type() const { return INT_RESULT; }
206
fix_length_and_dec(Item *arg, Item *item) const;
208
/* Hybrid_type operations. */
209
virtual void set_zero(Hybrid_type *val) const
211
virtual void add(Hybrid_type *val, Field *f) const
212
{ val->integer+= f->val_int(); }
213
virtual void div(Hybrid_type *val, ulonglong u) const
214
{ val->integer/= (longlong) u; }
216
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const
217
{ return val->integer; }
218
virtual double val_real(Hybrid_type *val) const
219
{ return (double) val->integer; }
220
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const
222
int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
223
return &val->dec_buf[2];
225
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const
226
{ buf->set(val->integer, &my_charset_bin); return buf;}
227
static const Hybrid_type_traits_integer *instance();
228
Hybrid_type_traits_integer() {};
232
void dummy_error_processor(THD *thd, void *data);
234
void view_error_processor(THD *thd, void *data);
237
Instances of Name_resolution_context store the information necesary for
238
name resolution of Items and other context analysis of a query made in
241
This structure is a part of SELECT_LEX, a pointer to this structure is
242
assigned when an item is created (which happens mostly during parsing
243
(sql_yacc.yy)), but the structure itself will be initialized after parsing
246
TODO: move subquery of INSERT ... SELECT and CREATE ... SELECT to
247
separate SELECT_LEX which allow to remove tricks of changing this
248
structure before and after INSERT/CREATE and its SELECT to make correct
249
field name resolution.
251
struct Name_resolution_context: Sql_alloc
254
The name resolution context to search in when an Item cannot be
255
resolved in this context (the context of an outer select)
257
Name_resolution_context *outer_context;
260
List of tables used to resolve the items of this context. Usually these
261
are tables from the FROM clause of SELECT statement. The exceptions are
262
INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
263
subquery is not moved to a separate SELECT_LEX. For these types of
264
statements we have to change this member dynamically to ensure correct
265
name resolution of different parts of the statement.
267
TABLE_LIST *table_list;
269
In most cases the two table references below replace 'table_list' above
270
for the purpose of name resolution. The first and last name resolution
271
table references allow us to search only in a sub-tree of the nested
272
join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
275
TABLE_LIST *first_name_resolution_table;
277
Last table to search in the list of leaf table references that begins
278
with first_name_resolution_table.
280
TABLE_LIST *last_name_resolution_table;
283
SELECT_LEX item belong to, in case of merged VIEW it can differ from
284
SELECT_LEX where item was created, so we can't use table_list/field_list
287
st_select_lex *select_lex;
290
Processor of errors caused during Item name resolving, now used only to
291
hide underlying tables in errors about views (i.e. it substitute some
294
void (*error_processor)(THD *, void *);
295
void *error_processor_data;
298
When TRUE items are resolved in this context both against the
299
SELECT list and this->table_list. If FALSE, items are resolved
300
only against this->table_list.
302
bool resolve_in_select_list;
305
Security context of this name resolution context. It's used for views
306
and is non-zero only if the view is defined with SQL SECURITY DEFINER.
308
Security_context *security_ctx;
310
Name_resolution_context()
311
:outer_context(0), table_list(0), select_lex(0),
312
error_processor_data(0),
318
resolve_in_select_list= FALSE;
319
error_processor= &dummy_error_processor;
320
first_name_resolution_table= NULL;
321
last_name_resolution_table= NULL;
324
void resolve_in_table_list_only(TABLE_LIST *tables)
326
table_list= first_name_resolution_table= tables;
327
resolve_in_select_list= FALSE;
330
void process_error(THD *thd)
332
(*error_processor)(thd, error_processor_data);
338
Store and restore the current state of a name resolution context.
341
class Name_resolution_context_state
344
TABLE_LIST *save_table_list;
345
TABLE_LIST *save_first_name_resolution_table;
346
TABLE_LIST *save_next_name_resolution_table;
347
bool save_resolve_in_select_list;
348
TABLE_LIST *save_next_local;
351
Name_resolution_context_state() {} /* Remove gcc warning */
354
/* Save the state of a name resolution context. */
355
void save_state(Name_resolution_context *context, TABLE_LIST *table_list)
357
save_table_list= context->table_list;
358
save_first_name_resolution_table= context->first_name_resolution_table;
359
save_resolve_in_select_list= context->resolve_in_select_list;
360
save_next_local= table_list->next_local;
361
save_next_name_resolution_table= table_list->next_name_resolution_table;
364
/* Restore a name resolution context from saved state. */
365
void restore_state(Name_resolution_context *context, TABLE_LIST *table_list)
367
table_list->next_local= save_next_local;
368
table_list->next_name_resolution_table= save_next_name_resolution_table;
369
context->table_list= save_table_list;
370
context->first_name_resolution_table= save_first_name_resolution_table;
371
context->resolve_in_select_list= save_resolve_in_select_list;
374
TABLE_LIST *get_first_name_resolution_table()
376
return save_first_name_resolution_table;
382
This enum is used to report information about monotonicity of function
383
represented by Item* tree.
384
Monotonicity is defined only for Item* trees that represent table
385
partitioning expressions (i.e. have no subselects/user vars/PS parameters
386
etc etc). An Item* tree is assumed to have the same monotonicity properties
387
as its correspoinding function F:
389
[signed] longlong F(field1, field2, ...) {
390
put values of field_i into table record buffer;
391
return item->val_int();
395
At the moment function monotonicity is not well defined (and so may be
396
incorrect) for Item trees with parameters/return types that are different
397
from INT_RESULT, may be NULL, or are unsigned.
398
It will be possible to address this issue once the related partitioning bugs
399
(BUG#16002, BUG#15447, BUG#13436) are fixed.
402
typedef enum monotonicity_info
404
NON_MONOTONIC, /* none of the below holds */
405
MONOTONIC_INCREASING, /* F() is unary and (x < y) => (F(x) <= F(y)) */
406
MONOTONIC_STRICT_INCREASING /* F() is unary and (x < y) => (F(x) < F(y)) */
407
} enum_monotonicity_info;
409
/*************************************************************************/
410
typedef bool (Item::*Item_processor) (uchar *arg);
414
argp in/out IN: Analysis parameter
415
OUT: Parameter to be passed to the transformer
418
TRUE Invoke the transformer
422
typedef bool (Item::*Item_analyzer) (uchar **argp);
423
typedef Item* (Item::*Item_transformer) (uchar *arg);
424
typedef void (*Cond_traverser) (const Item *item, void *arg);
429
Item(const Item &); /* Prevent use of these */
430
void operator=(Item &);
431
/* Cache of the result of is_expensive(). */
432
int8 is_expensive_cache;
433
virtual bool is_expensive_processor(uchar *arg) { return 0; }
436
static void *operator new(size_t size)
437
{ return sql_alloc(size); }
438
static void *operator new(size_t size, MEM_ROOT *mem_root)
439
{ return alloc_root(mem_root, size); }
440
static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
441
static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
443
enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM,
444
INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM,
445
COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM,
446
PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
447
FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
448
SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
449
PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM,
450
XPATH_NODESET, XPATH_NODESET_CMP,
453
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
455
enum traverse_order { POSTFIX, PREFIX };
457
/* Reuse size, only used by SP local variable assignment, otherwize 0 */
461
str_values's main purpose is to be used to cache the value in
465
char * name; /* Name from select */
466
/* Original item name (if it was renamed)*/
470
uint name_length; /* Length of name */
473
my_bool maybe_null; /* If item may be null */
474
my_bool null_value; /* if item is null */
475
my_bool unsigned_flag;
476
my_bool with_sum_func;
477
my_bool fixed; /* If item fixed with fix_fields */
478
my_bool is_autogenerated_name; /* indicate was name of this Item
479
autogenerated or set by user */
480
DTCollation collation;
481
my_bool with_subselect; /* If this item is a subselect or some
482
of its arguments is or contains a
483
subselect. Computed by fix_fields. */
484
Item_result cmp_context; /* Comparison context */
485
// alloc & destruct is done as start of select using sql_alloc
488
Constructor used by Item_field, Item_ref & aggregate (sum) functions.
489
Used for duplicating lists in processing queries with temporary
491
Also it used for Item_cond_and/Item_cond_or for creating
492
top AND/OR structure of WHERE clause to protect it of
493
optimisation changes in prepared statements
495
Item(THD *thd, Item *item);
502
void set_name(const char *str, uint length, CHARSET_INFO *cs);
503
void rename(char *new_name);
504
void init_make_field(Send_field *tmp_field,enum enum_field_types type);
505
virtual void cleanup();
506
virtual void make_field(Send_field *field);
507
Field *make_string_field(TABLE *table);
508
virtual bool fix_fields(THD *, Item **);
510
Fix after some tables has been pulled out. Basically re-calculate all
511
attributes that are dependent on the tables.
513
virtual void fix_after_pullout(st_select_lex *new_parent, Item **ref) {};
516
should be used in case where we are sure that we do not need
517
complete fix_fields() procedure.
519
inline void quick_fix_field() { fixed= 1; }
520
/* Function returns 1 on overflow and -1 on fatal errors */
521
int save_in_field_no_warnings(Field *field, bool no_conversions);
522
virtual int save_in_field(Field *field, bool no_conversions);
523
virtual void save_org_in_field(Field *field)
524
{ (void) save_in_field(field, 1); }
525
virtual int save_safe_in_field(Field *field)
526
{ return save_in_field(field, 1); }
527
virtual bool send(Protocol *protocol, String *str);
528
virtual bool eq(const Item *, bool binary_cmp) const;
529
virtual Item_result result_type() const { return REAL_RESULT; }
530
virtual Item_result cast_to_int_type() const { return result_type(); }
531
virtual enum_field_types string_field_type() const;
532
virtual enum_field_types field_type() const;
533
virtual enum Type type() const =0;
536
Return information about function monotonicity. See comment for
537
enum_monotonicity_info for details. This function can only be called
538
after fix_fields() call.
540
virtual enum_monotonicity_info get_monotonicity_info() const
541
{ return NON_MONOTONIC; }
544
Convert "func_arg $CMP$ const" half-interval into "FUNC(func_arg) $CMP2$ const2"
548
left_endp FALSE <=> The interval is "x < const" or "x <= const"
549
TRUE <=> The interval is "x > const" or "x >= const"
551
incl_endp IN TRUE <=> the comparison is '<' or '>'
552
FALSE <=> the comparison is '<=' or '>='
553
OUT The same but for the "F(x) $CMP$ F(const)" comparison
556
This function is defined only for unary monotonic functions. The caller
557
supplies the source half-interval
561
The value of const is supplied implicitly as the value this item's
562
argument, the form of $CMP$ comparison is specified through the
563
function's arguments. The calle returns the result interval
567
passing back F(const) as the return value, and the form of $CMP2$
568
through the out parameter. NULL values are assumed to be comparable and
569
be less than any non-NULL values.
572
The output range bound, which equal to the value of val_int()
573
- If the value of the function is NULL then the bound is the
574
smallest possible value of LONGLONG_MIN
576
virtual longlong val_int_endpoint(bool left_endp, bool *incl_endp)
577
{ DBUG_ASSERT(0); return 0; }
580
/* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */
582
Return double precision floating point representation of item.
588
In case of NULL value return 0.0 and set null_value flag to TRUE.
589
If value is not null null_value flag will be reset to FALSE.
591
virtual double val_real()=0;
593
Return integer representation of item.
599
In case of NULL value return 0 and set null_value flag to TRUE.
600
If value is not null null_value flag will be reset to FALSE.
602
virtual longlong val_int()=0;
604
This is just a shortcut to avoid the cast. You should still use
605
unsigned_flag to check the sign of the item.
607
inline ulonglong val_uint() { return (ulonglong) val_int(); }
609
Return string representation of this item object.
613
str an allocated buffer this or any nested Item object can use to
614
store return value of this method.
617
Buffer passed via argument should only be used if the item itself
618
doesn't have an own String buffer. In case when the item maintains
619
it's own string buffer, it's preferable to return it instead to
620
minimize number of mallocs/memcpys.
621
The caller of this method can modify returned string, but only in case
622
when it was allocated on heap, (is_alloced() is true). This allows
623
the caller to efficiently use a buffer allocated by a child without
624
having to allocate a buffer of it's own. The buffer, given to
625
val_str() as argument, belongs to the caller and is later used by the
626
caller at it's own choosing.
627
A few implications from the above:
628
- unless you return a string object which only points to your buffer
629
but doesn't manages it you should be ready that it will be
631
- even for not allocated strings (is_alloced() == false) the caller
632
can change charset (see Item_func_{typecast/binary}. XXX: is this
634
- still you should try to minimize data copying and return internal
635
object whenever possible.
638
In case of NULL value return 0 (NULL pointer) and set null_value flag
640
If value is not null null_value flag will be reset to FALSE.
642
virtual String *val_str(String *str)=0;
644
Return decimal representation of item with fixed point.
648
decimal_buffer buffer which can be used by Item for returning value
652
Returned value should not be changed if it is not the same which was
656
Return pointer on my_decimal (it can be other then passed via argument)
657
if value is not NULL (null_value flag will be reset to FALSE).
658
In case of NULL value it return 0 pointer and set null_value flag
661
virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
663
Return boolean value of item.
666
FALSE value is false or NULL
667
TRUE value is true (not equal to 0)
669
virtual bool val_bool();
670
virtual String *val_nodeset(String*) { return 0; }
671
/* Helper functions, see item_sum.cc */
672
String *val_string_from_real(String *str);
673
String *val_string_from_int(String *str);
674
String *val_string_from_decimal(String *str);
675
my_decimal *val_decimal_from_real(my_decimal *decimal_value);
676
my_decimal *val_decimal_from_int(my_decimal *decimal_value);
677
my_decimal *val_decimal_from_string(my_decimal *decimal_value);
678
my_decimal *val_decimal_from_date(my_decimal *decimal_value);
679
my_decimal *val_decimal_from_time(my_decimal *decimal_value);
680
longlong val_int_from_decimal();
681
double val_real_from_decimal();
683
int save_time_in_field(Field *field);
684
int save_date_in_field(Field *field);
685
int save_str_value_in_field(Field *field, String *result);
687
virtual Field *get_tmp_table_field() { return 0; }
688
/* This is also used to create fields in CREATE ... SELECT: */
689
virtual Field *tmp_table_field(TABLE *t_arg) { return 0; }
690
virtual const char *full_name() const { return name ? name : "???"; }
693
*result* family of methods is analog of *val* family (see above) but
694
return value of result_field of item if it is present. If Item have not
695
result field, it return val(). This methods set null_value flag in same
696
way as *val* methods do it.
698
virtual double val_result() { return val_real(); }
699
virtual longlong val_int_result() { return val_int(); }
700
virtual String *str_result(String* tmp) { return val_str(tmp); }
701
virtual my_decimal *val_decimal_result(my_decimal *val)
702
{ return val_decimal(val); }
703
virtual bool val_bool_result() { return val_bool(); }
705
/* bit map of tables used by item */
706
virtual table_map used_tables() const { return (table_map) 0L; }
708
Return table map of tables that can't be NULL tables (tables that are
709
used in a context where if they would contain a NULL row generated
710
by a LEFT or RIGHT join, the item would not be true).
711
This expression is used on WHERE item to determinate if a LEFT JOIN can be
712
converted to a normal join.
713
Generally this function should return used_tables() if the function
714
would return null if any of the arguments are null
715
As this is only used in the beginning of optimization, the value don't
716
have to be updated in update_used_tables()
718
virtual table_map not_null_tables() const { return used_tables(); }
720
Returns true if this is a simple constant item like an integer, not
721
a constant expression. Used in the optimizer to propagate basic constants.
723
virtual bool basic_const_item() const { return 0; }
724
/* cloning of constant items (0 if it is not const) */
725
virtual Item *clone_item() { return 0; }
726
virtual cond_result eq_cmp_result() const { return COND_OK; }
727
inline uint float_length(uint decimals_par) const
728
{ return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;}
729
virtual uint decimal_precision() const;
730
inline int decimal_int_part() const
731
{ return my_decimal_int_part(decimal_precision(), decimals); }
733
Returns true if this is constant (during query execution, i.e. its value
734
will not change until next fix_fields) and its value is known.
736
virtual bool const_item() const { return used_tables() == 0; }
738
Returns true if this is constant but its value may be not known yet.
739
(Can be used for parameters of prep. stmts or of stored procedures.)
741
virtual bool const_during_execution() const
742
{ return (used_tables() & ~PARAM_TABLE_BIT) == 0; }
745
This method is used for to:
746
- to generate a view definition query (SELECT-statement);
747
- to generate a SQL-query for EXPLAIN EXTENDED;
748
- to generate a SQL-query to be shown in INFORMATION_SCHEMA;
751
For more information about view definition query, INFORMATION_SCHEMA
752
query and why they should be generated from the Item-tree, @see
753
mysql_register_view().
755
virtual inline void print(String *str, enum_query_type query_type)
757
str->append(full_name());
760
void print_item_w_name(String *, enum_query_type query_type);
761
virtual void update_used_tables() {}
762
virtual void split_sum_func(THD *thd, Item **ref_pointer_array,
763
List<Item> &fields) {}
764
/* Called for items that really have to be split */
765
void split_sum_func2(THD *thd, Item **ref_pointer_array, List<Item> &fields,
766
Item **ref, bool skip_registered);
767
virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
768
virtual bool get_time(MYSQL_TIME *ltime);
769
virtual bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
770
{ return get_date(ltime,fuzzydate); }
772
The method allows to determine nullness of a complex expression
773
without fully evaluating it, instead of calling val/result*() then
774
checking null_value. Used in Item_func_isnull/Item_func_isnotnull
775
and Item_sum_count/Item_sum_count_distinct.
776
Any new item which can be NULL must implement this method.
778
virtual bool is_null() { return 0; }
781
Make sure the null_value member has a correct value.
783
virtual void update_null_value () { (void) val_int(); }
786
Inform the item that there will be no distinction between its result
790
This function will be called for eg. Items that are top-level AND-parts
791
of the WHERE clause. Items implementing this function (currently
792
Item_cond_and and subquery-related item) enable special optimizations
793
when they are "top level".
795
virtual void top_level_item() {}
797
set field of temporary table for Item which can be switched on temporary
798
table during query processing (grouping and so on)
800
virtual void set_result_field(Field *field) {}
801
virtual bool is_result_field() { return 0; }
802
virtual bool is_bool_func() { return 0; }
803
virtual void save_in_result_field(bool no_conversions) {}
805
set value of aggregate function in case of no rows for grouping were found
807
virtual void no_rows_in_result() {}
808
virtual Item *copy_or_same(THD *thd) { return this; }
809
virtual Item *copy_andor_structure(THD *thd) { return this; }
810
virtual Item *real_item() { return this; }
811
virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
813
static CHARSET_INFO *default_charset();
814
virtual CHARSET_INFO *compare_collation() { return NULL; }
816
virtual bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
818
return (this->*processor)(arg);
821
virtual Item* transform(Item_transformer transformer, uchar *arg);
824
This function performs a generic "compilation" of the Item tree.
825
The process of compilation is assumed to go as follows:
829
if (this->*some_analyzer(...))
831
compile children if any;
832
this->*some_transformer(...);
836
i.e. analysis is performed top-down while transformation is done
839
virtual Item* compile(Item_analyzer analyzer, uchar **arg_p,
840
Item_transformer transformer, uchar *arg_t)
842
if ((this->*analyzer) (arg_p))
843
return ((this->*transformer) (arg_t));
847
virtual void traverse_cond(Cond_traverser traverser,
848
void *arg, traverse_order order)
850
(*traverser)(this, arg);
853
virtual bool remove_dependence_processor(uchar * arg) { return 0; }
854
virtual bool remove_fixed(uchar * arg) { fixed= 0; return 0; }
855
virtual bool cleanup_processor(uchar *arg);
856
virtual bool collect_item_field_processor(uchar * arg) { return 0; }
857
virtual bool find_item_in_field_list_processor(uchar *arg) { return 0; }
858
virtual bool change_context_processor(uchar *context) { return 0; }
859
virtual bool reset_query_id_processor(uchar *query_id_arg) { return 0; }
860
virtual bool register_field_in_read_map(uchar *arg) { return 0; }
861
virtual bool subst_argument_checker(uchar **arg)
868
virtual Item *equal_fields_propagator(uchar * arg) { return this; }
869
virtual bool set_no_const_sub(uchar *arg) { return FALSE; }
870
virtual Item *replace_equal_field(uchar * arg) { return this; }
873
For SP local variable returns pointer to Item representing its
874
current value and pointer to current Item otherwise.
876
virtual Item *this_item() { return this; }
877
virtual const Item *this_item() const { return this; }
880
For SP local variable returns address of pointer to Item representing its
881
current value and pointer passed via parameter otherwise.
883
virtual Item **this_item_addr(THD *thd, Item **addr_arg) { return addr_arg; }
886
virtual uint cols() { return 1; }
887
virtual Item* element_index(uint i) { return this; }
888
virtual Item** addr(uint i) { return 0; }
889
virtual bool check_cols(uint c);
890
// It is not row => null inside is impossible
891
virtual bool null_inside() { return 0; }
892
// used in row subselects to get value of elements
893
virtual void bring_value() {}
895
Field *tmp_table_field_from_field_type(TABLE *table, bool fixed_length);
896
virtual Item_field *filed_for_view_update() { return 0; }
898
virtual Item *neg_transformer(THD *thd) { return NULL; }
899
virtual Item *update_value_transformer(uchar *select_arg) { return this; }
900
virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
908
result_as_longlong() must return TRUE for Items representing DATE/TIME
909
functions and DATE/TIME table fields.
910
Those Items have result_type()==STRING_RESULT (and not INT_RESULT), but
911
their values should be compared as integers (because the integer
912
representation is more precise than the string one).
914
virtual bool result_as_longlong() { return FALSE; }
918
Test whether an expression is expensive to compute. Used during
919
optimization to avoid computing expensive expressions during this
920
phase. Also used to force temp tables when sorting on expensive
923
Normally we should have a method:
924
cost Item::execution_cost(),
925
where 'cost' is either 'double' or some structure of various cost
928
virtual bool is_expensive()
930
if (is_expensive_cache < 0)
931
is_expensive_cache= walk(&Item::is_expensive_processor, 0, (uchar*)0);
932
return test(is_expensive_cache);
934
String *check_well_formed_result(String *str, bool send_error= 0);
935
bool eq_by_collation(Item *item, bool binary_cmp, CHARSET_INFO *cs);
939
class Item_basic_constant :public Item
942
/* to prevent drop fixed flag (no need parent cleanup call) */
946
Restore the original field name as it might not have been allocated
947
in the statement memory. If the name is auto generated, it must be
948
done again between subsequent executions of a prepared statement.
955
bool agg_item_collations(DTCollation &c, const char *name,
956
Item **items, uint nitems, uint flags, int item_sep);
957
bool agg_item_collations_for_comparison(DTCollation &c, const char *name,
958
Item **items, uint nitems, uint flags);
959
bool agg_item_charsets(DTCollation &c, const char *name,
960
Item **items, uint nitems, uint flags, int item_sep);
963
class Item_num: public Item_basic_constant
966
Item_num() {} /* Remove gcc warning */
967
virtual Item_num *neg()= 0;
968
Item *safe_charset_converter(CHARSET_INFO *tocs);
971
#define NO_CACHED_FIELD_INDEX ((uint)(-1))
974
class Item_ident :public Item
978
We have to store initial values of db_name, table_name and field_name
979
to be able to restore them during cleanup() because they can be
980
updated during fix_fields() to values from Field object and life-time
981
of those is shorter than life-time of Item_field.
983
const char *orig_db_name;
984
const char *orig_table_name;
985
const char *orig_field_name;
988
Name_resolution_context *context;
990
const char *table_name;
991
const char *field_name;
992
bool alias_name_used; /* true if item was resolved against alias */
994
Cached value of index for this field in table->field array, used by prep.
995
stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX
996
if index value is not known.
998
uint cached_field_index;
1000
Cached pointer to table which contains this field, used for the same reason
1001
by prep. stmt. too in case then we have not-fully qualified field.
1002
0 - means no cached value.
1004
TABLE_LIST *cached_table;
1005
st_select_lex *depended_from;
1006
Item_ident(Name_resolution_context *context_arg,
1007
const char *db_name_arg, const char *table_name_arg,
1008
const char *field_name_arg);
1009
Item_ident(THD *thd, Item_ident *item);
1010
const char *full_name() const;
1012
bool remove_dependence_processor(uchar * arg);
1013
virtual void print(String *str, enum_query_type query_type);
1014
virtual bool change_context_processor(uchar *cntx)
1015
{ context= (Name_resolution_context *)cntx; return FALSE; }
1016
friend bool insert_fields(THD *thd, Name_resolution_context *context,
1017
const char *db_name,
1018
const char *table_name, List_iterator<Item> *it,
1019
bool any_privileges);
1023
class Item_ident_for_show :public Item
1027
const char *db_name;
1028
const char *table_name;
1030
Item_ident_for_show(Field *par_field, const char *db_arg,
1031
const char *table_name_arg)
1032
:field(par_field), db_name(db_arg), table_name(table_name_arg)
1035
enum Type type() const { return FIELD_ITEM; }
1036
double val_real() { return field->val_real(); }
1037
longlong val_int() { return field->val_int(); }
1038
String *val_str(String *str) { return field->val_str(str); }
1039
my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); }
1040
void make_field(Send_field *tmp_field);
1047
class Item_field :public Item_ident
1050
void set_field(Field *field);
1052
Field *field,*result_field;
1053
Item_equal *item_equal;
1054
bool no_const_subst;
1056
if any_privileges set to TRUE then here real effective privileges will
1059
uint have_privileges;
1060
/* field need any privileges (for VIEW creation) */
1061
bool any_privileges;
1062
Item_field(Name_resolution_context *context_arg,
1063
const char *db_arg,const char *table_name_arg,
1064
const char *field_name_arg);
1066
Constructor needed to process subselect with temporary tables (see Item)
1068
Item_field(THD *thd, Item_field *item);
1070
Constructor used inside setup_wild(), ensures that field, table,
1071
and database names will live as long as Item_field (this is important
1072
in prepared statements).
1074
Item_field(THD *thd, Name_resolution_context *context_arg, Field *field);
1076
If this constructor is used, fix_fields() won't work, because
1077
db_name, table_name and column_name are unknown. It's necessary to call
1078
reset_field() before fix_fields() for all fields created this way.
1080
Item_field(Field *field);
1081
enum Type type() const { return FIELD_ITEM; }
1082
bool eq(const Item *item, bool binary_cmp) const;
1085
my_decimal *val_decimal(my_decimal *);
1086
String *val_str(String*);
1087
double val_result();
1088
longlong val_int_result();
1089
String *str_result(String* tmp);
1090
my_decimal *val_decimal_result(my_decimal *);
1091
bool val_bool_result();
1092
bool send(Protocol *protocol, String *str_arg);
1093
void reset_field(Field *f);
1094
bool fix_fields(THD *, Item **);
1095
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
1096
void make_field(Send_field *tmp_field);
1097
int save_in_field(Field *field,bool no_conversions);
1098
void save_org_in_field(Field *field);
1099
table_map used_tables() const;
1100
enum Item_result result_type () const
1102
return field->result_type();
1104
Item_result cast_to_int_type() const
1106
return field->cast_to_int_type();
1108
enum_field_types field_type() const
1110
return field->type();
1112
enum_monotonicity_info get_monotonicity_info() const
1114
return MONOTONIC_STRICT_INCREASING;
1116
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
1117
Field *get_tmp_table_field() { return result_field; }
1118
Field *tmp_table_field(TABLE *t_arg) { return result_field; }
1119
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1120
bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate);
1121
bool get_time(MYSQL_TIME *ltime);
1122
bool is_null() { return field->is_null(); }
1123
void update_null_value();
1124
Item *get_tmp_table_item(THD *thd);
1125
bool collect_item_field_processor(uchar * arg);
1126
bool find_item_in_field_list_processor(uchar *arg);
1127
bool register_field_in_read_map(uchar *arg);
1129
bool result_as_longlong()
1131
return field->can_be_compared_as_longlong();
1133
Item_equal *find_item_equal(COND_EQUAL *cond_equal);
1134
bool subst_argument_checker(uchar **arg);
1135
Item *equal_fields_propagator(uchar *arg);
1136
bool set_no_const_sub(uchar *arg);
1137
Item *replace_equal_field(uchar *arg);
1138
inline uint32 max_disp_length() { return field->max_display_length(); }
1139
Item_field *filed_for_view_update() { return this; }
1140
Item *safe_charset_converter(CHARSET_INFO *tocs);
1141
int fix_outer_field(THD *thd, Field **field, Item **reference);
1142
virtual Item *update_value_transformer(uchar *select_arg);
1143
virtual void print(String *str, enum_query_type query_type);
1148
fprintf(DBUG_FILE, "<field ");
1151
fprintf(DBUG_FILE, "'%s.%s': ", field->table->alias, field->field_name);
1152
field->dbug_print();
1155
fprintf(DBUG_FILE, "NULL");
1157
fprintf(DBUG_FILE, ", result_field: ");
1160
fprintf(DBUG_FILE, "'%s.%s': ",
1161
result_field->table->alias, result_field->field_name);
1162
result_field->dbug_print();
1165
fprintf(DBUG_FILE, "NULL");
1166
fprintf(DBUG_FILE, ">\n");
1170
friend class Item_default_value;
1171
friend class Item_insert_value;
1172
friend class st_select_lex_unit;
1175
class Item_null :public Item_basic_constant
1178
Item_null(char *name_par=0)
1180
maybe_null= null_value= TRUE;
1182
name= name_par ? name_par : (char*) "NULL";
1184
collation.set(&my_charset_bin, DERIVATION_IGNORABLE);
1186
enum Type type() const { return NULL_ITEM; }
1187
bool eq(const Item *item, bool binary_cmp) const;
1190
String *val_str(String *str);
1191
my_decimal *val_decimal(my_decimal *);
1192
int save_in_field(Field *field, bool no_conversions);
1193
int save_safe_in_field(Field *field);
1194
bool send(Protocol *protocol, String *str);
1195
enum Item_result result_type () const { return STRING_RESULT; }
1196
enum_field_types field_type() const { return MYSQL_TYPE_NULL; }
1197
bool basic_const_item() const { return 1; }
1198
Item *clone_item() { return new Item_null(name); }
1199
bool is_null() { return 1; }
1201
virtual inline void print(String *str, enum_query_type query_type)
1203
str->append(STRING_WITH_LEN("NULL"));
1206
Item *safe_charset_converter(CHARSET_INFO *tocs);
1209
class Item_null_result :public Item_null
1212
Field *result_field;
1213
Item_null_result() : Item_null(), result_field(0) {}
1214
bool is_result_field() { return result_field != 0; }
1215
void save_in_result_field(bool no_conversions)
1217
save_in_field(result_field, no_conversions);
1221
/* Item represents one placeholder ('?') of prepared statement */
1223
class Item_param :public Item
1225
char cnvbuf[MAX_FIELD_WIDTH];
1230
enum enum_item_param_state
1232
NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE,
1233
STRING_VALUE, TIME_VALUE, LONG_DATA_VALUE,
1238
A buffer for string and long data values. Historically all allocated
1239
values returned from val_str() were treated as eligible to
1240
modification. I. e. in some cases Item_func_concat can append it's
1241
second argument to return value of the first one. Because of that we
1242
can't return the original buffer holding string data from val_str(),
1243
and have to have one buffer for data and another just pointing to
1244
the data. This is the latter one and it's returned from val_str().
1245
Can not be declared inside the union as it's not a POD type.
1247
String str_value_ptr;
1248
my_decimal decimal_value;
1254
Character sets conversion info for string values.
1255
Character sets of client and connection defined at bind time are used
1256
for all conversions, even if one of them is later changed (i.e.
1257
between subsequent calls to mysql_stmt_execute).
1259
struct CONVERSION_INFO
1261
CHARSET_INFO *character_set_client;
1262
CHARSET_INFO *character_set_of_placeholder;
1264
This points at character set of connection if conversion
1265
to it is required (i. e. if placeholder typecode is not BLOB).
1266
Otherwise it's equal to character_set_client (to simplify
1267
check in convert_str_value()).
1269
CHARSET_INFO *final_character_set_of_str_value;
1274
/* Cached values for virtual methods to save us one switch. */
1275
enum Item_result item_result_type;
1276
enum Type item_type;
1279
Used when this item is used in a temporary table.
1280
This is NOT placeholder metadata sent to client, as this value
1281
is assigned after sending metadata (in setup_one_conversion_function).
1282
For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both
1283
in result set and placeholders metadata, no matter what type you will
1284
supply for this placeholder in mysql_stmt_execute.
1286
enum enum_field_types param_type;
1288
Offset of placeholder inside statement text. Used to create
1289
no-placeholders version of this statement for the binary log.
1293
Item_param(uint pos_in_query_arg);
1295
enum Item_result result_type () const { return item_result_type; }
1296
enum Type type() const { return item_type; }
1297
enum_field_types field_type() const { return param_type; }
1301
my_decimal *val_decimal(my_decimal*);
1302
String *val_str(String*);
1303
bool get_time(MYSQL_TIME *tm);
1304
bool get_date(MYSQL_TIME *tm, uint fuzzydate);
1305
int save_in_field(Field *field, bool no_conversions);
1308
void set_int(longlong i, uint32 max_length_arg);
1309
void set_double(double i);
1310
void set_decimal(const char *str, ulong length);
1311
bool set_str(const char *str, ulong length);
1312
bool set_longdata(const char *str, ulong length);
1313
void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg);
1314
bool set_from_user_var(THD *thd, const user_var_entry *entry);
1317
Assign placeholder value from bind data.
1318
Note, that 'len' has different semantics in embedded library (as we
1319
don't need to check that packet is not broken there). See
1320
sql_prepare.cc for details.
1322
void (*set_param_func)(Item_param *param, uchar **pos, ulong len);
1324
const String *query_val_str(String *str) const;
1326
bool convert_str_value(THD *thd);
1329
If value for parameter was not set we treat it as non-const
1330
so noone will use parameters value in fix_fields still
1331
parameter is constant during execution.
1333
virtual table_map used_tables() const
1334
{ return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; }
1335
virtual void print(String *str, enum_query_type query_type);
1337
{ DBUG_ASSERT(state != NO_VALUE); return state == NULL_VALUE; }
1338
bool basic_const_item() const;
1340
This method is used to make a copy of a basic constant item when
1341
propagating constants in the optimizer. The reason to create a new
1342
item and not use the existing one is not precisely known (2005/04/16).
1343
Probably we are trying to preserve tree structure of items, in other
1344
words, avoid pointing at one item from two different nodes of the tree.
1345
Return a new basic constant item if parameter value is a basic
1346
constant, assert otherwise. This method is called only if
1347
basic_const_item returned TRUE.
1349
Item *safe_charset_converter(CHARSET_INFO *tocs);
1352
Implement by-value equality evaluation if parameter value
1353
is set and is a basic constant (integer, real or string).
1354
Otherwise return FALSE.
1356
bool eq(const Item *item, bool binary_cmp) const;
1357
/** Item is a argument to a limit clause. */
1358
bool limit_clause_param;
1362
class Item_int :public Item_num
1366
Item_int(int32 i,uint length= MY_INT32_NUM_DECIMAL_DIGITS)
1367
:value((longlong) i)
1368
{ max_length=length; fixed= 1; }
1369
Item_int(longlong i,uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1371
{ max_length=length; fixed= 1; }
1372
Item_int(ulonglong i, uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1374
{ max_length=length; fixed= 1; unsigned_flag= 1; }
1375
Item_int(const char *str_arg,longlong i,uint length) :value(i)
1376
{ max_length=length; name=(char*) str_arg; fixed= 1; }
1377
Item_int(const char *str_arg, uint length=64);
1378
enum Type type() const { return INT_ITEM; }
1379
enum Item_result result_type () const { return INT_RESULT; }
1380
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
1381
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
1382
double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
1383
my_decimal *val_decimal(my_decimal *);
1384
String *val_str(String*);
1385
int save_in_field(Field *field, bool no_conversions);
1386
bool basic_const_item() const { return 1; }
1387
Item *clone_item() { return new Item_int(name,value,max_length); }
1388
virtual void print(String *str, enum_query_type query_type);
1389
Item_num *neg() { value= -value; return this; }
1390
uint decimal_precision() const
1391
{ return (uint)(max_length - test(value < 0)); }
1392
bool eq(const Item *, bool binary_cmp) const;
1396
class Item_uint :public Item_int
1399
Item_uint(const char *str_arg, uint length);
1400
Item_uint(ulonglong i) :Item_int((ulonglong) i, 10) {}
1401
Item_uint(const char *str_arg, longlong i, uint length);
1403
{ DBUG_ASSERT(fixed == 1); return ulonglong2double((ulonglong)value); }
1404
String *val_str(String*);
1405
Item *clone_item() { return new Item_uint(name, value, max_length); }
1406
int save_in_field(Field *field, bool no_conversions);
1407
virtual void print(String *str, enum_query_type query_type);
1409
uint decimal_precision() const { return max_length; }
1413
/* decimal (fixed point) constant */
1414
class Item_decimal :public Item_num
1417
my_decimal decimal_value;
1419
Item_decimal(const char *str_arg, uint length, CHARSET_INFO *charset);
1420
Item_decimal(const char *str, const my_decimal *val_arg,
1421
uint decimal_par, uint length);
1422
Item_decimal(my_decimal *value_par);
1423
Item_decimal(longlong val, bool unsig);
1424
Item_decimal(double val, int precision, int scale);
1425
Item_decimal(const uchar *bin, int precision, int scale);
1427
enum Type type() const { return DECIMAL_ITEM; }
1428
enum Item_result result_type () const { return DECIMAL_RESULT; }
1429
enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
1432
String *val_str(String*);
1433
my_decimal *val_decimal(my_decimal *val) { return &decimal_value; }
1434
int save_in_field(Field *field, bool no_conversions);
1435
bool basic_const_item() const { return 1; }
1438
return new Item_decimal(name, &decimal_value, decimals, max_length);
1440
virtual void print(String *str, enum_query_type query_type);
1443
my_decimal_neg(&decimal_value);
1444
unsigned_flag= !decimal_value.sign();
1447
uint decimal_precision() const { return decimal_value.precision(); }
1448
bool eq(const Item *, bool binary_cmp) const;
1449
void set_decimal_value(my_decimal *value_par);
1453
class Item_float :public Item_num
1458
// Item_real() :value(0) {}
1459
Item_float(const char *str_arg, uint length);
1460
Item_float(const char *str,double val_arg,uint decimal_par,uint length)
1463
presentation= name=(char*) str;
1464
decimals=(uint8) decimal_par;
1468
Item_float(double value_par, uint decimal_par) :presentation(0), value(value_par)
1470
decimals= (uint8) decimal_par;
1473
int save_in_field(Field *field, bool no_conversions);
1474
enum Type type() const { return REAL_ITEM; }
1475
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
1476
double val_real() { DBUG_ASSERT(fixed == 1); return value; }
1479
DBUG_ASSERT(fixed == 1);
1480
if (value <= (double) LONGLONG_MIN)
1482
return LONGLONG_MIN;
1484
else if (value >= (double) (ulonglong) LONGLONG_MAX)
1486
return LONGLONG_MAX;
1488
return (longlong) rint(value);
1490
String *val_str(String*);
1491
my_decimal *val_decimal(my_decimal *);
1492
bool basic_const_item() const { return 1; }
1494
{ return new Item_float(name, value, decimals, max_length); }
1495
Item_num *neg() { value= -value; return this; }
1496
virtual void print(String *str, enum_query_type query_type);
1497
bool eq(const Item *, bool binary_cmp) const;
1501
class Item_static_float_func :public Item_float
1503
const char *func_name;
1505
Item_static_float_func(const char *str, double val_arg, uint decimal_par,
1507
:Item_float(NullS, val_arg, decimal_par, length), func_name(str)
1510
virtual inline void print(String *str, enum_query_type query_type)
1512
str->append(func_name);
1515
Item *safe_charset_converter(CHARSET_INFO *tocs);
1519
class Item_string :public Item_basic_constant
1522
Item_string(const char *str,uint length,
1523
CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
1524
uint repertoire= MY_REPERTOIRE_UNICODE30)
1525
: m_cs_specified(FALSE)
1527
str_value.set_or_copy_aligned(str, length, cs);
1528
collation.set(cs, dv, repertoire);
1530
We have to have a different max_length than 'length' here to
1531
ensure that we get the right length if we do use the item
1532
to create a new table. In this case max_length must be the maximum
1533
number of chars for a string of this type because we in Create_field::
1534
divide the max_length with mbmaxlen).
1536
max_length= str_value.numchars()*cs->mbmaxlen;
1537
set_name(str, length, cs);
1538
decimals=NOT_FIXED_DEC;
1539
// it is constant => can be used without fix_fields (and frequently used)
1542
/* Just create an item and do not fill string representation */
1543
Item_string(CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE)
1544
: m_cs_specified(FALSE)
1546
collation.set(cs, dv);
1548
set_name(NULL, 0, cs);
1549
decimals= NOT_FIXED_DEC;
1552
Item_string(const char *name_par, const char *str, uint length,
1553
CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
1554
uint repertoire= MY_REPERTOIRE_UNICODE30)
1555
: m_cs_specified(FALSE)
1557
str_value.set_or_copy_aligned(str, length, cs);
1558
collation.set(cs, dv, repertoire);
1559
max_length= str_value.numchars()*cs->mbmaxlen;
1560
set_name(name_par, 0, cs);
1561
decimals=NOT_FIXED_DEC;
1562
// it is constant => can be used without fix_fields (and frequently used)
1566
This is used in stored procedures to avoid memory leaks and
1567
does a deep copy of its argument.
1569
void set_str_with_copy(const char *str_arg, uint length_arg)
1571
str_value.copy(str_arg, length_arg, collation.collation);
1572
max_length= str_value.numchars() * collation.collation->mbmaxlen;
1574
void set_repertoire_from_value()
1576
collation.repertoire= my_string_repertoire(str_value.charset(),
1578
str_value.length());
1580
enum Type type() const { return STRING_ITEM; }
1583
String *val_str(String*)
1585
DBUG_ASSERT(fixed == 1);
1586
return (String*) &str_value;
1588
my_decimal *val_decimal(my_decimal *);
1589
int save_in_field(Field *field, bool no_conversions);
1590
enum Item_result result_type () const { return STRING_RESULT; }
1591
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1592
bool basic_const_item() const { return 1; }
1593
bool eq(const Item *item, bool binary_cmp) const;
1596
return new Item_string(name, str_value.ptr(),
1597
str_value.length(), collation.collation);
1599
Item *safe_charset_converter(CHARSET_INFO *tocs);
1600
inline void append(char *str, uint length)
1602
str_value.append(str, length);
1603
max_length= str_value.numchars() * collation.collation->mbmaxlen;
1605
virtual void print(String *str, enum_query_type query_type);
1608
Return TRUE if character-set-introducer was explicitly specified in the
1609
original query for this item (text literal).
1611
This operation is to be called from Item_string::print(). The idea is
1612
that when a query is generated (re-constructed) from the Item-tree,
1613
character-set-introducers should appear only for those literals, where
1614
they were explicitly specified by the user. Otherwise, that may lead to
1615
loss collation information (character set introducers implies default
1616
collation for the literal).
1618
Basically, that makes sense only for views and hopefully will be gone
1619
one day when we start using original query as a view definition.
1621
@return This operation returns the value of m_cs_specified attribute.
1622
@retval TRUE if character set introducer was explicitly specified in
1624
@retval FALSE otherwise.
1626
inline bool is_cs_specified() const
1628
return m_cs_specified;
1632
Set the value of m_cs_specified attribute.
1634
m_cs_specified attribute shows whether character-set-introducer was
1635
explicitly specified in the original query for this text literal or
1636
not. The attribute makes sense (is used) only for views.
1638
This operation is to be called from the parser during parsing an input
1641
inline void set_cs_specified(bool cs_specified)
1643
m_cs_specified= cs_specified;
1647
bool m_cs_specified;
1651
class Item_static_string_func :public Item_string
1653
const char *func_name;
1655
Item_static_string_func(const char *name_par, const char *str, uint length,
1657
Derivation dv= DERIVATION_COERCIBLE)
1658
:Item_string(NullS, str, length, cs, dv), func_name(name_par)
1660
Item *safe_charset_converter(CHARSET_INFO *tocs);
1662
virtual inline void print(String *str, enum_query_type query_type)
1664
str->append(func_name);
1669
/* for show tables */
1670
class Item_return_date_time :public Item_string
1672
enum_field_types date_time_field_type;
1674
Item_return_date_time(const char *name_arg, enum_field_types field_type_arg)
1675
:Item_string(name_arg, 0, &my_charset_bin),
1676
date_time_field_type(field_type_arg)
1678
enum_field_types field_type() const { return date_time_field_type; }
1682
class Item_blob :public Item_string
1685
Item_blob(const char *name, uint length) :
1686
Item_string(name, length, &my_charset_bin)
1687
{ max_length= length; }
1688
enum Type type() const { return TYPE_HOLDER; }
1689
enum_field_types field_type() const { return MYSQL_TYPE_BLOB; }
1694
Item_empty_string -- is a utility class to put an item into List<Item>
1695
which is then used in protocol.send_fields() when sending SHOW output to
1699
class Item_empty_string :public Item_string
1702
Item_empty_string(const char *header,uint length, CHARSET_INFO *cs= NULL) :
1703
Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
1704
{ name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
1705
void make_field(Send_field *field);
1709
class Item_return_int :public Item_int
1711
enum_field_types int_field_type;
1713
Item_return_int(const char *name_arg, uint length,
1714
enum_field_types field_type_arg, longlong value= 0)
1715
:Item_int(name_arg, value, length), int_field_type(field_type_arg)
1719
enum_field_types field_type() const { return int_field_type; }
1723
class Item_hex_string: public Item_basic_constant
1726
Item_hex_string() {}
1727
Item_hex_string(const char *str,uint str_length);
1728
enum Type type() const { return VARBIN_ITEM; }
1731
DBUG_ASSERT(fixed == 1);
1732
return (double) (ulonglong) Item_hex_string::val_int();
1735
bool basic_const_item() const { return 1; }
1736
String *val_str(String*) { DBUG_ASSERT(fixed == 1); return &str_value; }
1737
my_decimal *val_decimal(my_decimal *);
1738
int save_in_field(Field *field, bool no_conversions);
1739
enum Item_result result_type () const { return STRING_RESULT; }
1740
enum Item_result cast_to_int_type() const { return INT_RESULT; }
1741
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
1742
virtual void print(String *str, enum_query_type query_type);
1743
bool eq(const Item *item, bool binary_cmp) const;
1744
virtual Item *safe_charset_converter(CHARSET_INFO *tocs);
1748
class Item_bin_string: public Item_hex_string
1751
Item_bin_string(const char *str,uint str_length);
1754
class Item_result_field :public Item /* Item with result field */
1757
Field *result_field; /* Save result here */
1758
Item_result_field() :result_field(0) {}
1759
// Constructor used for Item_sum/Item_cond_and/or (see Item comment)
1760
Item_result_field(THD *thd, Item_result_field *item):
1761
Item(thd, item), result_field(item->result_field)
1763
~Item_result_field() {} /* Required with gcc 2.95 */
1764
Field *get_tmp_table_field() { return result_field; }
1765
Field *tmp_table_field(TABLE *t_arg) { return result_field; }
1766
table_map used_tables() const { return 1; }
1767
virtual void fix_length_and_dec()=0;
1768
void set_result_field(Field *field) { result_field= field; }
1769
bool is_result_field() { return 1; }
1770
void save_in_result_field(bool no_conversions)
1772
save_in_field(result_field, no_conversions);
1778
class Item_ref :public Item_ident
1781
void set_properties();
1783
enum Ref_Type { REF, DIRECT_REF, VIEW_REF, OUTER_REF };
1784
Field *result_field; /* Save result here */
1786
Item_ref(Name_resolution_context *context_arg,
1787
const char *db_arg, const char *table_name_arg,
1788
const char *field_name_arg)
1789
:Item_ident(context_arg, db_arg, table_name_arg, field_name_arg),
1790
result_field(0), ref(0) {}
1792
This constructor is used in two scenarios:
1794
No initialization is performed, fix_fields() call will be necessary.
1796
B) *item points to an Item this Item_ref will refer to. This is
1797
used for GROUP BY. fix_fields() will not be called in this case,
1798
so we call set_properties to make this item "fixed". set_properties
1799
performs a subset of action Item_ref::fix_fields does, and this subset
1800
is enough for Item_ref's used in GROUP BY.
1802
TODO we probably fix a superset of problems like in BUG#6658. Check this
1803
with Bar, and if we have a more broader set of problems like this.
1805
Item_ref(Name_resolution_context *context_arg, Item **item,
1806
const char *table_name_arg, const char *field_name_arg,
1807
bool alias_name_used_arg= FALSE);
1809
/* Constructor need to process subselect with temporary tables (see Item) */
1810
Item_ref(THD *thd, Item_ref *item)
1811
:Item_ident(thd, item), result_field(item->result_field), ref(item->ref) {}
1812
enum Type type() const { return REF_ITEM; }
1813
bool eq(const Item *item, bool binary_cmp) const
1815
Item *it= ((Item *) item)->real_item();
1816
return ref && (*ref)->eq(it, binary_cmp);
1820
my_decimal *val_decimal(my_decimal *);
1822
String *val_str(String* tmp);
1824
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1825
double val_result();
1826
longlong val_int_result();
1827
String *str_result(String* tmp);
1828
my_decimal *val_decimal_result(my_decimal *);
1829
bool val_bool_result();
1830
bool send(Protocol *prot, String *tmp);
1831
void make_field(Send_field *field);
1832
bool fix_fields(THD *, Item **);
1833
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
1834
int save_in_field(Field *field, bool no_conversions);
1835
void save_org_in_field(Field *field);
1836
enum Item_result result_type () const { return (*ref)->result_type(); }
1837
enum_field_types field_type() const { return (*ref)->field_type(); }
1838
Field *get_tmp_table_field()
1839
{ return result_field ? result_field : (*ref)->get_tmp_table_field(); }
1840
Item *get_tmp_table_item(THD *thd);
1841
table_map used_tables() const
1843
return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
1845
void update_used_tables()
1848
(*ref)->update_used_tables();
1850
table_map not_null_tables() const { return (*ref)->not_null_tables(); }
1851
void set_result_field(Field *field) { result_field= field; }
1852
bool is_result_field() { return 1; }
1853
void save_in_result_field(bool no_conversions)
1855
(*ref)->save_in_field(result_field, no_conversions);
1859
return ref ? (*ref)->real_item() : this;
1861
bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
1862
{ return (*ref)->walk(processor, walk_subquery, arg); }
1863
virtual void print(String *str, enum_query_type query_type);
1864
bool result_as_longlong()
1866
return (*ref)->result_as_longlong();
1869
Item_field *filed_for_view_update()
1870
{ return (*ref)->filed_for_view_update(); }
1871
virtual Ref_Type ref_type() { return REF; }
1873
// Row emulation: forwarding of ROW-related calls to ref
1876
return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
1878
Item* element_index(uint i)
1880
return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
1884
return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
1886
bool check_cols(uint c)
1888
return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
1889
: Item::check_cols(c);
1893
return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
1897
if (ref && result_type() == ROW_RESULT)
1898
(*ref)->bring_value();
1905
The same as Item_ref, but get value from val_* family of method to get
1906
value of item on which it referred instead of result* family.
1908
class Item_direct_ref :public Item_ref
1911
Item_direct_ref(Name_resolution_context *context_arg, Item **item,
1912
const char *table_name_arg,
1913
const char *field_name_arg,
1914
bool alias_name_used_arg= FALSE)
1915
:Item_ref(context_arg, item, table_name_arg,
1916
field_name_arg, alias_name_used_arg)
1918
/* Constructor need to process subselect with temporary tables (see Item) */
1919
Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
1923
String *val_str(String* tmp);
1924
my_decimal *val_decimal(my_decimal *);
1927
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
1928
virtual Ref_Type ref_type() { return DIRECT_REF; }
1932
Class for view fields, the same as Item_direct_ref, but call fix_fields
1933
of reference if it is not called yet
1935
class Item_direct_view_ref :public Item_direct_ref
1938
Item_direct_view_ref(Name_resolution_context *context_arg, Item **item,
1939
const char *table_name_arg,
1940
const char *field_name_arg)
1941
:Item_direct_ref(context_arg, item, table_name_arg, field_name_arg) {}
1942
/* Constructor need to process subselect with temporary tables (see Item) */
1943
Item_direct_view_ref(THD *thd, Item_direct_ref *item)
1944
:Item_direct_ref(thd, item) {}
1946
bool fix_fields(THD *, Item **);
1947
bool eq(const Item *item, bool binary_cmp) const;
1948
Item *get_tmp_table_item(THD *thd)
1950
Item *item= Item_ref::get_tmp_table_item(thd);
1954
virtual Ref_Type ref_type() { return VIEW_REF; }
1959
Class for outer fields.
1960
An object of this class is created when the select where the outer field was
1961
resolved is a grouping one. After it has been fixed the ref field will point
1962
to either an Item_ref or an Item_direct_ref object which will be used to
1964
See also comments for the fix_inner_refs() and the
1965
Item_field::fix_outer_field() functions.
1969
class Item_outer_ref :public Item_direct_ref
1973
/* The aggregate function under which this outer ref is used, if any. */
1974
Item_sum *in_sum_func;
1976
TRUE <=> that the outer_ref is already present in the select list
1977
of the outer select.
1979
bool found_in_select_list;
1980
Item_outer_ref(Name_resolution_context *context_arg,
1981
Item_field *outer_field_arg)
1982
:Item_direct_ref(context_arg, 0, outer_field_arg->table_name,
1983
outer_field_arg->field_name),
1984
outer_ref(outer_field_arg), in_sum_func(0),
1985
found_in_select_list(0)
1991
Item_outer_ref(Name_resolution_context *context_arg, Item **item,
1992
const char *table_name_arg, const char *field_name_arg,
1993
bool alias_name_used_arg)
1994
:Item_direct_ref(context_arg, item, table_name_arg, field_name_arg,
1995
alias_name_used_arg),
1996
outer_ref(0), in_sum_func(0), found_in_select_list(1)
1998
void save_in_result_field(bool no_conversions)
2000
outer_ref->save_org_in_field(result_field);
2002
bool fix_fields(THD *, Item **);
2003
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
2004
table_map used_tables() const
2006
return (*ref)->const_item() ? 0 : OUTER_REF_TABLE_BIT;
2008
virtual Ref_Type ref_type() { return OUTER_REF; }
2012
class Item_in_subselect;
2016
An object of this class:
2017
- Converts val_XXX() calls to ref->val_XXX_result() calls, like Item_ref.
2018
- Sets owner->was_null=TRUE if it has returned a NULL value from any
2019
val_XXX() function. This allows to inject an Item_ref_null_helper
2020
object into subquery and then check if the subquery has produced a row
2024
class Item_ref_null_helper: public Item_ref
2027
Item_in_subselect* owner;
2029
Item_ref_null_helper(Name_resolution_context *context_arg,
2030
Item_in_subselect* master, Item **item,
2031
const char *table_name_arg, const char *field_name_arg)
2032
:Item_ref(context_arg, item, table_name_arg, field_name_arg),
2036
String* val_str(String* s);
2037
my_decimal *val_decimal(my_decimal *);
2039
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
2040
virtual void print(String *str, enum_query_type query_type);
2042
we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
2044
table_map used_tables() const
2046
return (depended_from ?
2047
OUTER_REF_TABLE_BIT :
2048
(*ref)->used_tables() | RAND_TABLE_BIT);
2053
The following class is used to optimize comparing of date and bigint columns
2054
We need to save the original item ('ref') to be able to call
2055
ref->save_in_field(). This is used to create index search keys.
2057
An instance of Item_int_with_ref may have signed or unsigned integer value.
2061
class Item_int_with_ref :public Item_int
2065
Item_int_with_ref(longlong i, Item *ref_arg, my_bool unsigned_arg) :
2066
Item_int(i), ref(ref_arg)
2068
unsigned_flag= unsigned_arg;
2070
int save_in_field(Field *field, bool no_conversions)
2072
return ref->save_in_field(field, no_conversions);
2075
virtual Item *real_item() { return ref; }
2079
#include "item_sum.h"
2080
#include "item_func.h"
2081
#include "item_row.h"
2082
#include "item_cmpfunc.h"
2083
#include "item_strfunc.h"
2084
#include "item_timefunc.h"
2085
#include "item_subselect.h"
2088
class Item_copy_string :public Item
2090
enum enum_field_types cached_field_type;
2093
Item_copy_string(Item *i) :item(i)
2095
null_value=maybe_null=item->maybe_null;
2096
decimals=item->decimals;
2097
max_length=item->max_length;
2099
cached_field_type= item->field_type();
2101
enum Type type() const { return COPY_STR_ITEM; }
2102
enum Item_result result_type () const { return STRING_RESULT; }
2103
enum_field_types field_type() const { return cached_field_type; }
2108
return (null_value ? 0.0 :
2109
my_strntod(str_value.charset(), (char*) str_value.ptr(),
2110
str_value.length(), &end_not_used, &err_not_used));
2115
return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(),
2116
str_value.length(),10, (char**) 0,
2119
String *val_str(String*);
2120
my_decimal *val_decimal(my_decimal *);
2121
void make_field(Send_field *field) { item->make_field(field); }
2123
int save_in_field(Field *field, bool no_conversions)
2125
return save_str_value_in_field(field, &str_value);
2127
table_map used_tables() const { return (table_map) 1L; }
2128
bool const_item() const { return 0; }
2129
bool is_null() { return null_value; }
2133
class Cached_item :public Sql_alloc
2137
Cached_item() :null_value(0) {}
2138
virtual bool cmp(void)=0;
2139
virtual ~Cached_item(); /*line -e1509 */
2142
class Cached_item_str :public Cached_item
2145
String value,tmp_value;
2147
Cached_item_str(THD *thd, Item *arg);
2149
~Cached_item_str(); // Deallocate String:s
2153
class Cached_item_real :public Cached_item
2158
Cached_item_real(Item *item_par) :item(item_par),value(0.0) {}
2162
class Cached_item_int :public Cached_item
2167
Cached_item_int(Item *item_par) :item(item_par),value(0) {}
2172
class Cached_item_decimal :public Cached_item
2177
Cached_item_decimal(Item *item_par);
2181
class Cached_item_field :public Cached_item
2192
org_ptr= field->ptr;
2193
fprintf(DBUG_FILE, "new: ");
2194
field->dbug_print();
2196
fprintf(DBUG_FILE, ", old: ");
2197
field->dbug_print();
2198
field->ptr= org_ptr;
2199
fprintf(DBUG_FILE, "\n");
2202
Cached_item_field(Field *arg_field) : field(arg_field)
2205
/* TODO: take the memory allocation below out of the constructor. */
2206
buff= (uchar*) sql_calloc(length=field->pack_length());
2211
class Item_default_value : public Item_field
2215
Item_default_value(Name_resolution_context *context_arg)
2216
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
2217
(const char *)NULL),
2219
Item_default_value(Name_resolution_context *context_arg, Item *a)
2220
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
2221
(const char *)NULL),
2223
enum Type type() const { return DEFAULT_VALUE_ITEM; }
2224
bool eq(const Item *item, bool binary_cmp) const;
2225
bool fix_fields(THD *, Item **);
2226
virtual void print(String *str, enum_query_type query_type);
2227
int save_in_field(Field *field_arg, bool no_conversions);
2228
table_map used_tables() const { return (table_map)0L; }
2230
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2232
return arg->walk(processor, walk_subquery, args) ||
2233
(this->*processor)(args);
2236
Item *transform(Item_transformer transformer, uchar *args);
2240
Item_insert_value -- an implementation of VALUES() function.
2241
You can use the VALUES(col_name) function in the UPDATE clause
2242
to refer to column values from the INSERT portion of the INSERT
2243
... UPDATE statement. In other words, VALUES(col_name) in the
2244
UPDATE clause refers to the value of col_name that would be
2245
inserted, had no duplicate-key conflict occurred.
2246
In all other places this function returns NULL.
2249
class Item_insert_value : public Item_field
2253
Item_insert_value(Name_resolution_context *context_arg, Item *a)
2254
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
2255
(const char *)NULL),
2257
bool eq(const Item *item, bool binary_cmp) const;
2258
bool fix_fields(THD *, Item **);
2259
virtual void print(String *str, enum_query_type query_type);
2260
int save_in_field(Field *field_arg, bool no_conversions)
2262
return Item_field::save_in_field(field_arg, no_conversions);
2265
We use RAND_TABLE_BIT to prevent Item_insert_value from
2266
being treated as a constant and precalculated before execution
2268
table_map used_tables() const { return RAND_TABLE_BIT; }
2270
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2272
return arg->walk(processor, walk_subquery, args) ||
2273
(this->*processor)(args);
2278
class Item_cache: public Item_basic_constant
2282
table_map used_table_map;
2284
Field that this object will get value from. This is set/used by
2285
index-based subquery engines to detect and remove the equality injected
2286
by IN->EXISTS transformation.
2287
For all other uses of Item_cache, cached_field doesn't matter.
2289
Field *cached_field;
2290
enum enum_field_types cached_field_type;
2293
example(0), used_table_map(0), cached_field(0), cached_field_type(MYSQL_TYPE_STRING)
2298
Item_cache(enum_field_types field_type_arg):
2299
example(0), used_table_map(0), cached_field(0), cached_field_type(field_type_arg)
2305
void set_used_tables(table_map map) { used_table_map= map; }
2307
virtual bool allocate(uint i) { return 0; }
2308
virtual bool setup(Item *item)
2311
max_length= item->max_length;
2312
decimals= item->decimals;
2313
collation.set(item->collation);
2314
unsigned_flag= item->unsigned_flag;
2315
if (item->type() == FIELD_ITEM)
2316
cached_field= ((Item_field *)item)->field;
2319
virtual void store(Item *)= 0;
2320
enum Type type() const { return CACHE_ITEM; }
2321
enum_field_types field_type() const { return cached_field_type; }
2322
static Item_cache* get_cache(const Item *item);
2323
table_map used_tables() const { return used_table_map; }
2324
virtual void keep_array() {}
2325
virtual void print(String *str, enum_query_type query_type);
2326
bool eq_def(Field *field)
2328
return cached_field ? cached_field->eq_def (field) : FALSE;
2330
bool eq(const Item *item, bool binary_cmp) const
2332
return this == item;
2337
class Item_cache_int: public Item_cache
2342
Item_cache_int(): Item_cache(), value(0) {}
2343
Item_cache_int(enum_field_types field_type_arg):
2344
Item_cache(field_type_arg), value(0) {}
2346
void store(Item *item);
2347
void store(Item *item, longlong val_arg);
2348
double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
2349
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
2350
String* val_str(String *str);
2351
my_decimal *val_decimal(my_decimal *);
2352
enum Item_result result_type() const { return INT_RESULT; }
2353
bool result_as_longlong() { return TRUE; }
2357
class Item_cache_real: public Item_cache
2361
Item_cache_real(): Item_cache(), value(0) {}
2363
void store(Item *item);
2364
double val_real() { DBUG_ASSERT(fixed == 1); return value; }
2366
String* val_str(String *str);
2367
my_decimal *val_decimal(my_decimal *);
2368
enum Item_result result_type() const { return REAL_RESULT; }
2372
class Item_cache_decimal: public Item_cache
2375
my_decimal decimal_value;
2377
Item_cache_decimal(): Item_cache() {}
2379
void store(Item *item);
2382
String* val_str(String *str);
2383
my_decimal *val_decimal(my_decimal *);
2384
enum Item_result result_type() const { return DECIMAL_RESULT; }
2388
class Item_cache_str: public Item_cache
2390
char buffer[STRING_BUFFER_USUAL_SIZE];
2391
String *value, value_buff;
2395
Item_cache_str(const Item *item) :
2396
Item_cache(), value(0),
2397
is_varbinary(item->type() == FIELD_ITEM &&
2398
((const Item_field *) item)->field->type() ==
2399
MYSQL_TYPE_VARCHAR &&
2400
!((const Item_field *) item)->field->has_charset())
2402
void store(Item *item);
2405
String* val_str(String *) { DBUG_ASSERT(fixed == 1); return value; }
2406
my_decimal *val_decimal(my_decimal *);
2407
enum Item_result result_type() const { return STRING_RESULT; }
2408
CHARSET_INFO *charset() const { return value->charset(); };
2409
int save_in_field(Field *field, bool no_conversions);
2412
class Item_cache_row: public Item_cache
2414
Item_cache **values;
2419
:Item_cache(), values(0), item_count(2), save_array(0) {}
2422
'allocate' used only in row transformer, to preallocate space for row
2425
bool allocate(uint num);
2427
'setup' is needed only by row => it not called by simple row subselect
2428
(only by IN subselect (in subselect optimizer))
2430
bool setup(Item *item);
2431
void store(Item *item);
2432
void illegal_method_call(const char *);
2433
void make_field(Send_field *)
2435
illegal_method_call((const char*)"make_field");
2439
illegal_method_call((const char*)"val");
2444
illegal_method_call((const char*)"val_int");
2447
String *val_str(String *)
2449
illegal_method_call((const char*)"val_str");
2452
my_decimal *val_decimal(my_decimal *val)
2454
illegal_method_call((const char*)"val_decimal");
2458
enum Item_result result_type() const { return ROW_RESULT; }
2460
uint cols() { return item_count; }
2461
Item *element_index(uint i) { return values[i]; }
2462
Item **addr(uint i) { return (Item **) (values + i); }
2463
bool check_cols(uint c);
2466
void keep_array() { save_array= 1; }
2469
DBUG_ENTER("Item_cache_row::cleanup");
2470
Item_cache::cleanup();
2472
bzero(values, item_count*sizeof(Item**));
2481
Item_type_holder used to store type. name, length of Item for UNIONS &
2484
Item_type_holder do not need cleanup() because its time of live limited by
2485
single SP/PS execution.
2487
class Item_type_holder: public Item
2490
TYPELIB *enum_set_typelib;
2491
enum_field_types fld_type;
2493
void get_full_info(Item *item);
2495
/* It is used to count decimal precision in join_types */
2496
int prev_decimal_int_part;
2498
Item_type_holder(THD*, Item*);
2500
Item_result result_type() const;
2501
enum_field_types field_type() const { return fld_type; };
2502
enum Type type() const { return TYPE_HOLDER; }
2505
my_decimal *val_decimal(my_decimal *);
2506
String *val_str(String*);
2507
bool join_types(THD *thd, Item *);
2508
Field *make_field_by_type(TABLE *table);
2509
static uint32 display_length(Item *item);
2510
static enum_field_types get_real_type(Item *);
2514
class st_select_lex;
2515
void mark_select_range_as_dependent(THD *thd,
2516
st_select_lex *last_select,
2517
st_select_lex *current_sel,
2518
Field *found_field, Item *found_item,
2519
Item_ident *resolved_item);
2521
extern Cached_item *new_Cached_item(THD *thd, Item *item,
2522
bool use_result_field);
2523
extern Item_result item_cmp_type(Item_result a,Item_result b);
2524
extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
2525
extern bool field_is_equal_to_item(Field *field,Item *item);