1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_ITEM_H
21
#define DRIZZLED_ITEM_H
23
#include <drizzled/dtcollation.h>
24
#include <mysys/drizzle_time.h>
25
#include <drizzled/my_decimal.h>
26
#include <drizzled/sql_bitmap.h>
27
#include <drizzled/sql_list.h>
28
#include <drizzled/sql_alloc.h>
1
/* Copyright (C) 2000-2006 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
void item_init(void); /* Init item functions */
33
class Name_resolution_context;
38
class Item_in_subselect;
42
void item_init(void); /* Init item functions */
45
void dummy_error_processor(Session *session, void *data);
46
void view_error_processor(Session *session, void *data);
49
/*************************************************************************/
22
"Declared Type Collation"
23
A combination of collation and its derivation.
25
Flags for collation aggregation modes:
26
MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
27
MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
29
MY_COLL_ALLOW_CONV - allow any kind of conversion
30
(combination of the above two)
31
MY_COLL_DISALLOW_NONE - don't allow return DERIVATION_NONE
32
(e.g. when aggregating for comparison)
33
MY_COLL_CMP_CONV - combination of MY_COLL_ALLOW_CONV
34
and MY_COLL_DISALLOW_NONE
37
#define MY_COLL_ALLOW_SUPERSET_CONV 1
38
#define MY_COLL_ALLOW_COERCIBLE_CONV 2
39
#define MY_COLL_ALLOW_CONV 3
40
#define MY_COLL_DISALLOW_NONE 4
41
#define MY_COLL_CMP_CONV 7
45
const CHARSET_INFO *collation;
46
enum Derivation derivation;
49
void set_repertoire_from_charset(const CHARSET_INFO * const cs)
51
repertoire= cs->state & MY_CS_PUREASCII ?
52
MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
56
collation= &my_charset_bin;
57
derivation= DERIVATION_NONE;
58
repertoire= MY_REPERTOIRE_UNICODE30;
60
DTCollation(const CHARSET_INFO * const collation_arg, Derivation derivation_arg)
62
collation= collation_arg;
63
derivation= derivation_arg;
64
set_repertoire_from_charset(collation_arg);
66
void set(DTCollation &dt)
68
collation= dt.collation;
69
derivation= dt.derivation;
70
repertoire= dt.repertoire;
72
void set(const CHARSET_INFO * const collation_arg, Derivation derivation_arg)
74
collation= collation_arg;
75
derivation= derivation_arg;
76
set_repertoire_from_charset(collation_arg);
78
void set(const CHARSET_INFO * const collation_arg,
79
Derivation derivation_arg,
82
collation= collation_arg;
83
derivation= derivation_arg;
84
repertoire= repertoire_arg;
86
void set(const CHARSET_INFO * const collation_arg)
88
collation= collation_arg;
89
set_repertoire_from_charset(collation_arg);
91
void set(Derivation derivation_arg)
92
{ derivation= derivation_arg; }
93
bool aggregate(DTCollation &dt, uint flags= 0);
94
bool set(DTCollation &dt1, DTCollation &dt2, uint flags= 0)
95
{ set(dt1); return aggregate(dt2, flags); }
96
const char *derivation_name() const
100
case DERIVATION_IGNORABLE: return "IGNORABLE";
101
case DERIVATION_COERCIBLE: return "COERCIBLE";
102
case DERIVATION_IMPLICIT: return "IMPLICIT";
103
case DERIVATION_SYSCONST: return "SYSCONST";
104
case DERIVATION_EXPLICIT: return "EXPLICIT";
105
case DERIVATION_NONE: return "NONE";
106
default: return "UNKNOWN";
111
/*************************************************************************/
113
A framework to easily handle different return types for hybrid items
114
(hybrid item is an item whose operand can be of any type, e.g. integer,
118
struct Hybrid_type_traits;
126
Use two decimal buffers interchangeably to speed up += operation
127
which has no native support in decimal library.
128
Hybrid_type+= arg is implemented as dec_buf[1]= dec_buf[0] + arg.
129
The third decimal is used as a handy temporary storage.
131
my_decimal dec_buf[3];
135
Traits moved to a separate class to
136
a) be able to easily change object traits in runtime
137
b) they work as a differentiator for the union above
139
const Hybrid_type_traits *traits;
142
/* XXX: add traits->copy() when needed */
143
Hybrid_type(const Hybrid_type &rhs) :traits(rhs.traits) {}
147
/* Hybryd_type_traits interface + default implementation for REAL_RESULT */
149
struct Hybrid_type_traits
151
virtual Item_result type() const { return REAL_RESULT; }
154
fix_length_and_dec(Item *item, Item *arg) const;
156
/* Hybrid_type operations. */
157
virtual void set_zero(Hybrid_type *val) const { val->real= 0.0; }
158
virtual void add(Hybrid_type *val, Field *f) const
159
{ val->real+= f->val_real(); }
160
virtual void div(Hybrid_type *val, uint64_t u) const
161
{ val->real/= uint64_t2double(u); }
163
virtual int64_t val_int(Hybrid_type *val,
164
bool unsigned_flag __attribute__((unused))) const
165
{ return (int64_t) rint(val->real); }
166
virtual double val_real(Hybrid_type *val) const { return val->real; }
167
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const;
168
virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
169
static const Hybrid_type_traits *instance();
170
Hybrid_type_traits() {}
171
virtual ~Hybrid_type_traits() {}
175
struct Hybrid_type_traits_decimal: public Hybrid_type_traits
177
virtual Item_result type() const { return DECIMAL_RESULT; }
180
fix_length_and_dec(Item *arg, Item *item) const;
182
/* Hybrid_type operations. */
183
virtual void set_zero(Hybrid_type *val) const;
184
virtual void add(Hybrid_type *val, Field *f) const;
185
virtual void div(Hybrid_type *val, uint64_t u) const;
187
virtual int64_t val_int(Hybrid_type *val, bool unsigned_flag) const;
188
virtual double val_real(Hybrid_type *val) const;
189
virtual my_decimal *val_decimal(Hybrid_type *val,
190
my_decimal *buf __attribute__((unused))) const
191
{ return &val->dec_buf[val->used_dec_buf_no]; }
192
virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
193
static const Hybrid_type_traits_decimal *instance();
194
Hybrid_type_traits_decimal() {};
198
struct Hybrid_type_traits_integer: public Hybrid_type_traits
200
virtual Item_result type() const { return INT_RESULT; }
203
fix_length_and_dec(Item *arg, Item *item) const;
205
/* Hybrid_type operations. */
206
virtual void set_zero(Hybrid_type *val) const
208
virtual void add(Hybrid_type *val, Field *f) const
209
{ val->integer+= f->val_int(); }
210
virtual void div(Hybrid_type *val, uint64_t u) const
211
{ val->integer/= (int64_t) u; }
213
virtual int64_t val_int(Hybrid_type *val,
214
bool unsigned_flag __attribute__((unused))) const
215
{ return val->integer; }
216
virtual double val_real(Hybrid_type *val) const
217
{ return (double) val->integer; }
218
virtual my_decimal *val_decimal(Hybrid_type *val,
219
my_decimal *buf __attribute__((unused))) const
221
int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
222
return &val->dec_buf[2];
224
virtual String *val_str(Hybrid_type *val, String *buf,
225
uint8_t decimals __attribute__((unused))) const
226
{ buf->set(val->integer, &my_charset_bin); return buf;}
227
static const Hybrid_type_traits_integer *instance();
228
Hybrid_type_traits_integer() {};
232
void dummy_error_processor(THD *thd, void *data);
234
void view_error_processor(THD *thd, void *data);
237
Instances of Name_resolution_context store the information necesary for
238
name resolution of Items and other context analysis of a query made in
241
This structure is a part of SELECT_LEX, a pointer to this structure is
242
assigned when an item is created (which happens mostly during parsing
243
(sql_yacc.yy)), but the structure itself will be initialized after parsing
246
TODO: move subquery of INSERT ... SELECT and CREATE ... SELECT to
247
separate SELECT_LEX which allow to remove tricks of changing this
248
structure before and after INSERT/CREATE and its SELECT to make correct
249
field name resolution.
251
struct Name_resolution_context: Sql_alloc
254
The name resolution context to search in when an Item cannot be
255
resolved in this context (the context of an outer select)
257
Name_resolution_context *outer_context;
260
List of tables used to resolve the items of this context. Usually these
261
are tables from the FROM clause of SELECT statement. The exceptions are
262
INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
263
subquery is not moved to a separate SELECT_LEX. For these types of
264
statements we have to change this member dynamically to ensure correct
265
name resolution of different parts of the statement.
267
TableList *table_list;
269
In most cases the two table references below replace 'table_list' above
270
for the purpose of name resolution. The first and last name resolution
271
table references allow us to search only in a sub-tree of the nested
272
join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
275
TableList *first_name_resolution_table;
277
Last table to search in the list of leaf table references that begins
278
with first_name_resolution_table.
280
TableList *last_name_resolution_table;
283
SELECT_LEX item belong to, in case of merged VIEW it can differ from
284
SELECT_LEX where item was created, so we can't use table_list/field_list
287
st_select_lex *select_lex;
290
Processor of errors caused during Item name resolving, now used only to
291
hide underlying tables in errors about views (i.e. it substitute some
294
void (*error_processor)(THD *, void *);
295
void *error_processor_data;
298
When true items are resolved in this context both against the
299
SELECT list and this->table_list. If false, items are resolved
300
only against this->table_list.
302
bool resolve_in_select_list;
305
Security context of this name resolution context. It's used for views
306
and is non-zero only if the view is defined with SQL SECURITY DEFINER.
308
Security_context *security_ctx;
310
Name_resolution_context()
311
:outer_context(0), table_list(0), select_lex(0),
312
error_processor_data(0),
318
resolve_in_select_list= false;
319
error_processor= &dummy_error_processor;
320
first_name_resolution_table= NULL;
321
last_name_resolution_table= NULL;
324
void resolve_in_table_list_only(TableList *tables)
326
table_list= first_name_resolution_table= tables;
327
resolve_in_select_list= false;
330
void process_error(THD *thd)
332
(*error_processor)(thd, error_processor_data);
338
Store and restore the current state of a name resolution context.
341
class Name_resolution_context_state
344
TableList *save_table_list;
345
TableList *save_first_name_resolution_table;
346
TableList *save_next_name_resolution_table;
347
bool save_resolve_in_select_list;
348
TableList *save_next_local;
351
Name_resolution_context_state() {} /* Remove gcc warning */
354
/* Save the state of a name resolution context. */
355
void save_state(Name_resolution_context *context, TableList *table_list)
357
save_table_list= context->table_list;
358
save_first_name_resolution_table= context->first_name_resolution_table;
359
save_resolve_in_select_list= context->resolve_in_select_list;
360
save_next_local= table_list->next_local;
361
save_next_name_resolution_table= table_list->next_name_resolution_table;
364
/* Restore a name resolution context from saved state. */
365
void restore_state(Name_resolution_context *context, TableList *table_list)
367
table_list->next_local= save_next_local;
368
table_list->next_name_resolution_table= save_next_name_resolution_table;
369
context->table_list= save_table_list;
370
context->first_name_resolution_table= save_first_name_resolution_table;
371
context->resolve_in_select_list= save_resolve_in_select_list;
374
TableList *get_first_name_resolution_table()
376
return save_first_name_resolution_table;
382
This enum is used to report information about monotonicity of function
383
represented by Item* tree.
384
Monotonicity is defined only for Item* trees that represent table
385
partitioning expressions (i.e. have no subselects/user vars/PS parameters
386
etc etc). An Item* tree is assumed to have the same monotonicity properties
387
as its correspoinding function F:
389
[signed] int64_t F(field1, field2, ...) {
390
put values of field_i into table record buffer;
391
return item->val_int();
395
At the moment function monotonicity is not well defined (and so may be
396
incorrect) for Item trees with parameters/return types that are different
397
from INT_RESULT, may be NULL, or are unsigned.
398
It will be possible to address this issue once the related partitioning bugs
399
(BUG#16002, BUG#15447, BUG#13436) are fixed.
402
typedef enum monotonicity_info
404
NON_MONOTONIC, /* none of the below holds */
405
MONOTONIC_INCREASING, /* F() is unary and (x < y) => (F(x) <= F(y)) */
406
MONOTONIC_STRICT_INCREASING /* F() is unary and (x < y) => (F(x) < F(y)) */
407
} enum_monotonicity_info;
409
/*************************************************************************/
410
typedef bool (Item::*Item_processor) (uchar *arg);
53
414
argp in/out IN: Analysis parameter
54
415
OUT: Parameter to be passed to the transformer
57
418
true Invoke the transformer
61
typedef bool (Item::*Item_analyzer) (unsigned char **argp);
62
typedef Item* (Item::*Item_transformer) (unsigned char *arg);
422
typedef bool (Item::*Item_analyzer) (uchar **argp);
423
typedef Item* (Item::*Item_transformer) (uchar *arg);
63
424
typedef void (*Cond_traverser) (const Item *item, void *arg);
64
typedef bool (Item::*Item_processor) (unsigned char *arg);
67
class Item: public Sql_alloc
69
/* Prevent use of these */
429
Item(const Item &); /* Prevent use of these */
71
430
void operator=(Item &);
73
431
/* Cache of the result of is_expensive(). */
74
432
int8_t is_expensive_cache;
75
virtual bool is_expensive_processor(unsigned char *arg);
433
virtual bool is_expensive_processor(uchar *arg __attribute__((unused)))
437
static void *operator new(size_t size)
438
{ return sql_alloc(size); }
439
static void *operator new(size_t size, MEM_ROOT *mem_root)
440
{ return alloc_root(mem_root, size); }
441
static void operator delete(void *ptr __attribute__((unused)),
442
size_t size __attribute__((unused)))
443
{ TRASH(ptr, size); }
444
static void operator delete(void *ptr __attribute__((unused)),
445
MEM_ROOT *mem_root __attribute__((unused)))
79
enum Type {FIELD_ITEM= 0,
448
enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM,
449
INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM,
450
COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM,
451
PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
452
FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
453
SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
454
PARAM_ITEM, DECIMAL_ITEM,
103
457
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
105
459
enum traverse_order { POSTFIX, PREFIX };
461
/* Reuse size, only used by SP local variable assignment, otherwize 0 */
108
465
str_values's main purpose is to be used to cache the value in
111
468
String str_value;
113
/* Name from select */
469
char * name; /* Name from select */
116
470
/* Original item name (if it was renamed)*/
117
471
char * orig_name;
119
473
uint32_t max_length;
122
uint32_t name_length;
474
uint name_length; /* Length of name */
125
476
uint8_t decimals;
126
477
bool maybe_null; /* If item may be null */
579
950
where 'cost' is either 'double' or some structure of various cost
582
virtual bool is_expensive();
953
virtual bool is_expensive()
955
if (is_expensive_cache < 0)
956
is_expensive_cache= walk(&Item::is_expensive_processor, 0, (uchar*)0);
957
return test(is_expensive_cache);
584
959
String *check_well_formed_result(String *str, bool send_error= 0);
585
bool eq_by_collation(Item *item, bool binary_cmp,
586
const CHARSET_INFO * const cs);
590
#include <drizzled/item/basic_constant.h>
591
#include <drizzled/item/bin_string.h>
592
#include <drizzled/item/blob.h>
593
#include <drizzled/item/copy_string.h>
594
#include <drizzled/item/ident.h>
595
#include <drizzled/item/field.h>
597
void mark_as_dependent(Session *session,
599
st_select_lex *current,
600
Item_ident *resolved_item,
601
Item_ident *mark_item);
603
Item** resolve_ref_in_select_and_group(Session *session,
605
st_select_lex *select);
608
void mark_select_range_as_dependent(Session *session,
960
bool eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs);
964
class Item_basic_constant :public Item
967
/* to prevent drop fixed flag (no need parent cleanup call) */
971
Restore the original field name as it might not have been allocated
972
in the statement memory. If the name is auto generated, it must be
973
done again between subsequent executions of a prepared statement.
980
bool agg_item_collations(DTCollation &c, const char *name,
981
Item **items, uint nitems, uint flags, int item_sep);
982
bool agg_item_collations_for_comparison(DTCollation &c, const char *name,
983
Item **items, uint nitems, uint flags);
984
bool agg_item_charsets(DTCollation &c, const char *name,
985
Item **items, uint nitems, uint flags, int item_sep);
988
class Item_num: public Item_basic_constant
991
Item_num() {} /* Remove gcc warning */
992
virtual Item_num *neg()= 0;
993
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
996
#define NO_CACHED_FIELD_INDEX ((uint)(-1))
999
class Item_ident :public Item
1003
We have to store initial values of db_name, table_name and field_name
1004
to be able to restore them during cleanup() because they can be
1005
updated during fix_fields() to values from Field object and life-time
1006
of those is shorter than life-time of Item_field.
1008
const char *orig_db_name;
1009
const char *orig_table_name;
1010
const char *orig_field_name;
1013
Name_resolution_context *context;
1014
const char *db_name;
1015
const char *table_name;
1016
const char *field_name;
1017
bool alias_name_used; /* true if item was resolved against alias */
1019
Cached value of index for this field in table->field array, used by prep.
1020
stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX
1021
if index value is not known.
1023
uint cached_field_index;
1025
Cached pointer to table which contains this field, used for the same reason
1026
by prep. stmt. too in case then we have not-fully qualified field.
1027
0 - means no cached value.
1029
TableList *cached_table;
1030
st_select_lex *depended_from;
1031
Item_ident(Name_resolution_context *context_arg,
1032
const char *db_name_arg, const char *table_name_arg,
1033
const char *field_name_arg);
1034
Item_ident(THD *thd, Item_ident *item);
1035
const char *full_name() const;
1037
bool remove_dependence_processor(uchar * arg);
1038
virtual void print(String *str, enum_query_type query_type);
1039
virtual bool change_context_processor(uchar *cntx)
1040
{ context= (Name_resolution_context *)cntx; return false; }
1041
friend bool insert_fields(THD *thd, Name_resolution_context *context,
1042
const char *db_name,
1043
const char *table_name, List_iterator<Item> *it,
1044
bool any_privileges);
1048
class Item_ident_for_show :public Item
1052
const char *db_name;
1053
const char *table_name;
1055
Item_ident_for_show(Field *par_field, const char *db_arg,
1056
const char *table_name_arg)
1057
:field(par_field), db_name(db_arg), table_name(table_name_arg)
1060
enum Type type() const { return FIELD_ITEM; }
1061
double val_real() { return field->val_real(); }
1062
int64_t val_int() { return field->val_int(); }
1063
String *val_str(String *str) { return field->val_str(str); }
1064
my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); }
1065
void make_field(Send_field *tmp_field);
1072
class Item_field :public Item_ident
1075
void set_field(Field *field);
1077
Field *field,*result_field;
1078
Item_equal *item_equal;
1079
bool no_const_subst;
1081
if any_privileges set to true then here real effective privileges will
1084
uint have_privileges;
1085
/* field need any privileges (for VIEW creation) */
1086
bool any_privileges;
1087
Item_field(Name_resolution_context *context_arg,
1088
const char *db_arg,const char *table_name_arg,
1089
const char *field_name_arg);
1091
Constructor needed to process subselect with temporary tables (see Item)
1093
Item_field(THD *thd, Item_field *item);
1095
Constructor used inside setup_wild(), ensures that field, table,
1096
and database names will live as long as Item_field (this is important
1097
in prepared statements).
1099
Item_field(THD *thd, Name_resolution_context *context_arg, Field *field);
1101
If this constructor is used, fix_fields() won't work, because
1102
db_name, table_name and column_name are unknown. It's necessary to call
1103
reset_field() before fix_fields() for all fields created this way.
1105
Item_field(Field *field);
1106
enum Type type() const { return FIELD_ITEM; }
1107
bool eq(const Item *item, bool binary_cmp) const;
1110
my_decimal *val_decimal(my_decimal *);
1111
String *val_str(String*);
1112
double val_result();
1113
int64_t val_int_result();
1114
String *str_result(String* tmp);
1115
my_decimal *val_decimal_result(my_decimal *);
1116
bool val_bool_result();
1117
bool send(Protocol *protocol, String *str_arg);
1118
void reset_field(Field *f);
1119
bool fix_fields(THD *, Item **);
1120
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
1121
void make_field(Send_field *tmp_field);
1122
int save_in_field(Field *field,bool no_conversions);
1123
void save_org_in_field(Field *field);
1124
table_map used_tables() const;
1125
enum Item_result result_type () const
1127
return field->result_type();
1129
Item_result cast_to_int_type() const
1131
return field->cast_to_int_type();
1133
enum_field_types field_type() const
1135
return field->type();
1137
enum_monotonicity_info get_monotonicity_info() const
1139
return MONOTONIC_STRICT_INCREASING;
1141
int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
1142
Field *get_tmp_table_field() { return result_field; }
1143
Field *tmp_table_field(Table *t_arg __attribute__((unused))) { return result_field; }
1144
bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
1145
bool get_date_result(DRIZZLE_TIME *ltime,uint fuzzydate);
1146
bool get_time(DRIZZLE_TIME *ltime);
1147
bool is_null() { return field->is_null(); }
1148
void update_null_value();
1149
Item *get_tmp_table_item(THD *thd);
1150
bool collect_item_field_processor(uchar * arg);
1151
bool find_item_in_field_list_processor(uchar *arg);
1152
bool register_field_in_read_map(uchar *arg);
1154
bool result_as_int64_t()
1156
return field->can_be_compared_as_int64_t();
1158
Item_equal *find_item_equal(COND_EQUAL *cond_equal);
1159
bool subst_argument_checker(uchar **arg);
1160
Item *equal_fields_propagator(uchar *arg);
1161
bool set_no_const_sub(uchar *arg);
1162
Item *replace_equal_field(uchar *arg);
1163
inline uint32_t max_disp_length() { return field->max_display_length(); }
1164
Item_field *filed_for_view_update() { return this; }
1165
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1166
int fix_outer_field(THD *thd, Field **field, Item **reference);
1167
virtual Item *update_value_transformer(uchar *select_arg);
1168
virtual void print(String *str, enum_query_type query_type);
1170
friend class Item_default_value;
1171
friend class Item_insert_value;
1172
friend class st_select_lex_unit;
1175
class Item_null :public Item_basic_constant
1178
Item_null(char *name_par=0)
1180
maybe_null= null_value= true;
1182
name= name_par ? name_par : (char*) "NULL";
1184
collation.set(&my_charset_bin, DERIVATION_IGNORABLE);
1186
enum Type type() const { return NULL_ITEM; }
1187
bool eq(const Item *item, bool binary_cmp) const;
1190
String *val_str(String *str);
1191
my_decimal *val_decimal(my_decimal *);
1192
int save_in_field(Field *field, bool no_conversions);
1193
int save_safe_in_field(Field *field);
1194
bool send(Protocol *protocol, String *str);
1195
enum Item_result result_type () const { return STRING_RESULT; }
1196
enum_field_types field_type() const { return DRIZZLE_TYPE_NULL; }
1197
bool basic_const_item() const { return 1; }
1198
Item *clone_item() { return new Item_null(name); }
1199
bool is_null() { return 1; }
1201
virtual inline void print(String *str,
1202
enum_query_type query_type __attribute__((unused)))
1204
str->append(STRING_WITH_LEN("NULL"));
1207
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1210
class Item_null_result :public Item_null
1213
Field *result_field;
1214
Item_null_result() : Item_null(), result_field(0) {}
1215
bool is_result_field() { return result_field != 0; }
1216
void save_in_result_field(bool no_conversions)
1218
save_in_field(result_field, no_conversions);
1222
/* Item represents one placeholder ('?') of prepared statement */
1224
class Item_param :public Item
1226
char cnvbuf[MAX_FIELD_WIDTH];
1231
enum enum_item_param_state
1233
NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE,
1234
STRING_VALUE, TIME_VALUE, LONG_DATA_VALUE,
1239
A buffer for string and long data values. Historically all allocated
1240
values returned from val_str() were treated as eligible to
1241
modification. I. e. in some cases Item_func_concat can append it's
1242
second argument to return value of the first one. Because of that we
1243
can't return the original buffer holding string data from val_str(),
1244
and have to have one buffer for data and another just pointing to
1245
the data. This is the latter one and it's returned from val_str().
1246
Can not be declared inside the union as it's not a POD type.
1248
String str_value_ptr;
1249
my_decimal decimal_value;
1255
Character sets conversion info for string values.
1256
Character sets of client and connection defined at bind time are used
1257
for all conversions, even if one of them is later changed (i.e.
1258
between subsequent calls to mysql_stmt_execute).
1260
struct CONVERSION_INFO
1262
const CHARSET_INFO *character_set_client;
1263
const CHARSET_INFO *character_set_of_placeholder;
1265
This points at character set of connection if conversion
1266
to it is required (i. e. if placeholder typecode is not BLOB).
1267
Otherwise it's equal to character_set_client (to simplify
1268
check in convert_str_value()).
1270
const CHARSET_INFO *final_character_set_of_str_value;
1275
/* Cached values for virtual methods to save us one switch. */
1276
enum Item_result item_result_type;
1277
enum Type item_type;
1280
Used when this item is used in a temporary table.
1281
This is NOT placeholder metadata sent to client, as this value
1282
is assigned after sending metadata (in setup_one_conversion_function).
1283
For example in case of 'SELECT ?' you'll get DRIZZLE_TYPE_STRING both
1284
in result set and placeholders metadata, no matter what type you will
1285
supply for this placeholder in mysql_stmt_execute.
1287
enum enum_field_types param_type;
1289
Offset of placeholder inside statement text. Used to create
1290
no-placeholders version of this statement for the binary log.
1294
Item_param(uint pos_in_query_arg);
1296
enum Item_result result_type () const { return item_result_type; }
1297
enum Type type() const { return item_type; }
1298
enum_field_types field_type() const { return param_type; }
1302
my_decimal *val_decimal(my_decimal*);
1303
String *val_str(String*);
1304
bool get_time(DRIZZLE_TIME *tm);
1305
bool get_date(DRIZZLE_TIME *tm, uint fuzzydate);
1306
int save_in_field(Field *field, bool no_conversions);
1309
void set_int(int64_t i, uint32_t max_length_arg);
1310
void set_double(double i);
1311
void set_decimal(char *str, ulong length);
1312
bool set_str(const char *str, ulong length);
1313
bool set_longdata(const char *str, ulong length);
1314
void set_time(DRIZZLE_TIME *tm, timestamp_type type, uint32_t max_length_arg);
1315
bool set_from_user_var(THD *thd, const user_var_entry *entry);
1318
Assign placeholder value from bind data.
1319
Note, that 'len' has different semantics in embedded library (as we
1320
don't need to check that packet is not broken there). See
1321
sql_prepare.cc for details.
1323
void (*set_param_func)(Item_param *param, uchar **pos, ulong len);
1325
const String *query_val_str(String *str) const;
1327
bool convert_str_value(THD *thd);
1330
If value for parameter was not set we treat it as non-const
1331
so noone will use parameters value in fix_fields still
1332
parameter is constant during execution.
1334
virtual table_map used_tables() const
1335
{ return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; }
1336
virtual void print(String *str, enum_query_type query_type);
1338
{ assert(state != NO_VALUE); return state == NULL_VALUE; }
1339
bool basic_const_item() const;
1341
This method is used to make a copy of a basic constant item when
1342
propagating constants in the optimizer. The reason to create a new
1343
item and not use the existing one is not precisely known (2005/04/16).
1344
Probably we are trying to preserve tree structure of items, in other
1345
words, avoid pointing at one item from two different nodes of the tree.
1346
Return a new basic constant item if parameter value is a basic
1347
constant, assert otherwise. This method is called only if
1348
basic_const_item returned true.
1350
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1353
Implement by-value equality evaluation if parameter value
1354
is set and is a basic constant (integer, real or string).
1355
Otherwise return false.
1357
bool eq(const Item *item, bool binary_cmp) const;
1358
/** Item is a argument to a limit clause. */
1359
bool limit_clause_param;
1363
class Item_int :public Item_num
1367
Item_int(int32_t i,uint length= MY_INT32_NUM_DECIMAL_DIGITS)
1369
{ max_length=length; fixed= 1; }
1370
Item_int(int64_t i,uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1372
{ max_length=length; fixed= 1; }
1373
Item_int(uint64_t i, uint length= MY_INT64_NUM_DECIMAL_DIGITS)
1375
{ max_length=length; fixed= 1; unsigned_flag= 1; }
1376
Item_int(const char *str_arg,int64_t i,uint length) :value(i)
1377
{ max_length=length; name=(char*) str_arg; fixed= 1; }
1378
Item_int(const char *str_arg, uint length=64);
1379
enum Type type() const { return INT_ITEM; }
1380
enum Item_result result_type () const { return INT_RESULT; }
1381
enum_field_types field_type() const { return DRIZZLE_TYPE_LONGLONG; }
1382
int64_t val_int() { assert(fixed == 1); return value; }
1383
double val_real() { assert(fixed == 1); return (double) value; }
1384
my_decimal *val_decimal(my_decimal *);
1385
String *val_str(String*);
1386
int save_in_field(Field *field, bool no_conversions);
1387
bool basic_const_item() const { return 1; }
1388
Item *clone_item() { return new Item_int(name,value,max_length); }
1389
virtual void print(String *str, enum_query_type query_type);
1390
Item_num *neg() { value= -value; return this; }
1391
uint decimal_precision() const
1392
{ return (uint)(max_length - test(value < 0)); }
1393
bool eq(const Item *, bool binary_cmp) const;
1397
class Item_uint :public Item_int
1400
Item_uint(const char *str_arg, uint length);
1401
Item_uint(uint64_t i) :Item_int((uint64_t) i, 10) {}
1402
Item_uint(const char *str_arg, int64_t i, uint length);
1404
{ assert(fixed == 1); return uint64_t2double((uint64_t)value); }
1405
String *val_str(String*);
1406
Item *clone_item() { return new Item_uint(name, value, max_length); }
1407
int save_in_field(Field *field, bool no_conversions);
1408
virtual void print(String *str, enum_query_type query_type);
1410
uint decimal_precision() const { return max_length; }
1414
/* decimal (fixed point) constant */
1415
class Item_decimal :public Item_num
1418
my_decimal decimal_value;
1420
Item_decimal(const char *str_arg, uint length, const CHARSET_INFO * const charset);
1421
Item_decimal(const char *str, const my_decimal *val_arg,
1422
uint decimal_par, uint length);
1423
Item_decimal(my_decimal *value_par);
1424
Item_decimal(int64_t val, bool unsig);
1425
Item_decimal(double val, int precision, int scale);
1426
Item_decimal(const uchar *bin, int precision, int scale);
1428
enum Type type() const { return DECIMAL_ITEM; }
1429
enum Item_result result_type () const { return DECIMAL_RESULT; }
1430
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDECIMAL; }
1433
String *val_str(String*);
1434
my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
1435
{ return &decimal_value; }
1436
int save_in_field(Field *field, bool no_conversions);
1437
bool basic_const_item() const { return 1; }
1440
return new Item_decimal(name, &decimal_value, decimals, max_length);
1442
virtual void print(String *str, enum_query_type query_type);
1445
my_decimal_neg(&decimal_value);
1446
unsigned_flag= !decimal_value.sign();
1449
uint decimal_precision() const { return decimal_value.precision(); }
1450
bool eq(const Item *, bool binary_cmp) const;
1451
void set_decimal_value(my_decimal *value_par);
1455
class Item_float :public Item_num
1460
// Item_real() :value(0) {}
1461
Item_float(const char *str_arg, uint length);
1462
Item_float(const char *str,double val_arg,uint decimal_par,uint length)
1465
presentation= name=(char*) str;
1466
decimals=(uint8_t) decimal_par;
1470
Item_float(double value_par, uint decimal_par) :presentation(0), value(value_par)
1472
decimals= (uint8_t) decimal_par;
1475
int save_in_field(Field *field, bool no_conversions);
1476
enum Type type() const { return REAL_ITEM; }
1477
enum_field_types field_type() const { return DRIZZLE_TYPE_DOUBLE; }
1478
double val_real() { assert(fixed == 1); return value; }
1482
if (value <= (double) INT64_MIN)
1486
else if (value >= (double) (uint64_t) INT64_MAX)
1490
return (int64_t) rint(value);
1492
String *val_str(String*);
1493
my_decimal *val_decimal(my_decimal *);
1494
bool basic_const_item() const { return 1; }
1496
{ return new Item_float(name, value, decimals, max_length); }
1497
Item_num *neg() { value= -value; return this; }
1498
virtual void print(String *str, enum_query_type query_type);
1499
bool eq(const Item *, bool binary_cmp) const;
1503
class Item_static_float_func :public Item_float
1505
const char *func_name;
1507
Item_static_float_func(const char *str, double val_arg, uint decimal_par,
1509
:Item_float(NullS, val_arg, decimal_par, length), func_name(str)
1512
virtual inline void print(String *str,
1513
enum_query_type query_type __attribute__((unused)))
1515
str->append(func_name);
1518
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1522
class Item_string :public Item_basic_constant
1525
Item_string(const char *str,uint length,
1526
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE,
1527
uint repertoire= MY_REPERTOIRE_UNICODE30)
1528
: m_cs_specified(false)
1530
str_value.set_or_copy_aligned(str, length, cs);
1531
collation.set(cs, dv, repertoire);
1533
We have to have a different max_length than 'length' here to
1534
ensure that we get the right length if we do use the item
1535
to create a new table. In this case max_length must be the maximum
1536
number of chars for a string of this type because we in Create_field::
1537
divide the max_length with mbmaxlen).
1539
max_length= str_value.numchars()*cs->mbmaxlen;
1540
set_name(str, length, cs);
1541
decimals=NOT_FIXED_DEC;
1542
// it is constant => can be used without fix_fields (and frequently used)
1545
/* Just create an item and do not fill string representation */
1546
Item_string(const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE)
1547
: m_cs_specified(false)
1549
collation.set(cs, dv);
1551
set_name(NULL, 0, cs);
1552
decimals= NOT_FIXED_DEC;
1555
Item_string(const char *name_par, const char *str, uint length,
1556
const CHARSET_INFO * const cs, Derivation dv= DERIVATION_COERCIBLE,
1557
uint repertoire= MY_REPERTOIRE_UNICODE30)
1558
: m_cs_specified(false)
1560
str_value.set_or_copy_aligned(str, length, cs);
1561
collation.set(cs, dv, repertoire);
1562
max_length= str_value.numchars()*cs->mbmaxlen;
1563
set_name(name_par, 0, cs);
1564
decimals=NOT_FIXED_DEC;
1565
// it is constant => can be used without fix_fields (and frequently used)
1569
This is used in stored procedures to avoid memory leaks and
1570
does a deep copy of its argument.
1572
void set_str_with_copy(const char *str_arg, uint length_arg)
1574
str_value.copy(str_arg, length_arg, collation.collation);
1575
max_length= str_value.numchars() * collation.collation->mbmaxlen;
1577
void set_repertoire_from_value()
1579
collation.repertoire= my_string_repertoire(str_value.charset(),
1581
str_value.length());
1583
enum Type type() const { return STRING_ITEM; }
1586
String *val_str(String*)
1589
return (String*) &str_value;
1591
my_decimal *val_decimal(my_decimal *);
1592
int save_in_field(Field *field, bool no_conversions);
1593
enum Item_result result_type () const { return STRING_RESULT; }
1594
enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
1595
bool basic_const_item() const { return 1; }
1596
bool eq(const Item *item, bool binary_cmp) const;
1599
return new Item_string(name, str_value.ptr(),
1600
str_value.length(), collation.collation);
1602
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1603
inline void append(char *str, uint length)
1605
str_value.append(str, length);
1606
max_length= str_value.numchars() * collation.collation->mbmaxlen;
1608
virtual void print(String *str, enum_query_type query_type);
1611
Return true if character-set-introducer was explicitly specified in the
1612
original query for this item (text literal).
1614
This operation is to be called from Item_string::print(). The idea is
1615
that when a query is generated (re-constructed) from the Item-tree,
1616
character-set-introducers should appear only for those literals, where
1617
they were explicitly specified by the user. Otherwise, that may lead to
1618
loss collation information (character set introducers implies default
1619
collation for the literal).
1621
Basically, that makes sense only for views and hopefully will be gone
1622
one day when we start using original query as a view definition.
1624
@return This operation returns the value of m_cs_specified attribute.
1625
@retval true if character set introducer was explicitly specified in
1627
@retval false otherwise.
1629
inline bool is_cs_specified() const
1631
return m_cs_specified;
1635
Set the value of m_cs_specified attribute.
1637
m_cs_specified attribute shows whether character-set-introducer was
1638
explicitly specified in the original query for this text literal or
1639
not. The attribute makes sense (is used) only for views.
1641
This operation is to be called from the parser during parsing an input
1644
inline void set_cs_specified(bool cs_specified)
1646
m_cs_specified= cs_specified;
1650
bool m_cs_specified;
1654
class Item_static_string_func :public Item_string
1656
const char *func_name;
1658
Item_static_string_func(const char *name_par, const char *str, uint length,
1659
const CHARSET_INFO * const cs,
1660
Derivation dv= DERIVATION_COERCIBLE)
1661
:Item_string(NullS, str, length, cs, dv), func_name(name_par)
1663
Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1665
virtual inline void print(String *str,
1666
enum_query_type query_type __attribute__((unused)))
1668
str->append(func_name);
1673
/* for show tables */
1674
class Item_return_date_time :public Item_string
1676
enum_field_types date_time_field_type;
1678
Item_return_date_time(const char *name_arg, enum_field_types field_type_arg)
1679
:Item_string(name_arg, 0, &my_charset_bin),
1680
date_time_field_type(field_type_arg)
1682
enum_field_types field_type() const { return date_time_field_type; }
1686
class Item_blob :public Item_string
1689
Item_blob(const char *name, uint length) :
1690
Item_string(name, length, &my_charset_bin)
1691
{ max_length= length; }
1692
enum Type type() const { return TYPE_HOLDER; }
1693
enum_field_types field_type() const { return DRIZZLE_TYPE_BLOB; }
1698
Item_empty_string -- is a utility class to put an item into List<Item>
1699
which is then used in protocol.send_fields() when sending SHOW output to
1703
class Item_empty_string :public Item_string
1706
Item_empty_string(const char *header,uint length, const CHARSET_INFO * cs= NULL) :
1707
Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
1708
{ name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
1709
void make_field(Send_field *field);
1713
class Item_return_int :public Item_int
1715
enum_field_types int_field_type;
1717
Item_return_int(const char *name_arg, uint length,
1718
enum_field_types field_type_arg, int64_t value= 0)
1719
:Item_int(name_arg, value, length), int_field_type(field_type_arg)
1723
enum_field_types field_type() const { return int_field_type; }
1727
class Item_hex_string: public Item_basic_constant
1730
Item_hex_string() {}
1731
Item_hex_string(const char *str,uint str_length);
1732
enum Type type() const { return VARBIN_ITEM; }
1736
return (double) (uint64_t) Item_hex_string::val_int();
1739
bool basic_const_item() const { return 1; }
1740
String *val_str(String*) { assert(fixed == 1); return &str_value; }
1741
my_decimal *val_decimal(my_decimal *);
1742
int save_in_field(Field *field, bool no_conversions);
1743
enum Item_result result_type () const { return STRING_RESULT; }
1744
enum Item_result cast_to_int_type() const { return INT_RESULT; }
1745
enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
1746
virtual void print(String *str, enum_query_type query_type);
1747
bool eq(const Item *item, bool binary_cmp) const;
1748
virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
1752
class Item_bin_string: public Item_hex_string
1755
Item_bin_string(const char *str,uint str_length);
1758
class Item_result_field :public Item /* Item with result field */
1761
Field *result_field; /* Save result here */
1762
Item_result_field() :result_field(0) {}
1763
// Constructor used for Item_sum/Item_cond_and/or (see Item comment)
1764
Item_result_field(THD *thd, Item_result_field *item):
1765
Item(thd, item), result_field(item->result_field)
1767
~Item_result_field() {} /* Required with gcc 2.95 */
1768
Field *get_tmp_table_field() { return result_field; }
1769
Field *tmp_table_field(Table *t_arg __attribute__((unused)))
1770
{ return result_field; }
1771
table_map used_tables() const { return 1; }
1772
virtual void fix_length_and_dec()=0;
1773
void set_result_field(Field *field) { result_field= field; }
1774
bool is_result_field() { return 1; }
1775
void save_in_result_field(bool no_conversions)
1777
save_in_field(result_field, no_conversions);
1783
class Item_ref :public Item_ident
1786
void set_properties();
1788
enum Ref_Type { REF, DIRECT_REF, VIEW_REF, OUTER_REF };
1789
Field *result_field; /* Save result here */
1791
Item_ref(Name_resolution_context *context_arg,
1792
const char *db_arg, const char *table_name_arg,
1793
const char *field_name_arg)
1794
:Item_ident(context_arg, db_arg, table_name_arg, field_name_arg),
1795
result_field(0), ref(0) {}
1797
This constructor is used in two scenarios:
1799
No initialization is performed, fix_fields() call will be necessary.
1801
B) *item points to an Item this Item_ref will refer to. This is
1802
used for GROUP BY. fix_fields() will not be called in this case,
1803
so we call set_properties to make this item "fixed". set_properties
1804
performs a subset of action Item_ref::fix_fields does, and this subset
1805
is enough for Item_ref's used in GROUP BY.
1807
TODO we probably fix a superset of problems like in BUG#6658. Check this
1808
with Bar, and if we have a more broader set of problems like this.
1810
Item_ref(Name_resolution_context *context_arg, Item **item,
1811
const char *table_name_arg, const char *field_name_arg,
1812
bool alias_name_used_arg= false);
1814
/* Constructor need to process subselect with temporary tables (see Item) */
1815
Item_ref(THD *thd, Item_ref *item)
1816
:Item_ident(thd, item), result_field(item->result_field), ref(item->ref) {}
1817
enum Type type() const { return REF_ITEM; }
1818
bool eq(const Item *item, bool binary_cmp) const
1820
Item *it= ((Item *) item)->real_item();
1821
return ref && (*ref)->eq(it, binary_cmp);
1825
my_decimal *val_decimal(my_decimal *);
1827
String *val_str(String* tmp);
1829
bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
1830
double val_result();
1831
int64_t val_int_result();
1832
String *str_result(String* tmp);
1833
my_decimal *val_decimal_result(my_decimal *);
1834
bool val_bool_result();
1835
bool send(Protocol *prot, String *tmp);
1836
void make_field(Send_field *field);
1837
bool fix_fields(THD *, Item **);
1838
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
1839
int save_in_field(Field *field, bool no_conversions);
1840
void save_org_in_field(Field *field);
1841
enum Item_result result_type () const { return (*ref)->result_type(); }
1842
enum_field_types field_type() const { return (*ref)->field_type(); }
1843
Field *get_tmp_table_field()
1844
{ return result_field ? result_field : (*ref)->get_tmp_table_field(); }
1845
Item *get_tmp_table_item(THD *thd);
1846
table_map used_tables() const
1848
return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
1850
void update_used_tables()
1853
(*ref)->update_used_tables();
1855
table_map not_null_tables() const { return (*ref)->not_null_tables(); }
1856
void set_result_field(Field *field) { result_field= field; }
1857
bool is_result_field() { return 1; }
1858
void save_in_result_field(bool no_conversions)
1860
(*ref)->save_in_field(result_field, no_conversions);
1864
return ref ? (*ref)->real_item() : this;
1866
bool walk(Item_processor processor, bool walk_subquery, uchar *arg)
1867
{ return (*ref)->walk(processor, walk_subquery, arg); }
1868
virtual void print(String *str, enum_query_type query_type);
1869
bool result_as_int64_t()
1871
return (*ref)->result_as_int64_t();
1874
Item_field *filed_for_view_update()
1875
{ return (*ref)->filed_for_view_update(); }
1876
virtual Ref_Type ref_type() { return REF; }
1878
// Row emulation: forwarding of ROW-related calls to ref
1881
return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
1883
Item* element_index(uint i)
1885
return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
1889
return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
1891
bool check_cols(uint c)
1893
return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
1894
: Item::check_cols(c);
1898
return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
1902
if (ref && result_type() == ROW_RESULT)
1903
(*ref)->bring_value();
1910
The same as Item_ref, but get value from val_* family of method to get
1911
value of item on which it referred instead of result* family.
1913
class Item_direct_ref :public Item_ref
1916
Item_direct_ref(Name_resolution_context *context_arg, Item **item,
1917
const char *table_name_arg,
1918
const char *field_name_arg,
1919
bool alias_name_used_arg= false)
1920
:Item_ref(context_arg, item, table_name_arg,
1921
field_name_arg, alias_name_used_arg)
1923
/* Constructor need to process subselect with temporary tables (see Item) */
1924
Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {}
1928
String *val_str(String* tmp);
1929
my_decimal *val_decimal(my_decimal *);
1932
bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
1933
virtual Ref_Type ref_type() { return DIRECT_REF; }
1937
Class for view fields, the same as Item_direct_ref, but call fix_fields
1938
of reference if it is not called yet
1940
class Item_direct_view_ref :public Item_direct_ref
1943
Item_direct_view_ref(Name_resolution_context *context_arg, Item **item,
1944
const char *table_name_arg,
1945
const char *field_name_arg)
1946
:Item_direct_ref(context_arg, item, table_name_arg, field_name_arg) {}
1947
/* Constructor need to process subselect with temporary tables (see Item) */
1948
Item_direct_view_ref(THD *thd, Item_direct_ref *item)
1949
:Item_direct_ref(thd, item) {}
1951
bool fix_fields(THD *, Item **);
1952
bool eq(const Item *item, bool binary_cmp) const;
1953
Item *get_tmp_table_item(THD *thd)
1955
Item *item= Item_ref::get_tmp_table_item(thd);
1959
virtual Ref_Type ref_type() { return VIEW_REF; }
1964
Class for outer fields.
1965
An object of this class is created when the select where the outer field was
1966
resolved is a grouping one. After it has been fixed the ref field will point
1967
to either an Item_ref or an Item_direct_ref object which will be used to
1969
See also comments for the fix_inner_refs() and the
1970
Item_field::fix_outer_field() functions.
1974
class Item_outer_ref :public Item_direct_ref
1978
/* The aggregate function under which this outer ref is used, if any. */
1979
Item_sum *in_sum_func;
1981
true <=> that the outer_ref is already present in the select list
1982
of the outer select.
1984
bool found_in_select_list;
1985
Item_outer_ref(Name_resolution_context *context_arg,
1986
Item_field *outer_field_arg)
1987
:Item_direct_ref(context_arg, 0, outer_field_arg->table_name,
1988
outer_field_arg->field_name),
1989
outer_ref(outer_field_arg), in_sum_func(0),
1990
found_in_select_list(0)
1996
Item_outer_ref(Name_resolution_context *context_arg, Item **item,
1997
const char *table_name_arg, const char *field_name_arg,
1998
bool alias_name_used_arg)
1999
:Item_direct_ref(context_arg, item, table_name_arg, field_name_arg,
2000
alias_name_used_arg),
2001
outer_ref(0), in_sum_func(0), found_in_select_list(1)
2003
void save_in_result_field(bool no_conversions __attribute__((unused)))
2005
outer_ref->save_org_in_field(result_field);
2007
bool fix_fields(THD *, Item **);
2008
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
2009
table_map used_tables() const
2011
return (*ref)->const_item() ? 0 : OUTER_REF_TABLE_BIT;
2013
virtual Ref_Type ref_type() { return OUTER_REF; }
2017
class Item_in_subselect;
2021
An object of this class:
2022
- Converts val_XXX() calls to ref->val_XXX_result() calls, like Item_ref.
2023
- Sets owner->was_null=true if it has returned a NULL value from any
2024
val_XXX() function. This allows to inject an Item_ref_null_helper
2025
object into subquery and then check if the subquery has produced a row
2029
class Item_ref_null_helper: public Item_ref
2032
Item_in_subselect* owner;
2034
Item_ref_null_helper(Name_resolution_context *context_arg,
2035
Item_in_subselect* master, Item **item,
2036
const char *table_name_arg, const char *field_name_arg)
2037
:Item_ref(context_arg, item, table_name_arg, field_name_arg),
2041
String* val_str(String* s);
2042
my_decimal *val_decimal(my_decimal *);
2044
bool get_date(DRIZZLE_TIME *ltime, uint fuzzydate);
2045
virtual void print(String *str, enum_query_type query_type);
2047
we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
2049
table_map used_tables() const
2051
return (depended_from ?
2052
OUTER_REF_TABLE_BIT :
2053
(*ref)->used_tables() | RAND_TABLE_BIT);
2058
The following class is used to optimize comparing of date and bigint columns
2059
We need to save the original item ('ref') to be able to call
2060
ref->save_in_field(). This is used to create index search keys.
2062
An instance of Item_int_with_ref may have signed or unsigned integer value.
2066
class Item_int_with_ref :public Item_int
2070
Item_int_with_ref(int64_t i, Item *ref_arg, bool unsigned_arg) :
2071
Item_int(i), ref(ref_arg)
2073
unsigned_flag= unsigned_arg;
2075
int save_in_field(Field *field, bool no_conversions)
2077
return ref->save_in_field(field, no_conversions);
2080
virtual Item *real_item() { return ref; }
2083
#ifdef DRIZZLE_SERVER
2084
#include "item_sum.h"
2085
#include "item_func.h"
2086
#include "item_row.h"
2087
#include "item_cmpfunc.h"
2088
#include "item_strfunc.h"
2089
#include "item_timefunc.h"
2090
#include "item_subselect.h"
2093
class Item_copy_string :public Item
2095
enum enum_field_types cached_field_type;
2098
Item_copy_string(Item *i) :item(i)
2100
null_value= maybe_null= item->maybe_null;
2101
decimals=item->decimals;
2102
max_length=item->max_length;
2104
cached_field_type= item->field_type();
2106
enum Type type() const { return COPY_STR_ITEM; }
2107
enum Item_result result_type () const { return STRING_RESULT; }
2108
enum_field_types field_type() const { return cached_field_type; }
2113
return (null_value ? 0.0 :
2114
my_strntod(str_value.charset(), (char*) str_value.ptr(),
2115
str_value.length(), &end_not_used, &err_not_used));
2120
return null_value ? 0LL : my_strntoll(str_value.charset(),str_value.ptr(),
2121
str_value.length(),10, (char**) 0,
2124
String *val_str(String*);
2125
my_decimal *val_decimal(my_decimal *);
2126
void make_field(Send_field *field) { item->make_field(field); }
2128
int save_in_field(Field *field,
2129
bool no_conversions __attribute__((unused)))
2131
return save_str_value_in_field(field, &str_value);
2133
table_map used_tables() const { return (table_map) 1L; }
2134
bool const_item() const { return 0; }
2135
bool is_null() { return null_value; }
2139
class Cached_item :public Sql_alloc
2143
Cached_item() :null_value(0) {}
2144
virtual bool cmp(void)=0;
2145
virtual ~Cached_item(); /*line -e1509 */
2148
class Cached_item_str :public Cached_item
2151
String value,tmp_value;
2153
Cached_item_str(THD *thd, Item *arg);
2155
~Cached_item_str(); // Deallocate String:s
2159
class Cached_item_real :public Cached_item
2164
Cached_item_real(Item *item_par) :item(item_par),value(0.0) {}
2168
class Cached_item_int :public Cached_item
2173
Cached_item_int(Item *item_par) :item(item_par),value(0) {}
2178
class Cached_item_decimal :public Cached_item
2183
Cached_item_decimal(Item *item_par);
2187
class Cached_item_field :public Cached_item
2194
Cached_item_field(Field *arg_field) : field(arg_field)
2197
/* TODO: take the memory allocation below out of the constructor. */
2198
buff= (uchar*) sql_calloc(length=field->pack_length());
2203
class Item_default_value : public Item_field
2207
Item_default_value(Name_resolution_context *context_arg)
2208
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
2209
(const char *)NULL),
2211
Item_default_value(Name_resolution_context *context_arg, Item *a)
2212
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
2213
(const char *)NULL),
2215
enum Type type() const { return DEFAULT_VALUE_ITEM; }
2216
bool eq(const Item *item, bool binary_cmp) const;
2217
bool fix_fields(THD *, Item **);
2218
virtual void print(String *str, enum_query_type query_type);
2219
int save_in_field(Field *field_arg, bool no_conversions);
2220
table_map used_tables() const { return (table_map)0L; }
2222
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2224
return arg->walk(processor, walk_subquery, args) ||
2225
(this->*processor)(args);
2228
Item *transform(Item_transformer transformer, uchar *args);
2232
Item_insert_value -- an implementation of VALUES() function.
2233
You can use the VALUES(col_name) function in the UPDATE clause
2234
to refer to column values from the INSERT portion of the INSERT
2235
... UPDATE statement. In other words, VALUES(col_name) in the
2236
UPDATE clause refers to the value of col_name that would be
2237
inserted, had no duplicate-key conflict occurred.
2238
In all other places this function returns NULL.
2241
class Item_insert_value : public Item_field
2245
Item_insert_value(Name_resolution_context *context_arg, Item *a)
2246
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
2247
(const char *)NULL),
2249
bool eq(const Item *item, bool binary_cmp) const;
2250
bool fix_fields(THD *, Item **);
2251
virtual void print(String *str, enum_query_type query_type);
2252
int save_in_field(Field *field_arg, bool no_conversions)
2254
return Item_field::save_in_field(field_arg, no_conversions);
2257
We use RAND_TABLE_BIT to prevent Item_insert_value from
2258
being treated as a constant and precalculated before execution
2260
table_map used_tables() const { return RAND_TABLE_BIT; }
2262
bool walk(Item_processor processor, bool walk_subquery, uchar *args)
2264
return arg->walk(processor, walk_subquery, args) ||
2265
(this->*processor)(args);
2270
class Item_cache: public Item_basic_constant
2274
table_map used_table_map;
2276
Field that this object will get value from. This is set/used by
2277
index-based subquery engines to detect and remove the equality injected
2278
by IN->EXISTS transformation.
2279
For all other uses of Item_cache, cached_field doesn't matter.
2281
Field *cached_field;
2282
enum enum_field_types cached_field_type;
2285
example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR)
2290
Item_cache(enum_field_types field_type_arg):
2291
example(0), used_table_map(0), cached_field(0), cached_field_type(field_type_arg)
2297
void set_used_tables(table_map map) { used_table_map= map; }
2299
virtual bool allocate(uint i __attribute__((unused)))
2301
virtual bool setup(Item *item)
2304
max_length= item->max_length;
2305
decimals= item->decimals;
2306
collation.set(item->collation);
2307
unsigned_flag= item->unsigned_flag;
2308
if (item->type() == FIELD_ITEM)
2309
cached_field= ((Item_field *)item)->field;
2312
virtual void store(Item *)= 0;
2313
enum Type type() const { return CACHE_ITEM; }
2314
enum_field_types field_type() const { return cached_field_type; }
2315
static Item_cache* get_cache(const Item *item);
2316
table_map used_tables() const { return used_table_map; }
2317
virtual void keep_array() {}
2318
virtual void print(String *str, enum_query_type query_type);
2319
bool eq_def(Field *field)
2321
return cached_field ? cached_field->eq_def (field) : false;
2323
bool eq(const Item *item,
2324
bool binary_cmp __attribute__((unused))) const
2326
return this == item;
2331
class Item_cache_int: public Item_cache
2336
Item_cache_int(): Item_cache(), value(0) {}
2337
Item_cache_int(enum_field_types field_type_arg):
2338
Item_cache(field_type_arg), value(0) {}
2340
void store(Item *item);
2341
void store(Item *item, int64_t val_arg);
2342
double val_real() { assert(fixed == 1); return (double) value; }
2343
int64_t val_int() { assert(fixed == 1); return value; }
2344
String* val_str(String *str);
2345
my_decimal *val_decimal(my_decimal *);
2346
enum Item_result result_type() const { return INT_RESULT; }
2347
bool result_as_int64_t() { return true; }
2351
class Item_cache_real: public Item_cache
2355
Item_cache_real(): Item_cache(), value(0) {}
2357
void store(Item *item);
2358
double val_real() { assert(fixed == 1); return value; }
2360
String* val_str(String *str);
2361
my_decimal *val_decimal(my_decimal *);
2362
enum Item_result result_type() const { return REAL_RESULT; }
2366
class Item_cache_decimal: public Item_cache
2369
my_decimal decimal_value;
2371
Item_cache_decimal(): Item_cache() {}
2373
void store(Item *item);
2376
String* val_str(String *str);
2377
my_decimal *val_decimal(my_decimal *);
2378
enum Item_result result_type() const { return DECIMAL_RESULT; }
2382
class Item_cache_str: public Item_cache
2384
char buffer[STRING_BUFFER_USUAL_SIZE];
2385
String *value, value_buff;
2389
Item_cache_str(const Item *item) :
2390
Item_cache(), value(0),
2391
is_varbinary(item->type() == FIELD_ITEM &&
2392
((const Item_field *) item)->field->type() ==
2393
DRIZZLE_TYPE_VARCHAR &&
2394
!((const Item_field *) item)->field->has_charset())
2396
void store(Item *item);
2399
String* val_str(String *) { assert(fixed == 1); return value; }
2400
my_decimal *val_decimal(my_decimal *);
2401
enum Item_result result_type() const { return STRING_RESULT; }
2402
const CHARSET_INFO *charset() const { return value->charset(); };
2403
int save_in_field(Field *field, bool no_conversions);
2406
class Item_cache_row: public Item_cache
2408
Item_cache **values;
2413
:Item_cache(), values(0), item_count(2), save_array(0) {}
2416
'allocate' used only in row transformer, to preallocate space for row
2419
bool allocate(uint num);
2421
'setup' is needed only by row => it not called by simple row subselect
2422
(only by IN subselect (in subselect optimizer))
2424
bool setup(Item *item);
2425
void store(Item *item);
2426
void illegal_method_call(const char *);
2427
void make_field(Send_field *)
2429
illegal_method_call((const char*)"make_field");
2433
illegal_method_call((const char*)"val");
2438
illegal_method_call((const char*)"val_int");
2441
String *val_str(String *)
2443
illegal_method_call((const char*)"val_str");
2446
my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
2448
illegal_method_call((const char*)"val_decimal");
2452
enum Item_result result_type() const { return ROW_RESULT; }
2454
uint cols() { return item_count; }
2455
Item *element_index(uint i) { return values[i]; }
2456
Item **addr(uint i) { return (Item **) (values + i); }
2457
bool check_cols(uint c);
2460
void keep_array() { save_array= 1; }
2463
Item_cache::cleanup();
2465
memset(values, 0, item_count*sizeof(Item**));
2474
Item_type_holder used to store type. name, length of Item for UNIONS &
2477
Item_type_holder do not need cleanup() because its time of live limited by
2478
single SP/PS execution.
2480
class Item_type_holder: public Item
2483
TYPELIB *enum_set_typelib;
2484
enum_field_types fld_type;
2486
void get_full_info(Item *item);
2488
/* It is used to count decimal precision in join_types */
2489
int prev_decimal_int_part;
2491
Item_type_holder(THD*, Item*);
2493
Item_result result_type() const;
2494
enum_field_types field_type() const { return fld_type; };
2495
enum Type type() const { return TYPE_HOLDER; }
2498
my_decimal *val_decimal(my_decimal *);
2499
String *val_str(String*);
2500
bool join_types(THD *thd, Item *);
2501
Field *make_field_by_type(Table *table);
2502
static uint32_t display_length(Item *item);
2503
static enum_field_types get_real_type(Item *);
2507
class st_select_lex;
2508
void mark_select_range_as_dependent(THD *thd,
609
2509
st_select_lex *last_select,
610
2510
st_select_lex *current_sel,
611
2511
Field *found_field, Item *found_item,
612
2512
Item_ident *resolved_item);
614
extern void resolve_const_item(Session *session, Item **ref, Item *cmp_item);
2514
extern Cached_item *new_Cached_item(THD *thd, Item *item,
2515
bool use_result_field);
2516
extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
615
2517
extern bool field_is_equal_to_item(Field *field,Item *item);
618
Create field for temporary table.
620
@param session Thread handler
621
@param table Temporary table
622
@param item Item to create a field for
623
@param type Type of item (normally item->type)
624
@param copy_func If set and item is a function, store copy of item
626
@param from_field if field will be created using other field as example,
627
pointer example field will be written here
628
@param default_field If field has a default value field, store it here
629
@param group 1 if we are going to do a relative group by on result
630
@param modify_item 1 if item->result_field should point to new item.
631
This is relevent for how fill_record() is going to
633
If modify_item is 1 then fill_record() will update
634
the record in the original table.
635
If modify_item is 0 then fill_record() will update
637
@param convert_blob_length If >0 create a varstring(convert_blob_length)
638
field instead of blob.
646
/* TODO: This is here for now because it needs the Item::Type. It should live
647
in Field or Table once item.h is clean enough to actually include */
648
Field *create_tmp_field(Session *session, Table *table, Item *item,
650
Item ***copy_func, Field **from_field,
652
bool group, bool modify_item,
653
bool table_cant_handle_bit_fields,
654
bool make_copy_field,
655
uint32_t convert_blob_length);
657
#endif /* DRIZZLED_ITEM_H */