4
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; version 2 of the License.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
20
#include "sql_priv.h" /* STRING_BUFFER_USUAL_SIZE */
22
#include "sql_const.h" /* RAND_TABLE_BIT, MAX_FIELD_NAME */
23
#include "unireg.h" // REQUIRED: for other includes
24
#include "thr_malloc.h" /* sql_calloc */
25
#include "field.h" /* Derivation */
26
#include "sql_array.h"
30
void item_init(void); /* Init item functions */
34
typedef Bounds_checked_array<Item*> Ref_ptr_array;
37
char_to_byte_length_safe(uint32 char_length_arg, uint32 mbmaxlen_arg)
39
ulonglong tmp= ((ulonglong) char_length_arg) * mbmaxlen_arg;
40
return (tmp > UINT_MAX32) ? (uint32) UINT_MAX32 : (uint32) tmp;
45
"Declared Type Collation"
46
A combination of collation and its derivation.
48
Flags for collation aggregation modes:
49
MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
50
MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
52
MY_COLL_ALLOW_CONV - allow any kind of conversion
53
(combination of the above two)
54
MY_COLL_ALLOW_NUMERIC_CONV - if all items were numbers, convert to
55
@@character_set_connection
56
MY_COLL_DISALLOW_NONE - don't allow return DERIVATION_NONE
57
(e.g. when aggregating for comparison)
58
MY_COLL_CMP_CONV - combination of MY_COLL_ALLOW_CONV
59
and MY_COLL_DISALLOW_NONE
62
#define MY_COLL_ALLOW_SUPERSET_CONV 1
63
#define MY_COLL_ALLOW_COERCIBLE_CONV 2
64
#define MY_COLL_DISALLOW_NONE 4
65
#define MY_COLL_ALLOW_NUMERIC_CONV 8
67
#define MY_COLL_ALLOW_CONV (MY_COLL_ALLOW_SUPERSET_CONV | MY_COLL_ALLOW_COERCIBLE_CONV)
68
#define MY_COLL_CMP_CONV (MY_COLL_ALLOW_CONV | MY_COLL_DISALLOW_NONE)
72
const CHARSET_INFO *collation;
73
enum Derivation derivation;
76
void set_repertoire_from_charset(const CHARSET_INFO *cs)
78
repertoire= cs->state & MY_CS_PUREASCII ?
79
MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
83
collation= &my_charset_bin;
84
derivation= DERIVATION_NONE;
85
repertoire= MY_REPERTOIRE_UNICODE30;
87
DTCollation(const CHARSET_INFO *collation_arg, Derivation derivation_arg)
89
collation= collation_arg;
90
derivation= derivation_arg;
91
set_repertoire_from_charset(collation_arg);
93
void set(DTCollation &dt)
95
collation= dt.collation;
96
derivation= dt.derivation;
97
repertoire= dt.repertoire;
99
void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg)
101
collation= collation_arg;
102
derivation= derivation_arg;
103
set_repertoire_from_charset(collation_arg);
105
void set(const CHARSET_INFO *collation_arg,
106
Derivation derivation_arg,
109
collation= collation_arg;
110
derivation= derivation_arg;
111
repertoire= repertoire_arg;
115
collation= &my_charset_numeric;
116
derivation= DERIVATION_NUMERIC;
117
repertoire= MY_REPERTOIRE_NUMERIC;
119
void set(const CHARSET_INFO *collation_arg)
121
collation= collation_arg;
122
set_repertoire_from_charset(collation_arg);
124
void set(Derivation derivation_arg)
125
{ derivation= derivation_arg; }
126
void set_repertoire(uint repertoire_arg)
127
{ repertoire= repertoire_arg; }
128
bool aggregate(DTCollation &dt, uint flags= 0);
129
bool set(DTCollation &dt1, DTCollation &dt2, uint flags= 0)
130
{ set(dt1); return aggregate(dt2, flags); }
131
const char *derivation_name() const
135
case DERIVATION_NUMERIC: return "NUMERIC";
136
case DERIVATION_IGNORABLE: return "IGNORABLE";
137
case DERIVATION_COERCIBLE: return "COERCIBLE";
138
case DERIVATION_IMPLICIT: return "IMPLICIT";
139
case DERIVATION_SYSCONST: return "SYSCONST";
140
case DERIVATION_EXPLICIT: return "EXPLICIT";
141
case DERIVATION_NONE: return "NONE";
142
default: return "UNKNOWN";
147
/*************************************************************************/
150
Storage for name strings.
151
Enpowers Simple_cstring with allocation routines from the sql_strmake family.
153
This class must stay as small as possible as we often
154
pass it into functions using call-by-value evaluation.
156
Don't add new members or virual methods into this class!
158
class Name_string: public Simple_cstring
161
void set_or_copy(const char *str, size_t length, bool is_null_terminated)
163
if (is_null_terminated)
169
Name_string(): Simple_cstring() {}
171
Please do NOT add constructor Name_string(const char *str) !
172
It will involve hidden strlen() call, which can affect
173
performance negatively. Use Name_string(str, len) instead.
175
Name_string(const char *str, size_t length):
176
Simple_cstring(str, length) {}
177
Name_string(const LEX_STRING str): Simple_cstring(str) {}
178
Name_string(const char *str, size_t length, bool is_null_terminated):
181
set_or_copy(str, length, is_null_terminated);
183
Name_string(const LEX_STRING str, bool is_null_terminated):
186
set_or_copy(str.str, str.length, is_null_terminated);
189
Allocate space using sql_strmake() or sql_strmake_with_convert().
191
void copy(const char *str, size_t length, const CHARSET_INFO *cs);
193
Variants for copy(), for various argument combinations.
195
void copy(const char *str, size_t length)
197
copy(str, length, system_charset_info);
199
void copy(const char *str)
201
copy(str, (str ? strlen(str) : 0), system_charset_info);
203
void copy(const LEX_STRING lex)
205
copy(lex.str, lex.length);
207
void copy(const LEX_STRING *lex)
209
copy(lex->str, lex->length);
211
void copy(const Name_string str)
213
copy(str.ptr(), str.length());
216
Compare name to another name in C string, case insensitively.
218
bool eq(const char *str) const
220
DBUG_ASSERT(str && ptr());
221
return my_strcasecmp(system_charset_info, ptr(), str) == 0;
223
bool eq_safe(const char *str) const
225
return is_set() && str && eq(str);
228
Compare name to another name in Name_string, case insensitively.
230
bool eq(const Name_string name) const
232
return eq(name.ptr());
234
bool eq_safe(const Name_string name) const
236
return is_set() && name.is_set() && eq(name);
241
#define NAME_STRING(x) Name_string(C_STRING_WITH_LEN(x))
244
extern const Name_string null_name_string;
248
Storage for Item names.
249
Adds "autogenerated" flag and warning functionality to Name_string.
251
class Item_name_string: public Name_string
254
bool m_is_autogenerated; /* indicates if name of this Item
255
was autogenerated or set by user */
257
Item_name_string(): Name_string(), m_is_autogenerated(true)
259
Item_name_string(const Name_string name)
260
:Name_string(name), m_is_autogenerated(true)
263
Set m_is_autogenerated flag to the given value.
265
void set_autogenerated(bool is_autogenerated)
267
m_is_autogenerated= is_autogenerated;
270
Return the auto-generated flag.
272
bool is_autogenerated() const { return m_is_autogenerated; }
273
using Name_string::copy;
275
Copy name together with autogenerated flag.
276
Produce a warning if name was cut.
278
void copy(const char *str_arg, size_t length_arg, const CHARSET_INFO *cs_arg,
279
bool is_autogenerated_arg);
284
/*************************************************************************/
286
A framework to easily handle different return types for hybrid items
287
(hybrid item is an item whose operand can be of any type, e.g. integer,
291
struct Hybrid_type_traits;
299
Use two decimal buffers interchangeably to speed up += operation
300
which has no native support in decimal library.
301
Hybrid_type+= arg is implemented as dec_buf[1]= dec_buf[0] + arg.
302
The third decimal is used as a handy temporary storage.
304
my_decimal dec_buf[3];
308
Traits moved to a separate class to
309
a) be able to easily change object traits in runtime
310
b) they work as a differentiator for the union above
312
const Hybrid_type_traits *traits;
315
/* XXX: add traits->copy() when needed */
316
Hybrid_type(const Hybrid_type &rhs) :traits(rhs.traits) {}
320
/* Hybryd_type_traits interface + default implementation for REAL_RESULT */
322
struct Hybrid_type_traits
324
virtual Item_result type() const { return REAL_RESULT; }
327
fix_length_and_dec(Item *item, Item *arg) const;
329
/* Hybrid_type operations. */
330
virtual void set_zero(Hybrid_type *val) const { val->real= 0.0; }
331
virtual void add(Hybrid_type *val, Field *f) const
332
{ val->real+= f->val_real(); }
333
virtual void div(Hybrid_type *val, ulonglong u) const
334
{ val->real/= ulonglong2double(u); }
336
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const
337
{ return (longlong) rint(val->real); }
338
virtual double val_real(Hybrid_type *val) const { return val->real; }
339
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const;
340
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
341
static const Hybrid_type_traits *instance();
342
Hybrid_type_traits() {}
343
virtual ~Hybrid_type_traits() {}
347
struct Hybrid_type_traits_decimal: public Hybrid_type_traits
349
virtual Item_result type() const { return DECIMAL_RESULT; }
352
fix_length_and_dec(Item *arg, Item *item) const;
354
/* Hybrid_type operations. */
355
virtual void set_zero(Hybrid_type *val) const;
356
virtual void add(Hybrid_type *val, Field *f) const;
357
virtual void div(Hybrid_type *val, ulonglong u) const;
359
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const;
360
virtual double val_real(Hybrid_type *val) const;
361
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const
362
{ return &val->dec_buf[val->used_dec_buf_no]; }
363
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
364
static const Hybrid_type_traits_decimal *instance();
365
Hybrid_type_traits_decimal() {};
369
struct Hybrid_type_traits_integer: public Hybrid_type_traits
371
virtual Item_result type() const { return INT_RESULT; }
374
fix_length_and_dec(Item *arg, Item *item) const;
376
/* Hybrid_type operations. */
377
virtual void set_zero(Hybrid_type *val) const
379
virtual void add(Hybrid_type *val, Field *f) const
380
{ val->integer+= f->val_int(); }
381
virtual void div(Hybrid_type *val, ulonglong u) const
382
{ val->integer/= (longlong) u; }
384
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const
385
{ return val->integer; }
386
virtual double val_real(Hybrid_type *val) const
387
{ return (double) val->integer; }
388
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const
390
int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
391
return &val->dec_buf[2];
393
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const
394
{ buf->set(val->integer, &my_charset_bin); return buf;}
395
static const Hybrid_type_traits_integer *instance();
396
Hybrid_type_traits_integer() {};
400
void dummy_error_processor(THD *thd, void *data);
402
void view_error_processor(THD *thd, void *data);
405
Instances of Name_resolution_context store the information necesary for
406
name resolution of Items and other context analysis of a query made in
409
This structure is a part of SELECT_LEX, a pointer to this structure is
410
assigned when an item is created (which happens mostly during parsing
411
(sql_yacc.yy)), but the structure itself will be initialized after parsing
414
TODO: move subquery of INSERT ... SELECT and CREATE ... SELECT to
415
separate SELECT_LEX which allow to remove tricks of changing this
416
structure before and after INSERT/CREATE and its SELECT to make correct
417
field name resolution.
419
struct Name_resolution_context: Sql_alloc
422
The name resolution context to search in when an Item cannot be
423
resolved in this context (the context of an outer select)
425
Name_resolution_context *outer_context;
428
List of tables used to resolve the items of this context. Usually these
429
are tables from the FROM clause of SELECT statement. The exceptions are
430
INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
431
subquery is not moved to a separate SELECT_LEX. For these types of
432
statements we have to change this member dynamically to ensure correct
433
name resolution of different parts of the statement.
435
TABLE_LIST *table_list;
437
In most cases the two table references below replace 'table_list' above
438
for the purpose of name resolution. The first and last name resolution
439
table references allow us to search only in a sub-tree of the nested
440
join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
443
TABLE_LIST *first_name_resolution_table;
445
Last table to search in the list of leaf table references that begins
446
with first_name_resolution_table.
448
TABLE_LIST *last_name_resolution_table;
451
SELECT_LEX item belong to, in case of merged VIEW it can differ from
452
SELECT_LEX where item was created, so we can't use table_list/field_list
455
st_select_lex *select_lex;
458
Processor of errors caused during Item name resolving, now used only to
459
hide underlying tables in errors about views (i.e. it substitute some
462
void (*error_processor)(THD *, void *);
463
void *error_processor_data;
466
When TRUE, items are resolved in this context against
467
SELECT_LEX::item_list, SELECT_lex::group_list and
468
this->table_list. If FALSE, items are resolved only against
471
@see st_select_lex::item_list, st_select_lex::group_list
473
bool resolve_in_select_list;
476
Security context of this name resolution context. It's used for views
477
and is non-zero only if the view is defined with SQL SECURITY DEFINER.
479
Security_context *security_ctx;
481
Name_resolution_context()
482
:outer_context(0), table_list(0), select_lex(0),
483
error_processor_data(0),
489
resolve_in_select_list= FALSE;
490
error_processor= &dummy_error_processor;
491
first_name_resolution_table= NULL;
492
last_name_resolution_table= NULL;
495
void resolve_in_table_list_only(TABLE_LIST *tables)
497
table_list= first_name_resolution_table= tables;
498
resolve_in_select_list= FALSE;
501
void process_error(THD *thd)
503
(*error_processor)(thd, error_processor_data);
509
Store and restore the current state of a name resolution context.
512
class Name_resolution_context_state
515
TABLE_LIST *save_table_list;
516
TABLE_LIST *save_first_name_resolution_table;
517
TABLE_LIST *save_next_name_resolution_table;
518
bool save_resolve_in_select_list;
519
TABLE_LIST *save_next_local;
522
Name_resolution_context_state() {} /* Remove gcc warning */
525
/* Save the state of a name resolution context. */
526
void save_state(Name_resolution_context *context, TABLE_LIST *table_list)
528
save_table_list= context->table_list;
529
save_first_name_resolution_table= context->first_name_resolution_table;
530
save_resolve_in_select_list= context->resolve_in_select_list;
531
save_next_local= table_list->next_local;
532
save_next_name_resolution_table= table_list->next_name_resolution_table;
535
/* Restore a name resolution context from saved state. */
536
void restore_state(Name_resolution_context *context, TABLE_LIST *table_list)
538
table_list->next_local= save_next_local;
539
table_list->next_name_resolution_table= save_next_name_resolution_table;
540
context->table_list= save_table_list;
541
context->first_name_resolution_table= save_first_name_resolution_table;
542
context->resolve_in_select_list= save_resolve_in_select_list;
545
TABLE_LIST *get_first_name_resolution_table()
547
return save_first_name_resolution_table;
553
This enum is used to report information about monotonicity of function
554
represented by Item* tree.
555
Monotonicity is defined only for Item* trees that represent table
556
partitioning expressions (i.e. have no subselects/user vars/PS parameters
557
etc etc). An Item* tree is assumed to have the same monotonicity properties
558
as its correspoinding function F:
560
[signed] longlong F(field1, field2, ...) {
561
put values of field_i into table record buffer;
562
return item->val_int();
566
At the moment function monotonicity is not well defined (and so may be
567
incorrect) for Item trees with parameters/return types that are different
568
from INT_RESULT, may be NULL, or are unsigned.
569
It will be possible to address this issue once the related partitioning bugs
570
(BUG#16002, BUG#15447, BUG#13436) are fixed.
572
The NOT_NULL enums are used in TO_DAYS, since TO_DAYS('2001-00-00') returns
573
NULL which puts those rows into the NULL partition, but
574
'2000-12-31' < '2001-00-00' < '2001-01-01'. So special handling is needed
575
for this (see Bug#20577).
578
typedef enum monotonicity_info
580
NON_MONOTONIC, /* none of the below holds */
581
MONOTONIC_INCREASING, /* F() is unary and (x < y) => (F(x) <= F(y)) */
582
MONOTONIC_INCREASING_NOT_NULL, /* But only for valid/real x and y */
583
MONOTONIC_STRICT_INCREASING,/* F() is unary and (x < y) => (F(x) < F(y)) */
584
MONOTONIC_STRICT_INCREASING_NOT_NULL /* But only for valid/real x and y */
585
} enum_monotonicity_info;
587
/*************************************************************************/
592
class Settable_routine_parameter
596
Set required privileges for accessing the parameter.
599
set_required_privilege()
600
rw if 'rw' is true then we are going to read and set the
601
parameter, so SELECT and UPDATE privileges might be
602
required, otherwise we only reading it and SELECT
603
privilege might be required.
605
Settable_routine_parameter() {}
606
virtual ~Settable_routine_parameter() {}
607
virtual void set_required_privilege(bool rw) {};
615
ctx context to which parameter belongs (if it is local
617
it item which represents new value
620
FALSE if parameter value has been set,
621
TRUE if error has occured.
623
virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it)= 0;
625
virtual void set_out_param_info(Send_field *info) {}
627
virtual const Send_field *get_out_param_info() const
632
typedef bool (Item::*Item_processor) (uchar *arg);
636
argp in/out IN: Analysis parameter
637
OUT: Parameter to be passed to the transformer
640
TRUE Invoke the transformer
644
typedef bool (Item::*Item_analyzer) (uchar **argp);
645
typedef Item* (Item::*Item_transformer) (uchar *arg);
646
typedef void (*Cond_traverser) (const Item *item, void *arg);
651
Item(const Item &); /* Prevent use of these */
652
void operator=(Item &);
653
/* Cache of the result of is_expensive(). */
654
int8 is_expensive_cache;
655
virtual bool is_expensive_processor(uchar *arg) { return 0; }
658
static void *operator new(size_t size) throw ()
659
{ return sql_alloc(size); }
660
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
661
{ return alloc_root(mem_root, size); }
662
static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
663
static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
665
enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM,
666
INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM,
667
COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM,
668
PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
669
FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
670
SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
671
PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM,
672
XPATH_NODESET, XPATH_NODESET_CMP,
675
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
677
enum traverse_order { POSTFIX, PREFIX };
679
/* Reuse size, only used by SP local variable assignment, otherwize 0 */
683
str_values's main purpose is to be used to cache the value in
688
Item_name_string item_name; /* Name from select */
689
Item_name_string orig_name; /* Original item name (if it was renamed)*/
692
Intrusive list pointer for free list. If not null, points to the next
693
Item on some Query_arena's free list. For instance, stored procedures
694
have their own Query_arena's.
696
@see Query_arena::free_list
699
uint32 max_length; /* Maximum length, in bytes */
701
This member has several successive meanings, depending on the phase we're
703
- during field resolution: it contains the index, in the "all_fields"
704
list, of the expression to which this field belongs; or a special
705
constant UNDEF_POS; see st_select_lex::cur_pos_in_all_fields and
706
match_exprs_for_only_full_group_by().
707
- when attaching conditions to tables: it says whether some condition
708
needs to be attached or can be omitted (for example because it is already
709
implemented by 'ref' access)
710
- when pushing index conditions: it says whether a condition uses only
712
- when creating an internal temporary table: it says how to store BIT
714
- when we change DISTINCT to GROUP BY: it is used for book-keeping of
719
my_bool maybe_null; /* If item may be null */
720
my_bool null_value; /* if item is null */
721
my_bool unsigned_flag;
722
my_bool with_sum_func;
723
my_bool fixed; /* If item fixed with fix_fields */
724
DTCollation collation;
725
Item_result cmp_context; /* Comparison context */
727
my_bool with_subselect; /* If this item is a subselect or some
728
of its arguments is or contains a
729
subselect. Computed by fix_fields
730
and updated by update_used_tables. */
731
my_bool with_stored_program; /* If this item is a stored program
732
or some of its arguments is or
733
contains a stored program.
734
Computed by fix_fields and updated
735
by update_used_tables. */
738
This variable is a cache of 'Needed tables are locked'. True if either
739
'No tables locks is needed' or 'Needed tables are locked'.
740
If tables are used, then it will be set to
741
current_thd->lex->is_query_tables_locked().
743
It is used when checking const_item()/can_be_evaluated_now().
745
bool tables_locked_cache;
747
// alloc & destruct is done as start of select using sql_alloc
750
Constructor used by Item_field, Item_ref & aggregate (sum) functions.
751
Used for duplicating lists in processing queries with temporary
753
Also it used for Item_cond_and/Item_cond_or for creating
754
top AND/OR structure of WHERE clause to protect it of
755
optimisation changes in prepared statements
757
Item(THD *thd, Item *item);
764
void rename(char *new_name);
765
void init_make_field(Send_field *tmp_field,enum enum_field_types type);
766
virtual void cleanup();
767
virtual void make_field(Send_field *field);
768
virtual Field *make_string_field(TABLE *table);
769
virtual bool fix_fields(THD *, Item **);
771
Fix after tables have been moved from one select_lex level to the parent
772
level, e.g by semijoin conversion.
773
Basically re-calculate all attributes dependent on the tables.
775
@param parent_select select_lex that tables are moved to.
776
@param removed_select select_lex that tables are moved away from,
777
child of parent_select.
779
virtual void fix_after_pullout(st_select_lex *parent_select,
780
st_select_lex *removed_select)
783
should be used in case where we are sure that we do not need
784
complete fix_fields() procedure.
786
inline void quick_fix_field() { fixed= 1; }
787
/* Function returns 1 on overflow and -1 on fatal errors */
788
type_conversion_status save_in_field_no_warnings(Field *field,
789
bool no_conversions);
791
Save a temporal value in packed longlong format into a Field.
793
@param OUT field The field to set the value to.
794
@retval 0 On success.
797
virtual type_conversion_status save_in_field(Field *field,
798
bool no_conversions);
799
virtual void save_org_in_field(Field *field)
800
{ (void) save_in_field(field, 1); }
801
virtual type_conversion_status save_safe_in_field(Field *field)
802
{ return save_in_field(field, 1); }
803
virtual bool send(Protocol *protocol, String *str);
804
virtual bool eq(const Item *, bool binary_cmp) const;
805
virtual Item_result result_type() const { return REAL_RESULT; }
807
Result type when an item appear in a numeric context.
808
See Field::numeric_context_result_type() for more comments.
810
virtual enum Item_result numeric_context_result_type() const
813
return decimals ? DECIMAL_RESULT : INT_RESULT;
814
if (result_type() == STRING_RESULT)
816
return result_type();
819
Similar to result_type() but makes DATE, DATETIME, TIMESTAMP
820
pretend to be numbers rather than strings.
822
inline enum Item_result temporal_with_date_as_number_result_type() const
824
return is_temporal_with_date() ?
825
(decimals ? DECIMAL_RESULT : INT_RESULT) : result_type();
827
virtual Item_result cast_to_int_type() const { return result_type(); }
828
virtual enum_field_types string_field_type() const;
829
virtual enum_field_types field_type() const;
830
virtual enum Type type() const =0;
833
Return information about function monotonicity. See comment for
834
enum_monotonicity_info for details. This function can only be called
835
after fix_fields() call.
837
virtual enum_monotonicity_info get_monotonicity_info() const
838
{ return NON_MONOTONIC; }
841
Convert "func_arg $CMP$ const" half-interval into "FUNC(func_arg) $CMP2$ const2"
845
left_endp FALSE <=> The interval is "x < const" or "x <= const"
846
TRUE <=> The interval is "x > const" or "x >= const"
848
incl_endp IN FALSE <=> the comparison is '<' or '>'
849
TRUE <=> the comparison is '<=' or '>='
850
OUT The same but for the "F(x) $CMP$ F(const)" comparison
853
This function is defined only for unary monotonic functions. The caller
854
supplies the source half-interval
858
The value of const is supplied implicitly as the value this item's
859
argument, the form of $CMP$ comparison is specified through the
860
function's arguments. The calle returns the result interval
864
passing back F(const) as the return value, and the form of $CMP2$
865
through the out parameter. NULL values are assumed to be comparable and
866
be less than any non-NULL values.
869
The output range bound, which equal to the value of val_int()
870
- If the value of the function is NULL then the bound is the
871
smallest possible value of LONGLONG_MIN
873
virtual longlong val_int_endpoint(bool left_endp, bool *incl_endp)
874
{ DBUG_ASSERT(0); return 0; }
877
/* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */
879
Return double precision floating point representation of item.
885
In case of NULL value return 0.0 and set null_value flag to TRUE.
886
If value is not null null_value flag will be reset to FALSE.
888
virtual double val_real()=0;
890
Return integer representation of item.
896
In case of NULL value return 0 and set null_value flag to TRUE.
897
If value is not null null_value flag will be reset to FALSE.
899
virtual longlong val_int()=0;
901
Return date value of item in packed longlong format.
903
virtual longlong val_date_temporal();
905
Return time value of item in packed longlong format.
907
virtual longlong val_time_temporal();
909
Return date or time value of item in packed longlong format,
910
depending on item field type.
912
longlong val_temporal_by_field_type()
914
if (field_type() == MYSQL_TYPE_TIME)
915
return val_time_temporal();
916
DBUG_ASSERT(is_temporal_with_date());
917
return val_date_temporal();
920
Get date or time value in packed longlong format.
921
Before conversion from MYSQL_TIME to packed format,
922
the MYSQL_TIME value is rounded to "dec" fractional digits.
924
longlong val_temporal_with_round(enum_field_types type, uint8 dec);
927
This is just a shortcut to avoid the cast. You should still use
928
unsigned_flag to check the sign of the item.
930
inline ulonglong val_uint() { return (ulonglong) val_int(); }
932
Return string representation of this item object.
936
str an allocated buffer this or any nested Item object can use to
937
store return value of this method.
940
Buffer passed via argument should only be used if the item itself
941
doesn't have an own String buffer. In case when the item maintains
942
it's own string buffer, it's preferable to return it instead to
943
minimize number of mallocs/memcpys.
944
The caller of this method can modify returned string, but only in case
945
when it was allocated on heap, (is_alloced() is true). This allows
946
the caller to efficiently use a buffer allocated by a child without
947
having to allocate a buffer of it's own. The buffer, given to
948
val_str() as argument, belongs to the caller and is later used by the
949
caller at it's own choosing.
950
A few implications from the above:
951
- unless you return a string object which only points to your buffer
952
but doesn't manages it you should be ready that it will be
954
- even for not allocated strings (is_alloced() == false) the caller
955
can change charset (see Item_func_{typecast/binary}. XXX: is this
957
- still you should try to minimize data copying and return internal
958
object whenever possible.
961
In case of NULL value return 0 (NULL pointer) and set null_value flag
963
If value is not null null_value flag will be reset to FALSE.
965
virtual String *val_str(String *str)=0;
968
Returns string representation of this item in ASCII format.
972
str - similar to val_str();
975
This method is introduced for performance optimization purposes.
977
1. val_str() result of some Items in string context
978
depends on @@character_set_results.
979
@@character_set_results can be set to a "real multibyte" character
980
set like UCS2, UTF16, UTF32. (We'll use only UTF32 in the examples
981
below for convenience.)
983
So the default string result of such functions
984
in these circumstances is real multi-byte character set, like UTF32.
986
For example, all numbers in string context
987
return result in @@character_set_results:
989
SELECT CONCAT(20010101); -> UTF32
991
We do sprintf() first (to get ASCII representation)
992
and then convert to UTF32;
994
So these kind "data sources" can use ASCII representation
995
internally, but return multi-byte data only because
996
@@character_set_results wants so.
997
Therefore, conversion from ASCII to UTF32 is applied internally.
1000
2. Some other functions need in fact ASCII input.
1003
inet_aton(), GeometryFromText(), Convert_TZ(), GET_FORMAT().
1005
Similar, fields of certain type, like DATE, TIME,
1006
when you insert string data into them, expect in fact ASCII input.
1007
If they get non-ASCII input, for example UTF32, they
1008
convert input from UTF32 to ASCII, and then use ASCII
1009
representation to do further processing.
1012
3. Now imagine we pass result of a data source of the first type
1013
to a data destination of the second type.
1016
a. data source converts data from ASCII to UTF32, because
1017
@@character_set_results wants so and passes the result to
1019
b. data destination gets UTF32 string.
1020
c. data destination converts UTF32 string to ASCII,
1021
because it needs ASCII representation to be able to handle data
1024
As a result we get two steps of unnecessary conversion:
1025
From ASCII to UTF32, then from UTF32 to ASCII.
1027
A better way to handle these situations is to pass ASCII
1028
representation directly from the source to the destination.
1030
This is why val_str_ascii() introduced.
1033
Similar to val_str()
1035
virtual String *val_str_ascii(String *str);
1038
Return decimal representation of item with fixed point.
1042
decimal_buffer buffer which can be used by Item for returning value
1046
Returned value should not be changed if it is not the same which was
1047
passed via argument.
1050
Return pointer on my_decimal (it can be other then passed via argument)
1051
if value is not NULL (null_value flag will be reset to FALSE).
1052
In case of NULL value it return 0 pointer and set null_value flag
1055
virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
1057
Return boolean value of item.
1060
FALSE value is false or NULL
1061
TRUE value is true (not equal to 0)
1063
virtual bool val_bool();
1064
virtual String *val_nodeset(String*) { return 0; }
1067
/* Helper functions, see item_sum.cc */
1068
String *val_string_from_real(String *str);
1069
String *val_string_from_int(String *str);
1070
String *val_string_from_decimal(String *str);
1071
String *val_string_from_date(String *str);
1072
String *val_string_from_datetime(String *str);
1073
String *val_string_from_time(String *str);
1074
my_decimal *val_decimal_from_real(my_decimal *decimal_value);
1075
my_decimal *val_decimal_from_int(my_decimal *decimal_value);
1076
my_decimal *val_decimal_from_string(my_decimal *decimal_value);
1077
my_decimal *val_decimal_from_date(my_decimal *decimal_value);
1078
my_decimal *val_decimal_from_time(my_decimal *decimal_value);
1079
longlong val_int_from_decimal();
1080
longlong val_int_from_date();
1081
longlong val_int_from_time();
1082
longlong val_int_from_datetime();
1083
double val_real_from_decimal();
1086
Convert val_str() to date in MYSQL_TIME
1088
bool get_date_from_string(MYSQL_TIME *ltime, uint flags);
1090
Convert val_real() to date in MYSQL_TIME
1092
bool get_date_from_real(MYSQL_TIME *ltime, uint flags);
1094
Convert val_decimal() to date in MYSQL_TIME
1096
bool get_date_from_decimal(MYSQL_TIME *ltime, uint flags);
1098
Convert val_int() to date in MYSQL_TIME
1100
bool get_date_from_int(MYSQL_TIME *ltime, uint flags);
1102
Convert get_time() from time to date in MYSQL_TIME
1104
bool get_date_from_time(MYSQL_TIME *ltime);
1107
Convert a numeric type to date
1109
bool get_date_from_numeric(MYSQL_TIME *ltime, uint fuzzydate);
1112
Convert a non-temporal type to date
1114
bool get_date_from_non_temporal(MYSQL_TIME *ltime, uint fuzzydate);
1117
Convert val_str() to time in MYSQL_TIME
1119
bool get_time_from_string(MYSQL_TIME *ltime);
1121
Convert val_real() to time in MYSQL_TIME
1123
bool get_time_from_real(MYSQL_TIME *ltime);
1125
Convert val_decimal() to time in MYSQL_TIME
1127
bool get_time_from_decimal(MYSQL_TIME *ltime);
1129
Convert val_int() to time in MYSQL_TIME
1131
bool get_time_from_int(MYSQL_TIME *ltime);
1133
Convert date to time
1135
bool get_time_from_date(MYSQL_TIME *ltime);
1137
Convert datetime to time
1139
bool get_time_from_datetime(MYSQL_TIME *ltime);
1142
Convert a numeric type to time
1144
bool get_time_from_numeric(MYSQL_TIME *ltime);
1147
Convert a non-temporal type to time
1149
bool get_time_from_non_temporal(MYSQL_TIME *ltime);
1154
type_conversion_status save_time_in_field(Field *field);
1155
type_conversion_status save_date_in_field(Field *field);
1156
type_conversion_status save_str_value_in_field(Field *field, String *result);
1158
virtual Field *get_tmp_table_field() { return 0; }
1159
/* This is also used to create fields in CREATE ... SELECT: */
1160
virtual Field *tmp_table_field(TABLE *t_arg) { return 0; }
1161
virtual const char *full_name() const
1163
return item_name.is_set() ? item_name.ptr() : "???";
1167
*result* family of methods is analog of *val* family (see above) but
1168
return value of result_field of item if it is present. If Item have not
1169
result field, it return val(). This methods set null_value flag in same
1170
way as *val* methods do it.
1172
virtual double val_result() { return val_real(); }
1173
virtual longlong val_int_result() { return val_int(); }
1175
Get time value in packed longlong format. NULL is converted to 0.
1177
virtual longlong val_time_temporal_result() { return val_time_temporal(); }
1179
Get date value in packed longlong format. NULL is converted to 0.
1181
virtual longlong val_date_temporal_result() { return val_date_temporal(); }
1182
virtual String *str_result(String* tmp) { return val_str(tmp); }
1183
virtual my_decimal *val_decimal_result(my_decimal *val)
1184
{ return val_decimal(val); }
1185
virtual bool val_bool_result() { return val_bool(); }
1186
virtual bool is_null_result() { return is_null(); }
1188
/* bit map of tables used by item */
1189
virtual table_map used_tables() const { return (table_map) 0L; }
1191
Return used table information for the level this item is resolved on.
1192
- For fields, this returns the table the item is resolved from.
1193
- For all other items, this behaves like used_tables().
1195
@note: Use this function with caution. External calls to this function
1196
should only be made for class objects derived from Item_ident.
1197
Item::resolved_used_tables is for internal use only, in order to
1198
process fields underlying a view column reference.
1200
virtual table_map resolved_used_tables() const
1202
// As this is the level this item was resolved on, it cannot be outer:
1203
DBUG_ASSERT(!(used_tables() & OUTER_REF_TABLE_BIT));
1205
return used_tables();
1208
Return table map of tables that can't be NULL tables (tables that are
1209
used in a context where if they would contain a NULL row generated
1210
by a LEFT or RIGHT join, the item would not be true).
1211
This expression is used on WHERE item to determinate if a LEFT JOIN can be
1212
converted to a normal join.
1213
Generally this function should return used_tables() if the function
1214
would return null if any of the arguments are null
1215
As this is only used in the beginning of optimization, the value don't
1216
have to be updated in update_used_tables()
1218
virtual table_map not_null_tables() const { return used_tables(); }
1220
Returns true if this is a simple constant item like an integer, not
1221
a constant expression. Used in the optimizer to propagate basic constants.
1223
virtual bool basic_const_item() const { return 0; }
1224
/* cloning of constant items (0 if it is not const) */
1225
virtual Item *clone_item() { return 0; }
1226
virtual cond_result eq_cmp_result() const { return COND_OK; }
1227
inline uint float_length(uint decimals_par) const
1228
{ return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;}
1229
virtual uint decimal_precision() const;
1230
inline int decimal_int_part() const
1231
{ return my_decimal_int_part(decimal_precision(), decimals); }
1233
TIME precision of the item: 0..6
1235
virtual uint time_precision();
1237
DATETIME precision of the item: 0..6
1239
virtual uint datetime_precision();
1241
Returns true if this is constant (during query execution, i.e. its value
1242
will not change until next fix_fields) and its value is known.
1243
When the default implementation of used_tables() is effective, this
1244
function will always return true (because used_tables() is empty).
1246
virtual bool const_item() const
1248
if (used_tables() == 0)
1249
return can_be_evaluated_now();
1253
Returns true if this is constant but its value may be not known yet.
1254
(Can be used for parameters of prep. stmts or of stored procedures.)
1256
virtual bool const_during_execution() const
1257
{ return (used_tables() & ~PARAM_TABLE_BIT) == 0; }
1260
This method is used for to:
1261
- to generate a view definition query (SELECT-statement);
1262
- to generate a SQL-query for EXPLAIN EXTENDED;
1263
- to generate a SQL-query to be shown in INFORMATION_SCHEMA;
1266
For more information about view definition query, INFORMATION_SCHEMA
1267
query and why they should be generated from the Item-tree, @see
1268
mysql_register_view().
1270
virtual inline void print(String *str, enum_query_type query_type)
1272
str->append(full_name());
1275
void print_item_w_name(String *, enum_query_type query_type);
1277
Prints the item when it's part of ORDER BY and GROUP BY.
1278
@param str String to print to
1279
@param query_type How to format the item
1280
@param used_alias Whether item was referenced with alias.
1282
void print_for_order(String *str, enum_query_type query_type,
1285
virtual void update_used_tables() {}
1286
virtual void split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array,
1287
List<Item> &fields) {}
1288
/* Called for items that really have to be split */
1289
void split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
1291
Item **ref, bool skip_registered);
1292
virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate)= 0;
1293
virtual bool get_time(MYSQL_TIME *ltime)= 0;
1295
Get timestamp in "struct timeval" format.
1296
@retval false on success
1297
@retval true on error
1299
virtual bool get_timeval(struct timeval *tm, int *warnings);
1300
virtual bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate)
1301
{ return get_date(ltime,fuzzydate); }
1303
The method allows to determine nullness of a complex expression
1304
without fully evaluating it, instead of calling val/result*() then
1305
checking null_value. Used in Item_func_isnull/Item_func_isnotnull
1306
and Item_sum_count/Item_sum_count_distinct.
1307
Any new item which can be NULL must implement this method.
1309
virtual bool is_null() { return 0; }
1312
Make sure the null_value member has a correct value.
1314
virtual void update_null_value () { (void) val_int(); }
1317
Inform the item that there will be no distinction between its result
1318
being FALSE or NULL.
1321
This function will be called for eg. Items that are top-level AND-parts
1322
of the WHERE clause. Items implementing this function (currently
1323
Item_cond_and and subquery-related item) enable special optimizations
1324
when they are "top level".
1326
virtual void top_level_item() {}
1328
set field of temporary table for Item which can be switched on temporary
1329
table during query processing (grouping and so on)
1331
virtual void set_result_field(Field *field) {}
1332
virtual bool is_result_field() { return 0; }
1333
virtual bool is_bool_func() { return 0; }
1334
virtual void save_in_result_field(bool no_conversions) {}
1336
Set value of aggregate function in case of no rows for grouping were found.
1337
Also used for subqueries with outer references in SELECT list.
1339
virtual void no_rows_in_result() {}
1340
virtual Item *copy_or_same(THD *thd) { return this; }
1342
@param real_items True <=> in the copy, replace any Item_ref with its
1344
@todo this argument should be always false and removed in WL#7082.
1346
virtual Item *copy_andor_structure(THD *thd, bool real_items= false)
1347
{ return real_items ? real_item() : this; }
1348
virtual Item *real_item() { return this; }
1349
virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
1351
static const CHARSET_INFO *default_charset();
1352
virtual const CHARSET_INFO *compare_collation() { return NULL; }
1355
For backward compatibility, to make numeric
1356
data types return "binary" charset in client-side metadata.
1358
virtual const CHARSET_INFO *charset_for_protocol(void) const
1360
return result_type() == STRING_RESULT ? collation.collation :
1364
virtual bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
1366
return (this->*processor)(arg);
1369
virtual Item* transform(Item_transformer transformer, uchar *arg);
1372
This function performs a generic "compilation" of the Item tree.
1373
The process of compilation is assumed to go as follows:
1377
if (this->*some_analyzer(...))
1379
compile children if any;
1380
return this->*some_transformer(...);
1386
i.e. analysis is performed top-down while transformation is done
1387
bottom-up. If no transformation is applied, the item is returned unchanged.
1388
A transformation error is indicated by returning a NULL pointer. Notice
1389
that the analyzer function should never cause an error.
1391
virtual Item* compile(Item_analyzer analyzer, uchar **arg_p,
1392
Item_transformer transformer, uchar *arg_t)
1394
if ((this->*analyzer) (arg_p))
1395
return ((this->*transformer) (arg_t));
1399
virtual void traverse_cond(Cond_traverser traverser,
1400
void *arg, traverse_order order)
1402
(*traverser)(this, arg);
1406
This is used to get the most recent version of any function in
1407
an item tree. The version is the version where a MySQL function
1408
was introduced in. So any function which is added should use
1409
this function and set the int_arg to maximum of the input data
1410
and their own version info.
1412
virtual bool intro_version(uchar *int_arg) { return 0; }
1414
virtual bool remove_dependence_processor(uchar * arg) { return 0; }
1415
virtual bool remove_fixed(uchar * arg) { fixed= 0; return 0; }
1416
virtual bool cleanup_processor(uchar *arg);
1417
virtual bool collect_item_field_processor(uchar * arg) { return 0; }
1418
virtual bool add_field_to_set_processor(uchar * arg) { return 0; }
1421
Visitor interface for removing all column expressions (Item_field) in
1422
this expression tree from a bitmap. @See walk()
1424
@param arg A MY_BITMAP* cast to unsigned char*, where the bits represent
1425
Field::field_index values.
1427
virtual bool remove_column_from_bitmap(uchar *arg) { return false; }
1428
virtual bool find_item_in_field_list_processor(uchar *arg) { return 0; }
1429
virtual bool change_context_processor(uchar *context) { return 0; }
1430
virtual bool reset_query_id_processor(uchar *query_id_arg) { return 0; }
1431
virtual bool find_item_processor(uchar *arg) { return this == (void *) arg; }
1432
virtual bool register_field_in_read_map(uchar *arg) { return 0; }
1433
virtual bool inform_item_in_cond_of_tab(uchar *join_tab_index) { return false; }
1435
Clean up after removing the item from the item tree.
1437
@param arg Pointer to the st_select_lex from which the walk started, i.e.,
1438
the st_select_lex that contained the clause that was removed.
1440
virtual bool clean_up_after_removal(uchar *arg) { return false; }
1442
virtual bool cache_const_expr_analyzer(uchar **arg);
1443
virtual Item* cache_const_expr_transformer(uchar *arg);
1446
Analyzer for finding Item_field by name
1448
@param arg Field name to search for
1450
@return TRUE Go deeper in item tree. (Found Item or not an Item_field)
1451
@return FALSE Don't go deeper in item tree. (Item_field with other name)
1453
virtual bool item_field_by_name_analyzer(uchar **arg) { return true; };
1456
Simple transformer that returns the argument if this is an Item_field.
1457
The new item will inherit it's name to maintain aliases.
1459
@param arg Item to replace Item_field
1461
@return argument if this is an Item_field
1462
@return this otherwise.
1464
virtual Item* item_field_by_name_transformer(uchar *arg) { return this; }
1466
virtual bool equality_substitution_analyzer(uchar **arg) { return false; }
1468
virtual Item* equality_substitution_transformer(uchar *arg) { return this; }
1471
Check if a partition function is allowed
1473
check_partition_func_processor()
1476
TRUE Partition function not accepted
1477
FALSE Partition function accepted
1480
check_partition_func_processor is used to check if a partition function
1481
uses an allowed function. An allowed function will always ensure that
1482
X=Y guarantees that also part_function(X)=part_function(Y) where X is
1483
a set of partition fields and so is Y. The problems comes mainly from
1484
character sets where two equal strings can be quite unequal. E.g. the
1485
german character for double s is equal to 2 s.
1487
The default is that an item is not allowed
1488
in a partition function. Allowed functions
1489
can never depend on server version, they cannot depend on anything
1490
related to the environment. They can also only depend on a set of
1491
fields in the table itself. They cannot depend on other tables and
1492
cannot contain any queries and cannot contain udf's or similar.
1493
If a new Item class is defined and it inherits from a class that is
1494
allowed in a partition function then it is very important to consider
1495
whether this should be inherited to the new class. If not the function
1496
below should be defined in the new Item class.
1498
The general behaviour is that most integer functions are allowed.
1499
If the partition function contains any multi-byte collations then
1500
the function check_part_func_fields will report an error on the
1501
partition function independent of what functions are used. So the
1502
only character sets allowed are single character collation and
1503
even for those only a limited set of functions are allowed. The
1504
problem with multi-byte collations is that almost every string
1505
function has the ability to change things such that two strings
1506
that are equal will not be equal after manipulated by a string
1507
function. E.g. two strings one contains a double s, there is a
1508
special german character that is equal to two s. Now assume a
1509
string function removes one character at this place, then in
1510
one the double s will be removed and in the other there will
1511
still be one s remaining and the strings are no longer equal
1512
and thus the partition function will not sort equal strings into
1513
the same partitions.
1515
So the check if a partition function is valid is two steps. First
1516
check that the field types are valid, next check that the partition
1517
function is valid. The current set of partition functions valid
1518
assumes that there are no multi-byte collations amongst the partition
1521
virtual bool check_partition_func_processor(uchar *bool_arg) { return TRUE;}
1522
virtual bool subst_argument_checker(uchar **arg)
1528
virtual bool explain_subquery_checker(uchar **arg) { return true; }
1529
virtual Item *explain_subquery_propagator(uchar *arg) { return this; }
1531
virtual Item *equal_fields_propagator(uchar * arg) { return this; }
1532
virtual bool set_no_const_sub(uchar *arg) { return FALSE; }
1533
virtual Item *replace_equal_field(uchar * arg) { return this; }
1535
Check if an expression value has allowed arguments, like DATE/DATETIME
1536
for date functions. Also used by partitioning code to reject
1537
timezone-dependent expressions in a (sub)partitioning function.
1539
virtual bool check_valid_arguments_processor(uchar *bool_arg)
1545
Find a function of a given type
1547
@param arg the function type to search (enum Item_func::Functype)
1549
@retval TRUE the function type we're searching for is found
1550
@retval FALSE the function type wasn't found
1553
This function can be used (together with Item::walk()) to find functions
1554
in an item tree fragment.
1556
virtual bool find_function_processor (uchar *arg)
1562
For SP local variable returns pointer to Item representing its
1563
current value and pointer to current Item otherwise.
1565
virtual Item *this_item() { return this; }
1566
virtual const Item *this_item() const { return this; }
1569
For SP local variable returns address of pointer to Item representing its
1570
current value and pointer passed via parameter otherwise.
1572
virtual Item **this_item_addr(THD *thd, Item **addr_arg) { return addr_arg; }
1575
virtual uint cols() { return 1; }
1576
virtual Item* element_index(uint i) { return this; }
1577
virtual Item** addr(uint i) { return 0; }
1578
virtual bool check_cols(uint c);
1579
// It is not row => null inside is impossible
1580
virtual bool null_inside() { return 0; }
1581
// used in row subselects to get value of elements
1582
virtual void bring_value() {}
1584
Field *tmp_table_field_from_field_type(TABLE *table, bool fixed_length);
1585
virtual Item_field *field_for_view_update() { return 0; }
1587
virtual Item *neg_transformer(THD *thd) { return NULL; }
1588
virtual Item *update_value_transformer(uchar *select_arg) { return this; }
1589
virtual Item *safe_charset_converter(const CHARSET_INFO *tocs);
1596
virtual bool is_splocal() { return 0; } /* Needed for error checking */
1599
Return Settable_routine_parameter interface of the Item. Return 0
1600
if this Item is not Settable_routine_parameter.
1602
virtual Settable_routine_parameter *get_settable_routine_parameter()
1606
inline bool is_temporal_with_date() const
1608
return is_temporal_type_with_date(field_type());
1610
inline bool is_temporal_with_date_and_time() const
1612
return is_temporal_type_with_date_and_time(field_type());
1614
inline bool is_temporal_with_time() const
1616
return is_temporal_type_with_time(field_type());
1618
inline bool is_temporal() const
1620
return is_temporal_type(field_type());
1623
Check whether this and the given item has compatible comparison context.
1624
Used by the equality propagation. See Item_field::equal_fields_propagator.
1627
TRUE if the context is the same or if fields could be
1628
compared as DATETIME values by the Arg_comparator.
1631
inline bool has_compatible_context(Item *item) const
1634
if (cmp_context == (Item_result)-1 || item->cmp_context == cmp_context)
1636
/* DATETIME comparison context. */
1637
if (is_temporal_with_date())
1638
return item->is_temporal_with_date() ||
1639
item->cmp_context == STRING_RESULT;
1640
if (item->is_temporal_with_date())
1641
return is_temporal_with_date() || cmp_context == STRING_RESULT;
1644
virtual Field::geometry_type get_geometry_type() const
1645
{ return Field::GEOM_GEOMETRY; };
1646
String *check_well_formed_result(String *str, bool send_error= 0);
1647
bool eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO *cs);
1650
Test whether an expression is expensive to compute. Used during
1651
optimization to avoid computing expensive expressions during this
1652
phase. Also used to force temp tables when sorting on expensive
1655
Normally we should have a method:
1656
cost Item::execution_cost(),
1657
where 'cost' is either 'double' or some structure of various cost
1660
virtual bool is_expensive()
1662
if (is_expensive_cache < 0)
1663
is_expensive_cache= walk(&Item::is_expensive_processor, 0, (uchar*)0);
1664
return MY_TEST(is_expensive_cache);
1666
virtual bool can_be_evaluated_now() const;
1667
uint32 max_char_length() const
1668
{ return max_length / collation.collation->mbmaxlen; }
1669
void fix_length_and_charset(uint32 max_char_length_arg,
1670
const CHARSET_INFO *cs)
1672
max_length= char_to_byte_length_safe(max_char_length_arg, cs->mbmaxlen);
1673
collation.collation= cs;
1675
void fix_char_length(uint32 max_char_length_arg)
1677
max_length= char_to_byte_length_safe(max_char_length_arg,
1678
collation.collation->mbmaxlen);
1680
void fix_char_length_ulonglong(ulonglong max_char_length_arg)
1682
ulonglong max_result_length= max_char_length_arg *
1683
collation.collation->mbmaxlen;
1684
if (max_result_length >= MAX_BLOB_WIDTH)
1686
max_length= MAX_BLOB_WIDTH;
1690
max_length= (uint32) max_result_length;
1692
void fix_length_and_charset_datetime(uint32 max_char_length_arg)
1694
collation.set(&my_charset_numeric, DERIVATION_NUMERIC, MY_REPERTOIRE_ASCII);
1695
fix_char_length(max_char_length_arg);
1697
void fix_length_and_dec_and_charset_datetime(uint32 max_char_length_arg,
1701
fix_length_and_charset_datetime(max_char_length_arg +
1702
(dec_arg ? dec_arg + 1 : 0));
1705
Return TRUE if the item points to a column of an outer-joined table.
1707
virtual bool is_outer_field() const { DBUG_ASSERT(fixed); return FALSE; }
1710
Check if an item either is a blob field, or will be represented as a BLOB
1711
field if a field is created based on this item.
1713
@retval TRUE If a field based on this item will be a BLOB field,
1714
@retval FALSE Otherwise.
1716
bool is_blob_field() const;
1719
Checks if this item or any of its decendents contains a subquery.
1721
virtual bool has_subquery() const { return with_subselect; }
1722
virtual bool has_stored_program() const { return with_stored_program; }
1723
/// Whether this Item was created by the IN->EXISTS subquery transformation
1724
virtual bool created_by_in2exists() const { return false; }
1731
class Item_basic_constant :public Item
1733
table_map used_table_map;
1735
Item_basic_constant(): Item(), used_table_map(0) {};
1736
void set_used_tables(table_map map) { used_table_map= map; }
1737
table_map used_tables() const { return used_table_map; }
1738
/* to prevent drop fixed flag (no need parent cleanup call) */
1742
Restore the original field name as it might not have been allocated
1743
in the statement memory. If the name is auto generated, it must be
1744
done again between subsequent executions of a prepared statement.
1746
if (orig_name.is_set())
1747
item_name= orig_name;
1752
/*****************************************************************************
1753
The class is a base class for representation of stored routine variables in
1754
the Item-hierarchy. There are the following kinds of SP-vars:
1755
- local variables (Item_splocal);
1756
- CASE expression (Item_case_expr);
1757
*****************************************************************************/
1759
class Item_sp_variable :public Item
1763
THD, which is stored in fix_fields() and is used in this_item() to avoid
1774
Routine to which this Item_splocal belongs. Used for checking if correct
1775
runtime context is used for variable handling.
1781
Item_sp_variable(const Name_string sp_var_name);
1784
bool fix_fields(THD *thd, Item **);
1788
String *val_str(String *sp);
1789
my_decimal *val_decimal(my_decimal *decimal_value);
1790
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
1791
bool get_time(MYSQL_TIME *ltime);
1795
inline void make_field(Send_field *field);
1796
inline type_conversion_status save_in_field(Field *field,
1797
bool no_conversions);
1798
inline bool send(Protocol *protocol, String *str);
1801
/*****************************************************************************
1802
Item_sp_variable inline implementation.
1803
*****************************************************************************/
1805
inline void Item_sp_variable::make_field(Send_field *field)
1807
Item *it= this_item();
1808
it->item_name.copy(item_name.is_set() ? item_name : m_name);
1809
it->make_field(field);
1812
inline type_conversion_status
1813
Item_sp_variable::save_in_field(Field *field, bool no_conversions)
1815
return this_item()->save_in_field(field, no_conversions);
1818
inline bool Item_sp_variable::send(Protocol *protocol, String *str)
1820
return this_item()->send(protocol, str);
1824
/*****************************************************************************
1825
A reference to local SP variable (incl. reference to SP parameter), used in
1827
*****************************************************************************/
1829
class Item_splocal :public Item_sp_variable,
1830
private Settable_routine_parameter
1835
Item_result m_result_type;
1836
enum_field_types m_field_type;
1839
If this variable is a parameter in LIMIT clause.
1840
Used only during NAME_CONST substitution, to not append
1841
NAME_CONST to the resulting query and thus not break
1844
bool limit_clause_param;
1846
Position of this reference to SP variable in the statement (the
1847
statement itself is in sp_instr_stmt::m_query).
1848
This is valid only for references to SP variables in statements,
1849
excluding DECLARE CURSOR statement. It is used to replace references to SP
1850
variables with NAME_CONST calls when putting statements into the binary
1852
Value of 0 means that this object doesn't corresponding to reference to
1853
SP variable in query text.
1857
Byte length of SP variable name in the statement (see pos_in_query).
1858
The value of this field may differ from the name_length value because
1859
name_length contains byte length of UTF8-encoded item name, but
1860
the query string (see sp_instr_stmt::m_query) is currently stored with
1861
a charset from the SET NAMES statement.
1865
Item_splocal(const Name_string sp_var_name, uint sp_var_idx,
1866
enum_field_types sp_var_type,
1867
uint pos_in_q= 0, uint len_in_q= 0);
1869
bool is_splocal() { return 1; } /* Needed for error checking */
1872
const Item *this_item() const;
1873
Item **this_item_addr(THD *thd, Item **);
1875
virtual void print(String *str, enum_query_type query_type);
1878
inline uint get_var_idx() const;
1880
inline enum Type type() const;
1881
inline Item_result result_type() const;
1882
inline enum_field_types field_type() const { return m_field_type; }
1885
bool set_value(THD *thd, sp_rcontext *ctx, Item **it);
1888
Settable_routine_parameter *get_settable_routine_parameter()
1894
/*****************************************************************************
1895
Item_splocal inline implementation.
1896
*****************************************************************************/
1898
inline uint Item_splocal::get_var_idx() const
1903
inline enum Item::Type Item_splocal::type() const
1908
inline Item_result Item_splocal::result_type() const
1910
return m_result_type;
1914
/*****************************************************************************
1915
A reference to case expression in SP, used in runtime.
1916
*****************************************************************************/
1918
class Item_case_expr :public Item_sp_variable
1921
Item_case_expr(uint case_expr_id);
1925
const Item *this_item() const;
1926
Item **this_item_addr(THD *thd, Item **);
1928
inline enum Type type() const;
1929
inline Item_result result_type() const;
1933
NOTE: print() is intended to be used from views and for debug.
1934
Item_case_expr can not occur in views, so here it is only for debug
1937
virtual void print(String *str, enum_query_type query_type);
1940
uint m_case_expr_id;
1943
/*****************************************************************************
1944
Item_case_expr inline implementation.
1945
*****************************************************************************/
1947
inline enum Item::Type Item_case_expr::type() const
1949
return this_item()->type();
1952
inline Item_result Item_case_expr::result_type() const
1954
return this_item()->result_type();
1959
NAME_CONST(given_name, const_value).
1960
This 'function' has all properties of the supplied const_value (which is
1961
assumed to be a literal constant), and the name given_name.
1963
This is used to replace references to SP variables when we write PROCEDURE
1964
statements into the binary log.
1967
Together with Item_splocal and Item::this_item() we can actually extract
1968
common a base of this class and Item_splocal. Maybe it is possible to
1969
extract a common base with class Item_ref, too.
1972
class Item_name_const : public Item
1978
Item_name_const(Item *name_arg, Item *val);
1980
bool fix_fields(THD *, Item **);
1982
enum Type type() const;
1985
String *val_str(String *sp);
1986
my_decimal *val_decimal(my_decimal *);
1987
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
1988
bool get_time(MYSQL_TIME *ltime);
1990
virtual void print(String *str, enum_query_type query_type);
1992
Item_result result_type() const
1994
return value_item->result_type();
1997
type_conversion_status save_in_field(Field *field, bool no_conversions)
1999
return value_item->save_in_field(field, no_conversions);
2002
bool send(Protocol *protocol, String *str)
2004
return value_item->send(protocol, str);
2008
bool agg_item_collations(DTCollation &c, const char *name,
2009
Item **items, uint nitems, uint flags, int item_sep);
2010
bool agg_item_collations_for_comparison(DTCollation &c, const char *name,
2011
Item **items, uint nitems, uint flags);
2012
bool agg_item_set_converter(DTCollation &coll, const char *fname,
2013
Item **args, uint nargs, uint flags, int item_sep);
2014
bool agg_item_charsets(DTCollation &c, const char *name,
2015
Item **items, uint nitems, uint flags, int item_sep);
2017
agg_item_charsets_for_string_result(DTCollation &c, const char *name,
2018
Item **items, uint nitems,
2021
uint flags= MY_COLL_ALLOW_SUPERSET_CONV |
2022
MY_COLL_ALLOW_COERCIBLE_CONV |
2023
MY_COLL_ALLOW_NUMERIC_CONV;
2024
return agg_item_charsets(c, name, items, nitems, flags, item_sep);
2027
agg_item_charsets_for_comparison(DTCollation &c, const char *name,
2028
Item **items, uint nitems,
2031
uint flags= MY_COLL_ALLOW_SUPERSET_CONV |
2032
MY_COLL_ALLOW_COERCIBLE_CONV |
2033
MY_COLL_DISALLOW_NONE;
2034
return agg_item_charsets(c, name, items, nitems, flags, item_sep);
2037
agg_item_charsets_for_string_result_with_comparison(DTCollation &c,
2039
Item **items, uint nitems,
2042
uint flags= MY_COLL_ALLOW_SUPERSET_CONV |
2043
MY_COLL_ALLOW_COERCIBLE_CONV |
2044
MY_COLL_ALLOW_NUMERIC_CONV |
2045
MY_COLL_DISALLOW_NONE;
2046
return agg_item_charsets(c, name, items, nitems, flags, item_sep);
2050
class Item_num: public Item_basic_constant
2053
Item_num() { collation.set_numeric(); } /* Remove gcc warning */
2054
virtual Item_num *neg()= 0;
2055
Item *safe_charset_converter(const CHARSET_INFO *tocs);
2056
bool check_partition_func_processor(uchar *int_arg) { return FALSE;}
2059
#define NO_CACHED_FIELD_INDEX ((uint)(-1))
2061
class st_select_lex;
2062
class Item_ident :public Item
2066
We have to store initial values of db_name, table_name and field_name
2067
to be able to restore them during cleanup() because they can be
2068
updated during fix_fields() to values from Field object and life-time
2069
of those is shorter than life-time of Item_field.
2071
const char *orig_db_name;
2072
const char *orig_table_name;
2073
const char *orig_field_name;
2076
Name_resolution_context *context;
2077
const char *db_name;
2078
const char *table_name;
2079
const char *field_name;
2080
bool alias_name_used; /* true if item was resolved against alias */
2082
Cached value of index for this field in table->field array, used by prep.
2083
stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX
2084
if index value is not known.
2086
uint cached_field_index;
2088
Cached pointer to table which contains this field, used for the same reason
2089
by prep. stmt. too in case then we have not-fully qualified field.
2090
0 - means no cached value.
2092
TABLE_LIST *cached_table;
2093
st_select_lex *depended_from;
2094
Item_ident(Name_resolution_context *context_arg,
2095
const char *db_name_arg, const char *table_name_arg,
2096
const char *field_name_arg);
2097
Item_ident(THD *thd, Item_ident *item);
2098
const char *full_name() const;
2099
virtual void fix_after_pullout(st_select_lex *parent_select,
2100
st_select_lex *removed_select);
2102
bool remove_dependence_processor(uchar * arg);
2103
virtual void print(String *str, enum_query_type query_type);
2104
virtual bool change_context_processor(uchar *cntx)
2105
{ context= (Name_resolution_context *)cntx; return FALSE; }
2106
friend bool insert_fields(THD *thd, Name_resolution_context *context,
2107
const char *db_name,
2108
const char *table_name, List_iterator<Item> *it,
2109
bool any_privileges);
2113
class Item_ident_for_show :public Item
2117
const char *db_name;
2118
const char *table_name;
2120
Item_ident_for_show(Field *par_field, const char *db_arg,
2121
const char *table_name_arg)
2122
:field(par_field), db_name(db_arg), table_name(table_name_arg)
2125
enum Type type() const { return FIELD_ITEM; }
2126
double val_real() { return field->val_real(); }
2127
longlong val_int() { return field->val_int(); }
2128
String *val_str(String *str) { return field->val_str(str); }
2129
my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); }
2130
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
2132
return field->get_date(ltime, fuzzydate);
2134
bool get_time(MYSQL_TIME *ltime)
2136
return field->get_time(ltime);
2138
void make_field(Send_field *tmp_field);
2139
CHARSET_INFO *charset_for_protocol(void) const
2140
{ return (CHARSET_INFO *)field->charset_for_protocol(); }
2147
class Item_field :public Item_ident
2150
void set_field(Field *field);
2152
Field *field,*result_field;
2153
Item_equal *item_equal;
2154
bool no_const_subst;
2156
if any_privileges set to TRUE then here real effective privileges will
2159
uint have_privileges;
2160
/* field need any privileges (for VIEW creation) */
2161
bool any_privileges;
2162
Item_field(Name_resolution_context *context_arg,
2163
const char *db_arg,const char *table_name_arg,
2164
const char *field_name_arg);
2166
Constructor needed to process subquery with temporary tables (see Item).
2167
Notice that it will have no name resolution context.
2169
Item_field(THD *thd, Item_field *item);
2171
Ensures that field, table, and database names will live as long as
2172
Item_field (this is important in prepared statements).
2174
Item_field(THD *thd, Name_resolution_context *context_arg, Field *field);
2176
If this constructor is used, fix_fields() won't work, because
2177
db_name, table_name and column_name are unknown. It's necessary to call
2178
reset_field() before fix_fields() for all fields created this way.
2180
Item_field(Field *field);
2181
enum Type type() const { return FIELD_ITEM; }
2182
bool eq(const Item *item, bool binary_cmp) const;
2185
longlong val_time_temporal();
2186
longlong val_date_temporal();
2187
my_decimal *val_decimal(my_decimal *);
2188
String *val_str(String*);
2189
double val_result();
2190
longlong val_int_result();
2191
longlong val_time_temporal_result();
2192
longlong val_date_temporal_result();
2193
String *str_result(String* tmp);
2194
my_decimal *val_decimal_result(my_decimal *);
2195
bool val_bool_result();
2196
bool is_null_result();
2197
bool send(Protocol *protocol, String *str_arg);
2198
void reset_field(Field *f);
2199
bool fix_fields(THD *, Item **);
2200
void make_field(Send_field *tmp_field);
2201
type_conversion_status save_in_field(Field *field,bool no_conversions);
2202
void save_org_in_field(Field *field);
2203
table_map used_tables() const;
2204
virtual table_map resolved_used_tables() const;
2205
enum Item_result result_type () const
2207
return field->result_type();
2209
enum Item_result numeric_context_result_type() const
2211
return field->numeric_context_result_type();
2213
Item_result cast_to_int_type() const
2215
return field->cast_to_int_type();
2217
enum_field_types field_type() const
2219
return field->type();
2221
enum_monotonicity_info get_monotonicity_info() const
2223
return MONOTONIC_STRICT_INCREASING;
2225
longlong val_int_endpoint(bool left_endp, bool *incl_endp);
2226
Field *get_tmp_table_field() { return result_field; }
2227
Field *tmp_table_field(TABLE *t_arg) { return result_field; }
2228
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
2229
bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate);
2230
bool get_time(MYSQL_TIME *ltime);
2231
bool get_timeval(struct timeval *tm, int *warnings);
2232
bool is_null() { return field->is_null(); }
2233
void update_null_value();
2234
Item *get_tmp_table_item(THD *thd);
2235
bool collect_item_field_processor(uchar * arg);
2236
bool add_field_to_set_processor(uchar * arg);
2237
bool remove_column_from_bitmap(uchar * arg);
2238
bool find_item_in_field_list_processor(uchar *arg);
2239
bool register_field_in_read_map(uchar *arg);
2240
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
2242
Item_equal *find_item_equal(COND_EQUAL *cond_equal);
2243
bool subst_argument_checker(uchar **arg);
2244
Item *equal_fields_propagator(uchar *arg);
2245
bool set_no_const_sub(uchar *arg);
2246
Item *replace_equal_field(uchar *arg);
2247
inline uint32 max_disp_length() { return field->max_display_length(); }
2248
Item_field *field_for_view_update() { return this; }
2249
Item *safe_charset_converter(const CHARSET_INFO *tocs);
2250
int fix_outer_field(THD *thd, Field **field, Item **reference);
2251
virtual Item *update_value_transformer(uchar *select_arg);
2252
virtual bool item_field_by_name_analyzer(uchar **arg);
2253
virtual Item* item_field_by_name_transformer(uchar *arg);
2254
virtual void print(String *str, enum_query_type query_type);
2255
bool is_outer_field() const
2258
return field->table->pos_in_table_list->outer_join ||
2259
field->table->pos_in_table_list->outer_join_nest();
2261
Field::geometry_type get_geometry_type() const
2263
DBUG_ASSERT(field_type() == MYSQL_TYPE_GEOMETRY);
2264
return field->get_geometry_type();
2266
const CHARSET_INFO *charset_for_protocol(void) const
2267
{ return field->charset_for_protocol(); }
2272
fprintf(DBUG_FILE, "<field ");
2275
fprintf(DBUG_FILE, "'%s.%s': ", field->table->alias, field->field_name);
2276
field->dbug_print();
2279
fprintf(DBUG_FILE, "NULL");
2281
fprintf(DBUG_FILE, ", result_field: ");
2284
fprintf(DBUG_FILE, "'%s.%s': ",
2285
result_field->table->alias, result_field->field_name);
2286
result_field->dbug_print();
2289
fprintf(DBUG_FILE, "NULL");
2290
fprintf(DBUG_FILE, ">\n");
2294
/// Pushes the item to select_lex.non_agg_fields() and updates its marker.
2295
bool push_to_non_agg_fields(st_select_lex *select_lex);
2297
friend class Item_default_value;
2298
friend class Item_insert_value;
2299
friend class st_select_lex_unit;
2302
class Item_null :public Item_basic_constant
2306
maybe_null= null_value= TRUE;
2309
collation.set(&my_charset_bin, DERIVATION_IGNORABLE);
2315
item_name= NAME_STRING("NULL");
2317
Item_null(const Name_string &name_par)
2320
item_name= name_par;
2322
enum Type type() const { return NULL_ITEM; }
2323
bool eq(const Item *item, bool binary_cmp) const;
2326
longlong val_time_temporal() { return val_int(); }
2327
longlong val_date_temporal() { return val_int(); }
2328
String *val_str(String *str);
2329
my_decimal *val_decimal(my_decimal *);
2330
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
2334
bool get_time(MYSQL_TIME *ltime)
2338
type_conversion_status save_in_field(Field *field, bool no_conversions);
2339
type_conversion_status save_safe_in_field(Field *field);
2340
bool send(Protocol *protocol, String *str);
2341
enum Item_result result_type () const { return STRING_RESULT; }
2342
enum_field_types field_type() const { return MYSQL_TYPE_NULL; }
2343
bool basic_const_item() const { return 1; }
2344
Item *clone_item() { return new Item_null(item_name); }
2345
bool is_null() { return 1; }
2347
virtual inline void print(String *str, enum_query_type query_type)
2349
str->append(STRING_WITH_LEN("NULL"));
2352
Item *safe_charset_converter(const CHARSET_INFO *tocs);
2353
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
2357
An item representing NULL values for use with ROLLUP.
2359
When grouping WITH ROLLUP, Item_null_result items are created to
2360
represent NULL values in the grouping columns of the ROLLUP rows. To
2361
avoid type problems during execution, these objects are created with
2362
the same field and result types as the fields of the columns they
2365
class Item_null_result :public Item_null
2367
/** Field type for this NULL value */
2368
enum_field_types fld_type;
2369
/** Result type for this NULL value */
2370
Item_result res_type;
2373
Field *result_field;
2374
Item_null_result(enum_field_types fld_type, Item_result res_type)
2375
: Item_null(), fld_type(fld_type), res_type(res_type), result_field(0) {}
2376
bool is_result_field() { return result_field != 0; }
2377
void save_in_result_field(bool no_conversions)
2379
save_in_field(result_field, no_conversions);
2381
bool check_partition_func_processor(uchar *int_arg) {return TRUE;}
2382
enum_field_types field_type() const { return fld_type; }
2383
Item_result result_type() const { return res_type; }
2386
/* Item represents one placeholder ('?') of prepared statement */
2388
class Item_param :public Item,
2389
private Settable_routine_parameter
2391
char cnvbuf[MAX_FIELD_WIDTH];
2396
enum enum_item_param_state
2398
NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE,
2399
STRING_VALUE, TIME_VALUE, LONG_DATA_VALUE,
2404
A buffer for string and long data values. Historically all allocated
2405
values returned from val_str() were treated as eligible to
2406
modification. I. e. in some cases Item_func_concat can append it's
2407
second argument to return value of the first one. Because of that we
2408
can't return the original buffer holding string data from val_str(),
2409
and have to have one buffer for data and another just pointing to
2410
the data. This is the latter one and it's returned from val_str().
2411
Can not be declared inside the union as it's not a POD type.
2413
String str_value_ptr;
2414
my_decimal decimal_value;
2420
Character sets conversion info for string values.
2421
Character sets of client and connection defined at bind time are used
2422
for all conversions, even if one of them is later changed (i.e.
2423
between subsequent calls to mysql_stmt_execute).
2425
struct CONVERSION_INFO
2427
const CHARSET_INFO *character_set_client;
2428
const CHARSET_INFO *character_set_of_placeholder;
2430
This points at character set of connection if conversion
2431
to it is required (i. e. if placeholder typecode is not BLOB).
2432
Otherwise it's equal to character_set_client (to simplify
2433
check in convert_str_value()).
2435
const CHARSET_INFO *final_character_set_of_str_value;
2440
/* Cached values for virtual methods to save us one switch. */
2441
enum Item_result item_result_type;
2442
enum Type item_type;
2445
Used when this item is used in a temporary table.
2446
This is NOT placeholder metadata sent to client, as this value
2447
is assigned after sending metadata (in setup_one_conversion_function).
2448
For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both
2449
in result set and placeholders metadata, no matter what type you will
2450
supply for this placeholder in mysql_stmt_execute.
2452
enum enum_field_types param_type;
2454
Offset of placeholder inside statement text. Used to create
2455
no-placeholders version of this statement for the binary log.
2459
Item_param(uint pos_in_query_arg);
2461
enum Item_result result_type () const { return item_result_type; }
2462
enum Type type() const { return item_type; }
2463
enum_field_types field_type() const { return param_type; }
2467
my_decimal *val_decimal(my_decimal*);
2468
String *val_str(String*);
2469
bool get_time(MYSQL_TIME *tm);
2470
bool get_date(MYSQL_TIME *tm, uint fuzzydate);
2471
type_conversion_status save_in_field(Field *field, bool no_conversions);
2474
void set_int(longlong i, uint32 max_length_arg);
2475
void set_double(double i);
2476
void set_decimal(const char *str, ulong length);
2477
void set_decimal(const my_decimal *dv);
2478
bool set_str(const char *str, ulong length);
2479
bool set_longdata(const char *str, ulong length);
2480
void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg);
2481
bool set_from_user_var(THD *thd, const user_var_entry *entry);
2484
Assign placeholder value from bind data.
2485
Note, that 'len' has different semantics in embedded library (as we
2486
don't need to check that packet is not broken there). See
2487
sql_prepare.cc for details.
2489
void (*set_param_func)(Item_param *param, uchar **pos, ulong len);
2491
const String *query_val_str(THD *thd, String *str) const;
2493
bool convert_str_value(THD *thd);
2496
If value for parameter was not set we treat it as non-const
2497
so noone will use parameters value in fix_fields still
2498
parameter is constant during execution.
2500
virtual table_map used_tables() const
2501
{ return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; }
2502
virtual void print(String *str, enum_query_type query_type);
2504
{ DBUG_ASSERT(state != NO_VALUE); return state == NULL_VALUE; }
2505
bool basic_const_item() const;
2507
This method is used to make a copy of a basic constant item when
2508
propagating constants in the optimizer. The reason to create a new
2509
item and not use the existing one is not precisely known (2005/04/16).
2510
Probably we are trying to preserve tree structure of items, in other
2511
words, avoid pointing at one item from two different nodes of the tree.
2512
Return a new basic constant item if parameter value is a basic
2513
constant, assert otherwise. This method is called only if
2514
basic_const_item returned TRUE.
2516
Item *safe_charset_converter(const CHARSET_INFO *tocs);
2519
Implement by-value equality evaluation if parameter value
2520
is set and is a basic constant (integer, real or string).
2521
Otherwise return FALSE.
2523
bool eq(const Item *item, bool binary_cmp) const;
2524
/** Item is a argument to a limit clause. */
2525
bool limit_clause_param;
2526
void set_param_type_and_swap_value(Item_param *from);
2529
virtual inline Settable_routine_parameter *
2530
get_settable_routine_parameter()
2535
virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it);
2537
virtual void set_out_param_info(Send_field *info);
2540
virtual const Send_field *get_out_param_info() const;
2542
virtual void make_field(Send_field *field);
2545
Send_field *m_out_param_info;
2549
class Item_int :public Item_num
2553
Item_int(int32 i,uint length= MY_INT32_NUM_DECIMAL_DIGITS)
2554
:value((longlong) i)
2555
{ max_length=length; fixed= 1; }
2556
Item_int(longlong i,uint length= MY_INT64_NUM_DECIMAL_DIGITS)
2558
{ max_length=length; fixed= 1; }
2559
Item_int(ulonglong i, uint length= MY_INT64_NUM_DECIMAL_DIGITS)
2561
{ max_length=length; fixed= 1; unsigned_flag= 1; }
2562
Item_int(Item_int *item_arg)
2564
value= item_arg->value;
2565
item_name= item_arg->item_name;
2566
max_length= item_arg->max_length;
2569
Item_int(const Name_string &name_arg, longlong i, uint length) :value(i)
2572
item_name= name_arg;
2575
Item_int(const char *str_arg, uint length);
2576
enum Type type() const { return INT_ITEM; }
2577
enum Item_result result_type () const { return INT_RESULT; }
2578
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
2579
longlong val_int() { DBUG_ASSERT(fixed == 1); return value; }
2580
double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; }
2581
my_decimal *val_decimal(my_decimal *);
2582
String *val_str(String*);
2583
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
2585
return get_date_from_int(ltime, fuzzydate);
2587
bool get_time(MYSQL_TIME *ltime)
2589
return get_time_from_int(ltime);
2591
type_conversion_status save_in_field(Field *field, bool no_conversions);
2592
bool basic_const_item() const { return 1; }
2593
Item *clone_item() { return new Item_int(this); }
2594
virtual void print(String *str, enum_query_type query_type);
2595
Item_num *neg() { value= -value; return this; }
2596
uint decimal_precision() const
2597
{ return (uint)(max_length - MY_TEST(value < 0)); }
2598
bool eq(const Item *, bool binary_cmp) const;
2599
bool check_partition_func_processor(uchar *bool_arg) { return FALSE;}
2604
Item_int with value==0 and length==1
2606
class Item_int_0 :public Item_int
2609
Item_int_0() :Item_int(NAME_STRING("0"), 0, 1) {}
2614
Item_temporal is used to store numeric representation
2615
of time/date/datetime values for queries like:
2617
WHERE datetime_column NOT IN
2618
('2006-04-25 10:00:00','2006-04-25 10:02:00', ...);
2620
and for SHOW/INFORMATION_SCHEMA purposes (see sql_show.cc)
2622
TS-TODO: Can't we use Item_time_literal, Item_date_literal,
2623
TS-TODO: and Item_datetime_literal for this purpose?
2625
class Item_temporal :public Item_int
2627
enum_field_types cached_field_type;
2629
Item_temporal(enum_field_types field_type_arg, longlong i): Item_int(i),
2630
cached_field_type(field_type_arg)
2632
DBUG_ASSERT(is_temporal_type(field_type_arg));
2634
Item_temporal(enum_field_types field_type_arg, const Name_string &name_arg,
2635
longlong i, uint length): Item_int(i),
2636
cached_field_type(field_type_arg)
2638
DBUG_ASSERT(is_temporal_type(field_type_arg));
2640
item_name= name_arg;
2643
Item *clone_item() { return new Item_temporal(field_type(), value); }
2644
type_conversion_status save_in_field(Field *field, bool no_conversions);
2645
longlong val_time_temporal() { return val_int(); }
2646
longlong val_date_temporal() { return val_int(); }
2647
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
2652
bool get_time(MYSQL_TIME *ltime)
2657
enum_field_types field_type() const
2659
return cached_field_type;
2664
class Item_uint :public Item_int
2667
Item_uint(const char *str_arg, uint length)
2668
:Item_int(str_arg, length) { unsigned_flag= 1; }
2669
Item_uint(ulonglong i) :Item_int((ulonglong) i, 10) {}
2670
Item_uint(const Name_string &name_arg, longlong i, uint length)
2671
:Item_int(name_arg, i, length) { unsigned_flag= 1; }
2673
{ DBUG_ASSERT(fixed == 1); return ulonglong2double((ulonglong)value); }
2674
String *val_str(String*);
2676
Item *clone_item() { return new Item_uint(item_name, value, max_length); }
2677
type_conversion_status save_in_field(Field *field, bool no_conversions);
2678
virtual void print(String *str, enum_query_type query_type);
2680
uint decimal_precision() const { return max_length; }
2681
bool check_partition_func_processor(uchar *bool_arg) { return FALSE;}
2685
/* decimal (fixed point) constant */
2686
class Item_decimal :public Item_num
2689
my_decimal decimal_value;
2691
Item_decimal(const char *str_arg, uint length, const CHARSET_INFO *charset);
2692
Item_decimal(const Name_string &name_arg,
2693
const my_decimal *val_arg, uint decimal_par, uint length);
2694
Item_decimal(my_decimal *value_par);
2695
Item_decimal(longlong val, bool unsig);
2696
Item_decimal(double val, int precision, int scale);
2697
Item_decimal(const uchar *bin, int precision, int scale);
2699
enum Type type() const { return DECIMAL_ITEM; }
2700
enum Item_result result_type () const { return DECIMAL_RESULT; }
2701
enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; }
2704
String *val_str(String*);
2705
my_decimal *val_decimal(my_decimal *val) { return &decimal_value; }
2706
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
2708
return get_date_from_decimal(ltime, fuzzydate);
2710
bool get_time(MYSQL_TIME *ltime)
2712
return get_time_from_decimal(ltime);
2714
type_conversion_status save_in_field(Field *field, bool no_conversions);
2715
bool basic_const_item() const { return 1; }
2718
return new Item_decimal(item_name, &decimal_value, decimals, max_length);
2720
virtual void print(String *str, enum_query_type query_type);
2723
my_decimal_neg(&decimal_value);
2724
unsigned_flag= !decimal_value.sign();
2727
uint decimal_precision() const { return decimal_value.precision(); }
2728
bool eq(const Item *, bool binary_cmp) const;
2729
void set_decimal_value(my_decimal *value_par);
2730
bool check_partition_func_processor(uchar *bool_arg) { return FALSE;}
2734
class Item_float :public Item_num
2736
Name_string presentation;
2739
// Item_real() :value(0) {}
2740
Item_float(const char *str_arg, uint length);
2741
Item_float(const Name_string name_arg,
2742
double val_arg, uint decimal_par, uint length)
2745
presentation= name_arg;
2746
item_name= name_arg;
2747
decimals= (uint8) decimal_par;
2751
Item_float(double value_par, uint decimal_par) :value(value_par)
2753
decimals= (uint8) decimal_par;
2756
type_conversion_status save_in_field(Field *field, bool no_conversions);
2757
enum Type type() const { return REAL_ITEM; }
2758
enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; }
2759
double val_real() { DBUG_ASSERT(fixed == 1); return value; }
2762
DBUG_ASSERT(fixed == 1);
2763
if (value <= (double) LONGLONG_MIN)
2765
return LONGLONG_MIN;
2767
else if (value >= (double) (ulonglong) LONGLONG_MAX)
2769
return LONGLONG_MAX;
2771
return (longlong) rint(value);
2773
String *val_str(String*);
2774
my_decimal *val_decimal(my_decimal *);
2775
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
2777
return get_date_from_real(ltime, fuzzydate);
2779
bool get_time(MYSQL_TIME *ltime)
2781
return get_time_from_real(ltime);
2783
bool basic_const_item() const { return 1; }
2785
{ return new Item_float(item_name, value, decimals, max_length); }
2786
Item_num *neg() { value= -value; return this; }
2787
virtual void print(String *str, enum_query_type query_type);
2788
bool eq(const Item *, bool binary_cmp) const;
2792
class Item_static_float_func :public Item_float
2794
const Name_string func_name;
2796
Item_static_float_func(const Name_string &name_arg,
2797
double val_arg, uint decimal_par, uint length)
2798
:Item_float(null_name_string,
2799
val_arg, decimal_par, length), func_name(name_arg)
2802
virtual inline void print(String *str, enum_query_type query_type)
2804
str->append(func_name);
2807
Item *safe_charset_converter(const CHARSET_INFO *tocs);
2811
class Item_string :public Item_basic_constant
2814
/* Create from a string, set name from the string itself. */
2815
Item_string(const char *str,uint length,
2816
const CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
2817
uint repertoire= MY_REPERTOIRE_UNICODE30)
2818
: m_cs_specified(FALSE)
2820
str_value.set_or_copy_aligned(str, length, cs);
2821
collation.set(cs, dv, repertoire);
2823
We have to have a different max_length than 'length' here to
2824
ensure that we get the right length if we do use the item
2825
to create a new table. In this case max_length must be the maximum
2826
number of chars for a string of this type because we in Create_field::
2827
divide the max_length with mbmaxlen).
2829
max_length= str_value.numchars()*cs->mbmaxlen;
2830
item_name.copy(str, length, cs);
2831
decimals=NOT_FIXED_DEC;
2832
// it is constant => can be used without fix_fields (and frequently used)
2835
/* Just create an item and do not fill string representation */
2836
Item_string(const CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE)
2837
: m_cs_specified(FALSE)
2839
collation.set(cs, dv);
2841
decimals= NOT_FIXED_DEC;
2844
/* Create from the given name and string. */
2845
Item_string(const Name_string name_par, const char *str, uint length,
2846
const CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE,
2847
uint repertoire= MY_REPERTOIRE_UNICODE30)
2848
: m_cs_specified(FALSE)
2850
str_value.set_or_copy_aligned(str, length, cs);
2851
collation.set(cs, dv, repertoire);
2852
max_length= str_value.numchars()*cs->mbmaxlen;
2853
item_name= name_par;
2854
decimals=NOT_FIXED_DEC;
2855
// it is constant => can be used without fix_fields (and frequently used)
2859
This is used in stored procedures to avoid memory leaks and
2860
does a deep copy of its argument.
2862
void set_str_with_copy(const char *str_arg, uint length_arg)
2864
str_value.copy(str_arg, length_arg, collation.collation);
2865
max_length= str_value.numchars() * collation.collation->mbmaxlen;
2867
void set_repertoire_from_value()
2869
collation.repertoire= my_string_repertoire(str_value.charset(),
2871
str_value.length());
2873
enum Type type() const { return STRING_ITEM; }
2876
String *val_str(String*)
2878
DBUG_ASSERT(fixed == 1);
2879
return (String*) &str_value;
2881
my_decimal *val_decimal(my_decimal *);
2882
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
2884
return get_date_from_string(ltime, fuzzydate);
2886
bool get_time(MYSQL_TIME *ltime)
2888
return get_time_from_string(ltime);
2890
type_conversion_status save_in_field(Field *field, bool no_conversions);
2891
enum Item_result result_type () const { return STRING_RESULT; }
2892
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
2893
bool basic_const_item() const { return 1; }
2894
bool eq(const Item *item, bool binary_cmp) const;
2897
return new Item_string(static_cast<Name_string>(item_name), str_value.ptr(),
2898
str_value.length(), collation.collation);
2900
Item *safe_charset_converter(const CHARSET_INFO *tocs);
2901
Item *charset_converter(const CHARSET_INFO *tocs, bool lossless);
2902
inline void append(char *str, uint length)
2904
str_value.append(str, length);
2905
max_length= str_value.numchars() * collation.collation->mbmaxlen;
2907
virtual void print(String *str, enum_query_type query_type);
2908
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
2911
Return TRUE if character-set-introducer was explicitly specified in the
2912
original query for this item (text literal).
2914
This operation is to be called from Item_string::print(). The idea is
2915
that when a query is generated (re-constructed) from the Item-tree,
2916
character-set-introducers should appear only for those literals, where
2917
they were explicitly specified by the user. Otherwise, that may lead to
2918
loss collation information (character set introducers implies default
2919
collation for the literal).
2921
Basically, that makes sense only for views and hopefully will be gone
2922
one day when we start using original query as a view definition.
2924
@return This operation returns the value of m_cs_specified attribute.
2925
@retval TRUE if character set introducer was explicitly specified in
2927
@retval FALSE otherwise.
2929
inline bool is_cs_specified() const
2931
return m_cs_specified;
2935
Set the value of m_cs_specified attribute.
2937
m_cs_specified attribute shows whether character-set-introducer was
2938
explicitly specified in the original query for this text literal or
2939
not. The attribute makes sense (is used) only for views.
2941
This operation is to be called from the parser during parsing an input
2944
inline void set_cs_specified(bool cs_specified)
2946
m_cs_specified= cs_specified;
2950
bool m_cs_specified;
2955
longlong_from_string_with_check (const CHARSET_INFO *cs,
2956
const char *cptr, char *end);
2958
double_from_string_with_check (const CHARSET_INFO *cs,
2959
const char *cptr, char *end);
2961
class Item_static_string_func :public Item_string
2963
const Name_string func_name;
2965
Item_static_string_func(const Name_string &name_par,
2966
const char *str, uint length, const CHARSET_INFO *cs,
2967
Derivation dv= DERIVATION_COERCIBLE)
2968
:Item_string(null_name_string, str, length, cs, dv), func_name(name_par)
2970
Item *safe_charset_converter(const CHARSET_INFO *tocs);
2972
virtual inline void print(String *str, enum_query_type query_type)
2974
str->append(func_name);
2977
bool check_partition_func_processor(uchar *int_arg) {return TRUE;}
2981
/* for show tables */
2982
class Item_partition_func_safe_string: public Item_string
2985
Item_partition_func_safe_string(const Name_string name, uint length,
2986
const CHARSET_INFO *cs= NULL):
2987
Item_string(name, NullS, 0, cs)
2994
class Item_blob :public Item_partition_func_safe_string
2997
Item_blob(const char *name, uint length) :
2998
Item_partition_func_safe_string(Name_string(name, strlen(name)),
2999
length, &my_charset_bin)
3001
enum Type type() const { return TYPE_HOLDER; }
3002
enum_field_types field_type() const { return MYSQL_TYPE_BLOB; }
3007
Item_empty_string -- is a utility class to put an item into List<Item>
3008
which is then used in protocol.send_result_set_metadata() when sending SHOW output to
3012
class Item_empty_string :public Item_partition_func_safe_string
3015
Item_empty_string(const char *header, uint length,
3016
const CHARSET_INFO *cs= NULL) :
3017
Item_partition_func_safe_string(Name_string(header, strlen(header)),
3018
0, cs ? cs : &my_charset_utf8_general_ci)
3020
max_length= length * collation.collation->mbmaxlen;
3022
void make_field(Send_field *field);
3026
class Item_return_int :public Item_int
3028
enum_field_types int_field_type;
3030
Item_return_int(const char *name_arg, uint length,
3031
enum_field_types field_type_arg, longlong value= 0)
3032
:Item_int(Name_string(name_arg, name_arg ? strlen(name_arg) : 0),
3033
value, length), int_field_type(field_type_arg)
3037
enum_field_types field_type() const { return int_field_type; }
3041
class Item_hex_string: public Item_basic_constant
3045
Item_hex_string(const char *str,uint str_length);
3046
enum Type type() const { return VARBIN_ITEM; }
3049
DBUG_ASSERT(fixed == 1);
3050
return (double) (ulonglong) Item_hex_string::val_int();
3053
bool basic_const_item() const { return 1; }
3054
String *val_str(String*) { DBUG_ASSERT(fixed == 1); return &str_value; }
3055
my_decimal *val_decimal(my_decimal *);
3056
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
3058
return get_date_from_string(ltime, fuzzydate);
3060
bool get_time(MYSQL_TIME *ltime)
3062
return get_time_from_string(ltime);
3064
type_conversion_status save_in_field(Field *field, bool no_conversions);
3065
enum Item_result result_type () const { return STRING_RESULT; }
3066
enum Item_result cast_to_int_type() const { return INT_RESULT; }
3067
enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; }
3068
virtual void print(String *str, enum_query_type query_type);
3069
bool eq(const Item *item, bool binary_cmp) const;
3070
virtual Item *safe_charset_converter(const CHARSET_INFO *tocs);
3071
bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
3073
void hex_string_init(const char *str, uint str_length);
3077
class Item_bin_string: public Item_hex_string
3080
Item_bin_string(const char *str,uint str_length);
3083
class Item_result_field :public Item /* Item with result field */
3086
Field *result_field; /* Save result here */
3087
Item_result_field() :result_field(0) {}
3088
// Constructor used for Item_sum/Item_cond_and/or (see Item comment)
3089
Item_result_field(THD *thd, Item_result_field *item):
3090
Item(thd, item), result_field(item->result_field)
3092
~Item_result_field() {} /* Required with gcc 2.95 */
3093
Field *get_tmp_table_field() { return result_field; }
3094
Field *tmp_table_field(TABLE *t_arg) { return result_field; }
3095
table_map used_tables() const { return 1; }
3096
virtual void fix_length_and_dec()=0;
3097
void set_result_field(Field *field) { result_field= field; }
3098
bool is_result_field() { return 1; }
3099
void save_in_result_field(bool no_conversions)
3101
save_in_field(result_field, no_conversions);
3105
This method is used for debug purposes to print the name of an
3106
item to the debug log. The second use of this method is as
3107
a helper function of print() and error messages, where it is
3108
applicable. To suit both goals it should return a meaningful,
3109
distinguishable and sintactically correct string. This method
3110
should not be used for runtime type identification, use enum
3111
{Sum}Functype and Item_func::functype()/Item_sum::sum_func()
3113
Added here, to the parent class of both Item_func and Item_sum_func.
3115
NOTE: for Items inherited from Item_sum, func_name() return part of
3116
function name till first argument (including '(') to make difference in
3117
names for functions with 'distinct' clause and without 'distinct' and
3118
also to make printing of items inherited from Item_sum uniform.
3120
virtual const char *func_name() const= 0;
3124
class Item_ref :public Item_ident
3127
void set_properties();
3129
enum Ref_Type { REF, DIRECT_REF, VIEW_REF, OUTER_REF, AGGREGATE_REF };
3130
Field *result_field; /* Save result here */
3132
Item_ref(Name_resolution_context *context_arg,
3133
const char *db_arg, const char *table_name_arg,
3134
const char *field_name_arg)
3135
:Item_ident(context_arg, db_arg, table_name_arg, field_name_arg),
3136
result_field(0), ref(0) {}
3138
This constructor is used in two scenarios:
3140
No initialization is performed, fix_fields() call will be necessary.
3142
B) *item points to an Item this Item_ref will refer to. This is
3143
used for GROUP BY. fix_fields() will not be called in this case,
3144
so we call set_properties to make this item "fixed". set_properties
3145
performs a subset of action Item_ref::fix_fields does, and this subset
3146
is enough for Item_ref's used in GROUP BY.
3148
TODO we probably fix a superset of problems like in BUG#6658. Check this
3149
with Bar, and if we have a more broader set of problems like this.
3151
Item_ref(Name_resolution_context *context_arg, Item **item,
3152
const char *table_name_arg, const char *field_name_arg,
3153
bool alias_name_used_arg= FALSE);
3155
/* Constructor need to process subselect with temporary tables (see Item) */
3156
Item_ref(THD *thd, Item_ref *item)
3157
:Item_ident(thd, item), result_field(item->result_field), ref(item->ref) {}
3158
enum Type type() const { return REF_ITEM; }
3159
bool eq(const Item *item, bool binary_cmp) const
3161
Item *it= ((Item *) item)->real_item();
3162
return ref && (*ref)->eq(it, binary_cmp);
3166
longlong val_time_temporal();
3167
longlong val_date_temporal();
3168
my_decimal *val_decimal(my_decimal *);
3170
String *val_str(String* tmp);
3172
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
3173
double val_result();
3174
longlong val_int_result();
3175
String *str_result(String* tmp);
3176
my_decimal *val_decimal_result(my_decimal *);
3177
bool val_bool_result();
3178
bool is_null_result();
3179
bool send(Protocol *prot, String *tmp);
3180
void make_field(Send_field *field);
3181
bool fix_fields(THD *, Item **);
3182
void fix_after_pullout(st_select_lex *parent_select,
3183
st_select_lex *removed_select);
3184
type_conversion_status save_in_field(Field *field, bool no_conversions);
3185
void save_org_in_field(Field *field);
3186
enum Item_result result_type () const { return (*ref)->result_type(); }
3187
enum_field_types field_type() const { return (*ref)->field_type(); }
3188
Field *get_tmp_table_field()
3189
{ return result_field ? result_field : (*ref)->get_tmp_table_field(); }
3190
Item *get_tmp_table_item(THD *thd);
3191
bool const_item() const
3193
return (*ref)->const_item() && (used_tables() == 0);
3195
table_map used_tables() const
3197
return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
3199
void update_used_tables()
3202
(*ref)->update_used_tables();
3205
virtual table_map resolved_used_tables() const
3206
{ return (*ref)->resolved_used_tables(); }
3208
table_map not_null_tables() const
3211
It can happen that our 'depended_from' member is set but the
3212
'depended_from' member of the referenced item is not (example: if a
3213
field in a subquery belongs to an outer merged view), so we first test
3216
return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->not_null_tables();
3218
void set_result_field(Field *field) { result_field= field; }
3219
bool is_result_field() { return 1; }
3220
void save_in_result_field(bool no_conversions)
3222
(*ref)->save_in_field(result_field, no_conversions);
3226
return ref ? (*ref)->real_item() : this;
3228
bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
3230
return (*ref)->walk(processor, walk_subquery, arg) ||
3231
(this->*processor)(arg);
3233
virtual Item* transform(Item_transformer, uchar *arg);
3234
virtual Item* compile(Item_analyzer analyzer, uchar **arg_p,
3235
Item_transformer transformer, uchar *arg_t);
3236
virtual bool explain_subquery_checker(uchar **arg)
3239
Always return false: we don't need to go deeper into referenced
3240
expression tree since we have to mark aliased subqueries at
3241
their original places (select list, derived tables), not by
3242
references from other expression (order by etc).
3246
virtual void print(String *str, enum_query_type query_type);
3248
Item_field *field_for_view_update()
3249
{ return (*ref)->field_for_view_update(); }
3250
virtual Ref_Type ref_type() { return REF; }
3252
// Row emulation: forwarding of ROW-related calls to ref
3255
return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
3257
Item* element_index(uint i)
3259
return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
3263
return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
3265
bool check_cols(uint c)
3267
return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
3268
: Item::check_cols(c);
3272
return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
3276
if (ref && result_type() == ROW_RESULT)
3277
(*ref)->bring_value();
3279
bool get_time(MYSQL_TIME *ltime)
3282
return (*ref)->get_time(ltime);
3284
virtual bool basic_const_item() const { return ref && (*ref)->basic_const_item(); }
3285
bool is_outer_field() const
3289
return (*ref)->is_outer_field();
3293
Checks if the item tree that ref points to contains a subquery.
3295
virtual bool has_subquery() const
3298
return (*ref)->has_subquery();
3302
Checks if the item tree that ref points to contains a stored program.
3304
virtual bool has_stored_program() const
3307
return (*ref)->has_stored_program();
3310
virtual bool created_by_in2exists() const
3312
return (*ref)->created_by_in2exists();
3318
The same as Item_ref, but get value from val_* family of method to get
3319
value of item on which it referred instead of result* family.
3321
class Item_direct_ref :public Item_ref
3324
Item_direct_ref(Name_resolution_context *context_arg, Item **item,
3325
const char *table_name_arg,
3326
const char *field_name_arg,
3327
bool alias_name_used_arg= FALSE)
3328
:Item_ref(context_arg, item, table_name_arg,
3329
field_name_arg, alias_name_used_arg)
3331
/* Constructor need to process subselect with temporary tables (see Item) */
3332
Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
3336
longlong val_time_temporal();
3337
longlong val_date_temporal();
3338
String *val_str(String* tmp);
3339
my_decimal *val_decimal(my_decimal *);
3342
bool get_date(MYSQL_TIME *ltime,uint fuzzydate);
3343
virtual Ref_Type ref_type() { return DIRECT_REF; }
3347
Class for view fields, the same as Item_direct_ref, but call fix_fields
3348
of reference if it is not called yet
3350
class Item_direct_view_ref :public Item_direct_ref
3353
Item_direct_view_ref(Name_resolution_context *context_arg,
3355
const char *alias_name_arg,
3356
const char *table_name_arg,
3357
const char *field_name_arg)
3358
: Item_direct_ref(context_arg, item, alias_name_arg, field_name_arg)
3360
orig_table_name= table_name_arg;
3363
/* Constructor need to process subselect with temporary tables (see Item) */
3364
Item_direct_view_ref(THD *thd, Item_direct_ref *item)
3365
:Item_direct_ref(thd, item) {}
3368
We share one underlying Item_field, so we have to disable
3369
build_equal_items_for_cond().
3370
TODO: Implement multiple equality optimization for views.
3372
virtual bool subst_argument_checker(uchar **arg)
3377
bool fix_fields(THD *, Item **);
3378
bool eq(const Item *item, bool binary_cmp) const;
3379
Item *get_tmp_table_item(THD *thd)
3381
Item *item= Item_ref::get_tmp_table_item(thd);
3382
item->item_name= item_name;
3385
virtual Ref_Type ref_type() { return VIEW_REF; }
3390
Class for outer fields.
3391
An object of this class is created when the select where the outer field was
3392
resolved is a grouping one. After it has been fixed the ref field will point
3393
to either an Item_ref or an Item_direct_ref object which will be used to
3395
The ref field may also point to an Item_field instance.
3396
See also comments for the fix_inner_refs() and the
3397
Item_field::fix_outer_field() functions.
3401
class Item_outer_ref :public Item_direct_ref
3405
/* The aggregate function under which this outer ref is used, if any. */
3406
Item_sum *in_sum_func;
3408
TRUE <=> that the outer_ref is already present in the select list
3409
of the outer select.
3411
bool found_in_select_list;
3412
Item_outer_ref(Name_resolution_context *context_arg,
3413
Item_field *outer_field_arg)
3414
:Item_direct_ref(context_arg, 0, outer_field_arg->table_name,
3415
outer_field_arg->field_name),
3416
outer_ref(outer_field_arg), in_sum_func(0),
3417
found_in_select_list(0)
3423
Item_outer_ref(Name_resolution_context *context_arg, Item **item,
3424
const char *table_name_arg, const char *field_name_arg,
3425
bool alias_name_used_arg)
3426
:Item_direct_ref(context_arg, item, table_name_arg, field_name_arg,
3427
alias_name_used_arg),
3428
outer_ref(0), in_sum_func(0), found_in_select_list(1)
3430
void save_in_result_field(bool no_conversions)
3432
outer_ref->save_org_in_field(result_field);
3434
bool fix_fields(THD *, Item **);
3435
void fix_after_pullout(st_select_lex *parent_select,
3436
st_select_lex *removed_select);
3437
table_map used_tables() const
3439
return (*ref)->const_item() ? 0 : OUTER_REF_TABLE_BIT;
3441
table_map not_null_tables() const { return 0; }
3443
virtual Ref_Type ref_type() { return OUTER_REF; }
3447
class Item_in_subselect;
3451
An object of this class:
3452
- Converts val_XXX() calls to ref->val_XXX_result() calls, like Item_ref.
3453
- Sets owner->was_null=TRUE if it has returned a NULL value from any
3454
val_XXX() function. This allows to inject an Item_ref_null_helper
3455
object into subquery and then check if the subquery has produced a row
3459
class Item_ref_null_helper: public Item_ref
3462
Item_in_subselect* owner;
3464
Item_ref_null_helper(Name_resolution_context *context_arg,
3465
Item_in_subselect* master, Item **item,
3466
const char *table_name_arg, const char *field_name_arg)
3467
:Item_ref(context_arg, item, table_name_arg, field_name_arg),
3471
longlong val_time_temporal();
3472
longlong val_date_temporal();
3473
String* val_str(String* s);
3474
my_decimal *val_decimal(my_decimal *);
3476
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
3477
virtual void print(String *str, enum_query_type query_type);
3479
we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
3481
table_map used_tables() const
3483
return (depended_from ?
3484
OUTER_REF_TABLE_BIT :
3485
(*ref)->used_tables() | RAND_TABLE_BIT);
3490
The following class is used to optimize comparing of bigint columns.
3491
We need to save the original item ('ref') to be able to call
3492
ref->save_in_field(). This is used to create index search keys.
3494
An instance of Item_int_with_ref may have signed or unsigned integer value.
3498
class Item_int_with_ref :public Item_int
3503
Item_int_with_ref(longlong i, Item *ref_arg, my_bool unsigned_arg) :
3504
Item_int(i), ref(ref_arg)
3506
unsigned_flag= unsigned_arg;
3508
type_conversion_status save_in_field(Field *field, bool no_conversions)
3510
return ref->save_in_field(field, no_conversions);
3513
virtual Item *real_item() { return ref; }
3518
Similar to Item_int_with_ref, but to optimize comparing of temporal columns.
3520
class Item_temporal_with_ref :public Item_int_with_ref
3523
enum_field_types cached_field_type;
3525
Item_temporal_with_ref(enum_field_types field_type_arg,
3526
uint8 decimals_arg, longlong i, Item *ref_arg,
3527
bool unsigned_flag):
3528
Item_int_with_ref(i, ref_arg, unsigned_flag),
3529
cached_field_type(field_type_arg)
3531
decimals= decimals_arg;
3533
enum_field_types field_type() const { return cached_field_type; }
3534
void print(String *str, enum_query_type query_type);
3535
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
3540
bool get_time(MYSQL_TIME *ltime)
3550
Item_datetime_with_ref is used to optimize queries like:
3551
SELECT ... FROM t1 WHERE date_or_datetime_column = 20110101101010;
3552
The numeric constant is replaced to Item_datetime_with_ref
3553
by convert_constant_item().
3555
class Item_datetime_with_ref :public Item_temporal_with_ref
3558
enum_field_types cached_field_type;
3561
Constructor for Item_datetime_with_ref.
3562
@param field_type_arg Data type: MYSQL_TYPE_DATE or MYSQL_TYPE_DATETIME
3563
@param decimals_arg Number of fractional digits.
3564
@param i Temporal value in packed format.
3565
@param ref_arg Pointer to the original numeric Item.
3567
Item_datetime_with_ref(enum_field_types field_type_arg,
3568
uint8 decimals_arg, longlong i, Item *ref_arg):
3569
Item_temporal_with_ref(field_type_arg, decimals_arg, i, ref_arg, true),
3570
cached_field_type(field_type_arg)
3574
longlong val_date_temporal() { return val_int(); }
3575
longlong val_time_temporal()
3584
Item_time_with_ref is used to optimize queries like:
3585
SELECT ... FROM t1 WHERE time_column = 20110101101010;
3586
The numeric constant is replaced to Item_time_with_ref
3587
by convert_constant_item().
3589
class Item_time_with_ref :public Item_temporal_with_ref
3593
Constructor for Item_time_with_ref.
3594
@param decimals_arg Number of fractional digits.
3595
@param i Temporal value in packed format.
3596
@param ref_arg Pointer to the original numeric Item.
3598
Item_time_with_ref(uint8 decimals_arg, longlong i, Item *ref_arg):
3599
Item_temporal_with_ref(MYSQL_TYPE_TIME, decimals_arg, i, ref_arg, 0)
3603
longlong val_time_temporal() { return val_int(); }
3604
longlong val_date_temporal()
3613
#include "gstream.h"
3614
#include "spatial.h"
3615
#include "item_sum.h"
3616
#include "item_func.h"
3617
#include "item_row.h"
3618
#include "item_cmpfunc.h"
3619
#include "item_strfunc.h"
3620
#include "item_geofunc.h"
3621
#include "item_timefunc.h"
3622
#include "item_subselect.h"
3623
#include "item_xmlfunc.h"
3624
#include "item_create.h"
3628
Base class to implement typed value caching Item classes
3630
Item_copy_ classes are very similar to the corresponding Item_
3631
classes (e.g. Item_copy_int is similar to Item_int) but they add
3632
the following additional functionality to Item_ :
3634
2. Possibility to store the value not only on instantiation time,
3636
Item_copy_ classes are a functionality subset of Item_cache_
3637
classes, as e.g. they don't support comparisons with the original Item
3638
as Item_cache_ classes do.
3639
Item_copy_ classes are used in GROUP BY calculation.
3640
TODO: Item_copy should be made an abstract interface and Item_copy_
3641
classes should inherit both the respective Item_ class and the interface.
3642
Ideally we should drop Item_copy_ classes altogether and merge
3643
their functionality to Item_cache_ (and these should be made to inherit
3647
class Item_copy :public Item
3652
Stores the type of the resulting field that would be used to store the data
3653
in the cache. This is to avoid calls to the original item.
3655
enum enum_field_types cached_field_type;
3657
/** The original item that is copied */
3661
Stores the result type of the original item, so it can be returned
3662
without calling the original item's method
3664
Item_result cached_result_type;
3667
Constructor of the Item_copy class
3669
stores metadata information about the original class as well as a
3675
null_value=maybe_null=item->maybe_null;
3676
decimals=item->decimals;
3677
max_length=item->max_length;
3678
item_name= item->item_name;
3679
cached_field_type= item->field_type();
3680
cached_result_type= item->result_type();
3681
unsigned_flag= item->unsigned_flag;
3683
collation.set(item->collation);
3688
Factory method to create the appropriate subclass dependent on the type of
3691
@param item the original item.
3693
static Item_copy *create (Item *item);
3696
Update the cache with the value of the original item
3698
This is the method that updates the cached value.
3699
It must be explicitly called by the user of this class to store the value
3700
of the orginal item in the cache.
3702
virtual void copy() = 0;
3704
Item *get_item() { return item; }
3705
/** All of the subclasses should have the same type tag */
3706
enum Type type() const { return COPY_STR_ITEM; }
3707
enum_field_types field_type() const { return cached_field_type; }
3708
enum Item_result result_type () const { return cached_result_type; }
3710
void make_field(Send_field *field) { item->make_field(field); }
3711
table_map used_tables() const { return (table_map) 1L; }
3712
bool const_item() const { return 0; }
3713
bool is_null() { return null_value; }
3715
virtual void no_rows_in_result()
3717
item->no_rows_in_result();
3721
Override the methods below as pure virtual to make sure all the
3722
sub-classes implement them.
3725
virtual String *val_str(String*) = 0;
3726
virtual my_decimal *val_decimal(my_decimal *) = 0;
3727
virtual double val_real() = 0;
3728
virtual longlong val_int() = 0;
3729
virtual bool get_date(MYSQL_TIME *ltime, uint fuzzydate)= 0;
3730
virtual bool get_time(MYSQL_TIME *ltime)= 0;
3731
virtual type_conversion_status save_in_field(Field *field,
3732
bool no_conversions) = 0;
3736
Implementation of a string cache.
3738
Uses Item::str_value for storage
3740
class Item_copy_string : public Item_copy
3743
Item_copy_string (Item *item) : Item_copy(item) {}
3745
String *val_str(String*);
3746
my_decimal *val_decimal(my_decimal *);
3749
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
3750
bool get_time(MYSQL_TIME *ltime);
3752
type_conversion_status save_in_field(Field *field, bool no_conversions);
3756
class Item_copy_int : public Item_copy
3759
longlong cached_value;
3761
Item_copy_int (Item *i) : Item_copy(i) {}
3762
type_conversion_status save_in_field(Field *field, bool no_conversions);
3764
virtual String *val_str(String*);
3765
virtual my_decimal *val_decimal(my_decimal *);
3766
virtual double val_real()
3768
return null_value ? 0.0 : (double) cached_value;
3770
virtual longlong val_int()
3772
return null_value ? LL(0) : cached_value;
3774
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
3776
return get_date_from_int(ltime, fuzzydate);
3778
bool get_time(MYSQL_TIME *ltime)
3780
return get_time_from_int(ltime);
3782
virtual void copy();
3786
class Item_copy_uint : public Item_copy_int
3789
Item_copy_uint (Item *item) : Item_copy_int(item)
3794
String *val_str(String*);
3797
return null_value ? 0.0 : (double) (ulonglong) cached_value;
3802
class Item_copy_float : public Item_copy
3805
double cached_value;
3807
Item_copy_float (Item *i) : Item_copy(i) {}
3808
type_conversion_status save_in_field(Field *field, bool no_conversions);
3810
String *val_str(String*);
3811
my_decimal *val_decimal(my_decimal *);
3814
return null_value ? 0.0 : cached_value;
3818
return (longlong) rint(val_real());
3820
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
3822
return get_date_from_real(ltime, fuzzydate);
3824
bool get_time(MYSQL_TIME *ltime)
3826
return get_time_from_real(ltime);
3830
cached_value= item->val_real();
3831
null_value= item->null_value;
3836
class Item_copy_decimal : public Item_copy
3839
my_decimal cached_value;
3841
Item_copy_decimal (Item *i) : Item_copy(i) {}
3842
type_conversion_status save_in_field(Field *field, bool no_conversions);
3844
String *val_str(String*);
3845
my_decimal *val_decimal(my_decimal *)
3847
return null_value ? NULL: &cached_value;
3851
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
3853
return get_date_from_decimal(ltime, fuzzydate);
3855
bool get_time(MYSQL_TIME *ltime)
3857
return get_time_from_decimal(ltime);
3863
class Cached_item :public Sql_alloc
3867
Cached_item() :null_value(0) {}
3868
virtual bool cmp(void)=0;
3869
virtual ~Cached_item(); /*line -e1509 */
3872
class Cached_item_str :public Cached_item
3875
uint32 value_max_length;
3876
String value,tmp_value;
3878
Cached_item_str(THD *thd, Item *arg);
3880
~Cached_item_str(); // Deallocate String:s
3884
class Cached_item_real :public Cached_item
3889
Cached_item_real(Item *item_par) :item(item_par),value(0.0) {}
3893
class Cached_item_int :public Cached_item
3898
Cached_item_int(Item *item_par) :item(item_par),value(0) {}
3902
class Cached_item_temporal :public Cached_item
3907
Cached_item_temporal(Item *item_par) :item(item_par), value(0) {}
3912
class Cached_item_decimal :public Cached_item
3917
Cached_item_decimal(Item *item_par);
3921
class Cached_item_field :public Cached_item
3932
org_ptr= field->ptr;
3933
fprintf(DBUG_FILE, "new: ");
3934
field->dbug_print();
3936
fprintf(DBUG_FILE, ", old: ");
3937
field->dbug_print();
3938
field->ptr= org_ptr;
3939
fprintf(DBUG_FILE, "\n");
3942
Cached_item_field(Field *arg_field) : field(arg_field)
3945
/* TODO: take the memory allocation below out of the constructor. */
3946
buff= (uchar*) sql_calloc(length=field->pack_length());
3951
class Item_default_value : public Item_field
3955
Item_default_value(Name_resolution_context *context_arg)
3956
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
3957
(const char *)NULL),
3959
Item_default_value(Name_resolution_context *context_arg, Item *a)
3960
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
3961
(const char *)NULL),
3963
enum Type type() const { return DEFAULT_VALUE_ITEM; }
3964
bool eq(const Item *item, bool binary_cmp) const;
3965
bool fix_fields(THD *, Item **);
3966
virtual void print(String *str, enum_query_type query_type);
3967
type_conversion_status save_in_field(Field *field_arg, bool no_conversions);
3968
table_map used_tables() const { return (table_map)0L; }
3969
Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
3971
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
3973
if (arg && arg->walk(processor, walk_subquery, args))
3976
return (this->*processor)(args);
3979
Item *transform(Item_transformer transformer, uchar *args);
3983
Item_insert_value -- an implementation of VALUES() function.
3984
You can use the VALUES(col_name) function in the UPDATE clause
3985
to refer to column values from the INSERT portion of the INSERT
3986
... UPDATE statement. In other words, VALUES(col_name) in the
3987
UPDATE clause refers to the value of col_name that would be
3988
inserted, had no duplicate-key conflict occurred.
3989
In all other places this function returns NULL.
3992
class Item_insert_value : public Item_field
3996
Item_insert_value(Name_resolution_context *context_arg, Item *a)
3997
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
3998
(const char *)NULL),
4000
bool eq(const Item *item, bool binary_cmp) const;
4001
bool fix_fields(THD *, Item **);
4002
virtual void print(String *str, enum_query_type query_type);
4003
type_conversion_status save_in_field(Field *field_arg, bool no_conversions)
4005
return Item_field::save_in_field(field_arg, no_conversions);
4008
We use RAND_TABLE_BIT to prevent Item_insert_value from
4009
being treated as a constant and precalculated before execution
4011
table_map used_tables() const { return RAND_TABLE_BIT; }
4013
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
4015
return arg->walk(processor, walk_subquery, args) ||
4016
(this->*processor)(args);
4021
class Table_triggers_list;
4024
Represents NEW/OLD version of field of row which is
4025
changed/read in trigger.
4027
Note: For this item main part of actual binding to Field object happens
4028
not during fix_fields() call (like for Item_field) but right after
4029
parsing of trigger definition, when table is opened, with special
4030
setup_field() call. On fix_fields() stage we simply choose one of
4031
two Field instances representing either OLD or NEW version of this
4034
class Item_trigger_field : public Item_field,
4035
private Settable_routine_parameter
4038
/* Is this item represents row from NEW or OLD row ? */
4039
enum row_version_type {OLD_ROW, NEW_ROW};
4040
row_version_type row_version;
4041
/* Next in list of all Item_trigger_field's in trigger */
4042
Item_trigger_field *next_trg_field;
4043
/* Index of the field in the TABLE::field array */
4045
/* Pointer to Table_trigger_list object for table of this trigger */
4046
Table_triggers_list *triggers;
4048
Item_trigger_field(Name_resolution_context *context_arg,
4049
row_version_type row_ver_arg,
4050
const char *field_name_arg,
4051
ulong priv, const bool ro)
4052
:Item_field(context_arg,
4053
(const char *)NULL, (const char *)NULL, field_name_arg),
4054
row_version(row_ver_arg), field_idx((uint)-1), original_privilege(priv),
4055
want_privilege(priv), table_grants(NULL), read_only (ro)
4057
void setup_field(THD *thd, TABLE *table, GRANT_INFO *table_grant_info);
4058
enum Type type() const { return TRIGGER_FIELD_ITEM; }
4059
bool eq(const Item *item, bool binary_cmp) const;
4060
bool fix_fields(THD *, Item **);
4061
virtual void print(String *str, enum_query_type query_type);
4062
table_map used_tables() const { return (table_map)0L; }
4063
Field *get_tmp_table_field() { return 0; }
4064
Item *copy_or_same(THD *thd) { return this; }
4065
Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
4069
void set_required_privilege(bool rw);
4070
bool set_value(THD *thd, sp_rcontext *ctx, Item **it);
4073
Settable_routine_parameter *get_settable_routine_parameter()
4075
return (read_only ? 0 : this);
4078
bool set_value(THD *thd, Item **it)
4080
return set_value(thd, NULL, it);
4085
'want_privilege' holds privileges required to perform operation on
4086
this trigger field (SELECT_ACL if we are going to read it and
4087
UPDATE_ACL if we are going to update it). It is initialized at
4088
parse time but can be updated later if this trigger field is used
4089
as OUT or INOUT parameter of stored routine (in this case
4090
set_required_privilege() is called to appropriately update
4091
want_privilege and cleanup() is responsible for restoring of
4092
original want_privilege once parameter's value is updated).
4094
ulong original_privilege;
4095
ulong want_privilege;
4096
GRANT_INFO *table_grants;
4098
Trigger field is read-only unless it belongs to the NEW row in a
4099
BEFORE INSERT of BEFORE UPDATE trigger.
4105
class Item_cache: public Item_basic_constant
4109
table_map used_table_map;
4111
Field that this object will get value from. This is used by
4112
index-based subquery engines to detect and remove the equality injected
4113
by IN->EXISTS transformation.
4115
Field *cached_field;
4116
enum enum_field_types cached_field_type;
4118
TRUE <=> cache holds value of the last stored item (i.e actual value).
4119
store() stores item to be cached and sets this flag to FALSE.
4120
On the first call of val_xxx function if this flag is set to FALSE the
4121
cache_value() will be called to actually cache value of saved item.
4122
cache_value() will set this flag to TRUE.
4127
example(0), used_table_map(0), cached_field(0),
4128
cached_field_type(MYSQL_TYPE_STRING),
4134
Item_cache(enum_field_types field_type_arg):
4135
example(0), used_table_map(0), cached_field(0),
4136
cached_field_type(field_type_arg),
4143
void set_used_tables(table_map map) { used_table_map= map; }
4145
virtual table_map resolved_used_tables() const
4147
return example ? example->resolved_used_tables() : used_table_map;
4150
virtual bool allocate(uint i) { return 0; }
4151
virtual bool setup(Item *item)
4154
max_length= item->max_length;
4155
decimals= item->decimals;
4156
collation.set(item->collation);
4157
unsigned_flag= item->unsigned_flag;
4158
if (item->type() == FIELD_ITEM)
4159
cached_field= ((Item_field *)item)->field;
4162
enum Type type() const { return CACHE_ITEM; }
4163
enum_field_types field_type() const { return cached_field_type; }
4164
static Item_cache* get_cache(const Item *item);
4165
static Item_cache* get_cache(const Item* item, const Item_result type);
4166
table_map used_tables() const { return used_table_map; }
4167
virtual void keep_array() {}
4168
virtual void print(String *str, enum_query_type query_type);
4169
bool eq_def(Field *field)
4171
return cached_field ? cached_field->eq_def (field) : FALSE;
4173
bool eq(const Item *item, bool binary_cmp) const
4175
return this == item;
4178
Check if saved item has a non-NULL value.
4179
Will cache value of saved item if not already done.
4180
@return TRUE if cached value is non-NULL.
4184
return (value_cached || cache_value()) && !null_value;
4188
If this item caches a field value, return pointer to underlying field.
4190
@return Pointer to field, or NULL if this is not a cache for a field value.
4192
Field* field() { return cached_field; }
4194
virtual void store(Item *item);
4195
virtual bool cache_value()= 0;
4196
bool basic_const_item() const
4197
{ return MY_TEST(example && example->basic_const_item());}
4198
bool walk (Item_processor processor, bool walk_subquery, uchar *argument);
4199
virtual void clear() { null_value= TRUE; value_cached= FALSE; }
4200
bool is_null() { return value_cached ? null_value : example->is_null(); }
4201
Item_result result_type() const
4205
return Field::result_merge_type(example->field_type());
4210
class Item_cache_int: public Item_cache
4215
Item_cache_int(): Item_cache(),
4217
Item_cache_int(enum_field_types field_type_arg):
4218
Item_cache(field_type_arg), value(0) {}
4220
virtual void store(Item *item){ Item_cache::store(item); }
4221
void store(Item *item, longlong val_arg);
4224
longlong val_time_temporal() { return val_int(); }
4225
longlong val_date_temporal() { return val_int(); }
4226
String* val_str(String *str);
4227
my_decimal *val_decimal(my_decimal *);
4228
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
4230
return get_date_from_int(ltime, fuzzydate);
4232
bool get_time(MYSQL_TIME *ltime)
4234
return get_time_from_int(ltime);
4236
enum Item_result result_type() const { return INT_RESULT; }
4241
class Item_cache_real: public Item_cache
4245
Item_cache_real(): Item_cache(),
4250
String* val_str(String *str);
4251
my_decimal *val_decimal(my_decimal *);
4252
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
4254
return get_date_from_real(ltime, fuzzydate);
4256
bool get_time(MYSQL_TIME *ltime)
4258
return get_time_from_real(ltime);
4260
enum Item_result result_type() const { return REAL_RESULT; }
4265
class Item_cache_decimal: public Item_cache
4268
my_decimal decimal_value;
4270
Item_cache_decimal(): Item_cache() {}
4274
String* val_str(String *str);
4275
my_decimal *val_decimal(my_decimal *);
4276
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
4278
return get_date_from_decimal(ltime, fuzzydate);
4280
bool get_time(MYSQL_TIME *ltime)
4282
return get_time_from_decimal(ltime);
4284
enum Item_result result_type() const { return DECIMAL_RESULT; }
4289
class Item_cache_str: public Item_cache
4291
char buffer[STRING_BUFFER_USUAL_SIZE];
4292
String *value, value_buff;
4296
Item_cache_str(const Item *item) :
4297
Item_cache(item->field_type()), value(0),
4298
is_varbinary(item->type() == FIELD_ITEM &&
4299
cached_field_type == MYSQL_TYPE_VARCHAR &&
4300
!((const Item_field *) item)->field->has_charset())
4302
collation.set(const_cast<DTCollation&>(item->collation));
4306
String* val_str(String *);
4307
my_decimal *val_decimal(my_decimal *);
4308
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
4310
return get_date_from_string(ltime, fuzzydate);
4312
bool get_time(MYSQL_TIME *ltime)
4314
return get_time_from_string(ltime);
4316
enum Item_result result_type() const { return STRING_RESULT; }
4317
const CHARSET_INFO *charset() const { return value->charset(); };
4318
type_conversion_status save_in_field(Field *field, bool no_conversions);
4322
class Item_cache_row: public Item_cache
4324
Item_cache **values;
4329
:Item_cache(), values(0), item_count(2),
4333
'allocate' used only in row transformer, to preallocate space for row
4336
bool allocate(uint num);
4338
'setup' is needed only by row => it not called by simple row subselect
4339
(only by IN subselect (in subselect optimizer))
4341
bool setup(Item *item);
4342
void store(Item *item);
4343
void illegal_method_call(const char *);
4344
void make_field(Send_field *)
4346
illegal_method_call((const char*)"make_field");
4350
illegal_method_call((const char*)"val");
4355
illegal_method_call((const char*)"val_int");
4358
String *val_str(String *)
4360
illegal_method_call((const char*)"val_str");
4363
my_decimal *val_decimal(my_decimal *val)
4365
illegal_method_call((const char*)"val_decimal");
4368
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
4370
illegal_method_call((const char *) "get_date");
4373
bool get_time(MYSQL_TIME *ltime)
4375
illegal_method_call((const char *) "get_time");
4379
enum Item_result result_type() const { return ROW_RESULT; }
4381
uint cols() { return item_count; }
4382
Item *element_index(uint i) { return values[i]; }
4383
Item **addr(uint i) { return (Item **) (values + i); }
4384
bool check_cols(uint c);
4387
void keep_array() { save_array= 1; }
4390
DBUG_ENTER("Item_cache_row::cleanup");
4391
Item_cache::cleanup();
4393
memset(values, 0, item_count*sizeof(Item**));
4402
class Item_cache_datetime: public Item_cache
4407
bool str_value_cached;
4409
Item_cache_datetime(enum_field_types field_type_arg):
4410
Item_cache(field_type_arg), int_value(0), str_value_cached(0)
4412
cmp_context= STRING_RESULT;
4415
void store(Item *item, longlong val_arg);
4416
void store(Item *item);
4419
longlong val_time_temporal();
4420
longlong val_date_temporal();
4421
String* val_str(String *str);
4422
my_decimal *val_decimal(my_decimal *);
4423
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
4424
bool get_time(MYSQL_TIME *ltime);
4425
enum Item_result result_type() const { return STRING_RESULT; }
4427
In order to avoid INT <-> STRING conversion of a DATETIME value
4428
two cache_value functions are introduced. One (cache_value) caches STRING
4429
value, another (cache_value_int) - INT value. Thus this cache item
4430
completely relies on the ability of the underlying item to do the
4433
bool cache_value_int();
4435
void clear() { Item_cache::clear(); str_value_cached= FALSE; }
4440
Item_type_holder used to store type. name, length of Item for UNIONS &
4443
Item_type_holder do not need cleanup() because its time of live limited by
4444
single SP/PS execution.
4446
class Item_type_holder: public Item
4449
TYPELIB *enum_set_typelib;
4450
enum_field_types fld_type;
4451
Field::geometry_type geometry_type;
4453
void get_full_info(Item *item);
4455
/* It is used to count decimal precision in join_types */
4456
int prev_decimal_int_part;
4458
Item_type_holder(THD*, Item*);
4460
Item_result result_type() const;
4461
enum_field_types field_type() const { return fld_type; };
4462
enum Type type() const { return TYPE_HOLDER; }
4465
my_decimal *val_decimal(my_decimal *);
4466
String *val_str(String*);
4467
bool get_date(MYSQL_TIME *ltime, uint fuzzydate)
4472
bool get_time(MYSQL_TIME *ltime)
4477
bool join_types(THD *thd, Item *);
4478
Field *make_field_by_type(TABLE *table);
4479
static uint32 display_length(Item *item);
4480
static enum_field_types get_real_type(Item *);
4481
Field::geometry_type get_geometry_type() const { return geometry_type; };
4485
class st_select_lex;
4486
void mark_select_range_as_dependent(THD *thd,
4487
st_select_lex *last_select,
4488
st_select_lex *current_sel,
4489
Field *found_field, Item *found_item,
4490
Item_ident *resolved_item);
4492
extern Cached_item *new_Cached_item(THD *thd, Item *item,
4493
bool use_result_field);
4494
extern Item_result item_cmp_type(Item_result a,Item_result b);
4495
extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
4496
extern int stored_field_cmp_to_item(THD *thd, Field *field, Item *item);
4498
extern const String my_null_string;
4500
#endif /* ITEM_INCLUDED */