33
#include <drizzled/functions/func.h>
34
#include <drizzled/functions/additive_op.h>
35
#include <drizzled/functions/connection_id.h>
36
#include <drizzled/functions/decimal_typecast.h>
37
#include <drizzled/functions/divide.h>
38
#include <drizzled/functions/get_system_var.h>
39
#include <drizzled/functions/int.h>
40
#include <drizzled/functions/bit.h>
41
#include <drizzled/functions/bit_count.h>
42
#include <drizzled/functions/bit_length.h>
43
#include <drizzled/functions/field.h>
44
#include <drizzled/functions/find_in_set.h>
45
#include <drizzled/functions/found_rows.h>
46
#include <drizzled/functions/get_user_var.h>
47
#include <drizzled/functions/get_variable.h>
48
#include <drizzled/functions/integer.h>
49
#include <drizzled/functions/int_divide.h>
50
#include <drizzled/functions/length.h>
51
#include <drizzled/functions/lock.h>
52
#include <drizzled/functions/master_pos_wait.h>
53
#include <drizzled/functions/min_max.h>
54
#include <drizzled/functions/minus.h>
55
#include <drizzled/functions/mod.h>
56
#include <drizzled/functions/multiply.h>
57
#include <drizzled/functions/neg.h>
58
#include <drizzled/functions/numhybrid.h>
59
#include <drizzled/functions/num_op.h>
60
#include <drizzled/functions/num1.h>
61
#include <drizzled/functions/abs.h>
62
#include <drizzled/functions/plus.h>
63
#include <drizzled/functions/real.h>
64
#include <drizzled/functions/rollup_const.h>
65
#include <drizzled/functions/row_count.h>
66
#include <drizzled/functions/set_user_var.h>
67
#include <drizzled/functions/dec.h>
68
#include <drizzled/functions/int_val.h>
69
#include <drizzled/functions/acos.h>
70
#include <drizzled/functions/ascii.h>
71
#include <drizzled/functions/asin.h>
72
#include <drizzled/functions/atan.h>
73
#include <drizzled/functions/benchmark.h>
74
#include <drizzled/functions/char_length.h>
75
#include <drizzled/functions/ceiling.h>
76
#include <drizzled/functions/cos.h>
77
#include <drizzled/functions/exp.h>
78
#include <drizzled/functions/floor.h>
79
#include <drizzled/functions/last_insert.h>
80
#include <drizzled/functions/ln.h>
81
#include <drizzled/functions/log.h>
82
#include <drizzled/functions/units.h>
83
#include <drizzled/functions/ord.h>
84
#include <drizzled/functions/pow.h>
85
#include <drizzled/functions/rand.h>
86
#include <drizzled/functions/round.h>
87
#include <drizzled/functions/sin.h>
88
#include <drizzled/functions/sqrt.h>
89
#include <drizzled/functions/sign.h>
90
#include <drizzled/functions/signed.h>
91
#include <drizzled/functions/tan.h>
92
#include <drizzled/functions/update_hash.h>
93
#include <drizzled/functions/user_var_as_out_param.h>
94
#include <drizzled/functions/unsigned.h>
32
class Item_func :public Item_result_field
35
Item **args, *tmp_arg[2];
37
Allowed numbers of columns in result (usually 1, which means scalar value)
38
0 means get this number from first argument
40
uint allowed_arg_cols;
43
table_map used_tables_cache, not_null_tables_cache;
44
bool const_item_cache;
45
enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC,
47
LIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC,
48
COND_AND_FUNC, COND_OR_FUNC, COND_XOR_FUNC,
49
BETWEEN, IN_FUNC, MULT_EQUAL_FUNC,
50
INTERVAL_FUNC, ISNOTNULLTEST_FUNC,
51
NOT_FUNC, NOT_ALL_FUNC,
52
NOW_FUNC, TRIG_COND_FUNC,
53
SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC,
54
EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP, UDF_FUNC,
56
enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL,
58
enum Type type() const { return FUNC_ITEM; }
59
virtual enum Functype functype() const { return UNKNOWN_FUNC; }
61
allowed_arg_cols(1), arg_count(0)
66
allowed_arg_cols(1), arg_count(1)
70
with_sum_func= a->with_sum_func;
72
Item_func(Item *a,Item *b):
73
allowed_arg_cols(1), arg_count(2)
76
args[0]= a; args[1]= b;
77
with_sum_func= a->with_sum_func || b->with_sum_func;
79
Item_func(Item *a,Item *b,Item *c):
83
if ((args= (Item**) sql_alloc(sizeof(Item*)*3)))
86
args[0]= a; args[1]= b; args[2]= c;
87
with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
90
Item_func(Item *a,Item *b,Item *c,Item *d):
94
if ((args= (Item**) sql_alloc(sizeof(Item*)*4)))
97
args[0]= a; args[1]= b; args[2]= c; args[3]= d;
98
with_sum_func= a->with_sum_func || b->with_sum_func ||
99
c->with_sum_func || d->with_sum_func;
102
Item_func(Item *a,Item *b,Item *c,Item *d,Item* e):
106
if ((args= (Item**) sql_alloc(sizeof(Item*)*5)))
108
args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= e;
109
with_sum_func= a->with_sum_func || b->with_sum_func ||
110
c->with_sum_func || d->with_sum_func || e->with_sum_func ;
113
Item_func(List<Item> &list);
114
// Constructor used for Item_cond_and/or (see Item comment)
115
Item_func(THD *thd, Item_func *item);
116
bool fix_fields(THD *, Item **ref);
117
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
118
table_map used_tables() const;
119
table_map not_null_tables() const;
120
void update_used_tables();
121
bool eq(const Item *item, bool binary_cmp) const;
122
virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; }
123
virtual bool have_rev_func() const { return 0; }
124
virtual Item *key_item() const { return args[0]; }
126
This method is used for debug purposes to print the name of an
127
item to the debug log. The second use of this method is as
128
a helper function of print(), where it is applicable.
129
To suit both goals it should return a meaningful,
130
distinguishable and sintactically correct string. This method
131
should not be used for runtime type identification, use enum
132
{Sum}Functype and Item_func::functype()/Item_sum::sum_func()
135
virtual const char *func_name() const= 0;
136
virtual bool const_item() const { return const_item_cache; }
137
inline Item **arguments() const { return args; }
138
void set_arguments(List<Item> &list);
139
inline uint argument_count() const { return arg_count; }
140
inline void remove_arguments() { arg_count=0; }
141
void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields);
142
virtual void print(String *str, enum_query_type query_type);
143
void print_op(String *str, enum_query_type query_type);
144
void print_args(String *str, uint from, enum_query_type query_type);
145
virtual void fix_num_length_and_dec();
146
void count_only_length();
147
void count_real_length();
148
void count_decimal_length();
149
inline bool get_arg0_date(DRIZZLE_TIME *ltime, uint fuzzy_date)
151
return (null_value=args[0]->get_date(ltime, fuzzy_date));
153
inline bool get_arg0_time(DRIZZLE_TIME *ltime)
155
return (null_value=args[0]->get_time(ltime));
161
void signal_divide_by_null();
162
friend class udf_handler;
163
Field *tmp_table_field() { return result_field; }
164
Field *tmp_table_field(Table *t_arg);
165
Item *get_tmp_table_item(THD *thd);
167
my_decimal *val_decimal(my_decimal *);
169
bool agg_arg_collations(DTCollation &c, Item **items, uint nitems,
172
return agg_item_collations(c, func_name(), items, nitems, flags, 1);
174
bool agg_arg_collations_for_comparison(DTCollation &c,
175
Item **items, uint nitems,
178
return agg_item_collations_for_comparison(c, func_name(),
179
items, nitems, flags);
181
bool agg_arg_charsets(DTCollation &c, Item **items, uint nitems,
182
uint flags, int item_sep)
184
return agg_item_charsets(c, func_name(), items, nitems, flags, item_sep);
186
bool walk(Item_processor processor, bool walk_subquery, uchar *arg);
187
Item *transform(Item_transformer transformer, uchar *arg);
188
Item* compile(Item_analyzer analyzer, uchar **arg_p,
189
Item_transformer transformer, uchar *arg_t);
190
void traverse_cond(Cond_traverser traverser,
191
void * arg, traverse_order order);
192
inline double fix_result(double value)
202
class Item_real_func :public Item_func
205
Item_real_func() :Item_func() {}
206
Item_real_func(Item *a) :Item_func(a) {}
207
Item_real_func(Item *a,Item *b) :Item_func(a,b) {}
208
Item_real_func(List<Item> &list) :Item_func(list) {}
209
String *val_str(String*str);
210
my_decimal *val_decimal(my_decimal *decimal_value);
212
{ assert(fixed == 1); return (int64_t) rint(val_real()); }
213
enum Item_result result_type () const { return REAL_RESULT; }
214
void fix_length_and_dec()
215
{ decimals= NOT_FIXED_DEC; max_length= float_length(decimals); }
219
class Item_func_numhybrid: public Item_func
222
Item_result hybrid_type;
224
Item_func_numhybrid(Item *a) :Item_func(a), hybrid_type(REAL_RESULT)
226
Item_func_numhybrid(Item *a,Item *b)
227
:Item_func(a,b), hybrid_type(REAL_RESULT)
229
Item_func_numhybrid(List<Item> &list)
230
:Item_func(list), hybrid_type(REAL_RESULT)
233
enum Item_result result_type () const { return hybrid_type; }
234
void fix_length_and_dec();
235
void fix_num_length_and_dec();
236
virtual void find_num_type()= 0; /* To be called from fix_length_and_dec */
240
my_decimal *val_decimal(my_decimal *);
241
String *val_str(String*str);
244
@brief Performs the operation that this functions implements when the
247
@return The result of the operation.
249
virtual int64_t int_op()= 0;
252
@brief Performs the operation that this functions implements when the
255
@return The result of the operation.
257
virtual double real_op()= 0;
260
@brief Performs the operation that this functions implements when the
261
result type is DECIMAL.
263
@param A pointer where the DECIMAL value will be allocated.
265
- 0 If the result is NULL
266
- The same pointer it was given, with the area initialized to the
267
result of the operation.
269
virtual my_decimal *decimal_op(my_decimal *)= 0;
272
@brief Performs the operation that this functions implements when the
273
result type is a string type.
275
@return The result of the operation.
277
virtual String *str_op(String *)= 0;
278
bool is_null() { update_null_value(); return null_value; }
281
/* function where type of result detected by first argument */
282
class Item_func_num1: public Item_func_numhybrid
285
Item_func_num1(Item *a) :Item_func_numhybrid(a) {}
286
Item_func_num1(Item *a, Item *b) :Item_func_numhybrid(a, b) {}
288
void fix_num_length_and_dec();
289
void find_num_type();
290
String *str_op(String *str __attribute__((unused)))
291
{ assert(0); return 0; }
295
/* Base class for operations like '+', '-', '*' */
296
class Item_num_op :public Item_func_numhybrid
299
Item_num_op(Item *a,Item *b) :Item_func_numhybrid(a, b) {}
300
virtual void result_precision()= 0;
302
virtual inline void print(String *str, enum_query_type query_type)
304
print_op(str, query_type);
307
void find_num_type();
308
String *str_op(String *str __attribute__((unused)))
309
{ assert(0); return 0; }
313
class Item_int_func :public Item_func
316
Item_int_func() :Item_func() { max_length= 21; }
317
Item_int_func(Item *a) :Item_func(a) { max_length= 21; }
318
Item_int_func(Item *a,Item *b) :Item_func(a,b) { max_length= 21; }
319
Item_int_func(Item *a,Item *b,Item *c) :Item_func(a,b,c)
321
Item_int_func(List<Item> &list) :Item_func(list) { max_length= 21; }
322
Item_int_func(THD *thd, Item_int_func *item) :Item_func(thd, item) {}
324
String *val_str(String*str);
325
enum Item_result result_type () const { return INT_RESULT; }
326
void fix_length_and_dec() {}
330
class Item_func_connection_id :public Item_int_func
335
Item_func_connection_id() {}
336
const char *func_name() const { return "connection_id"; }
337
void fix_length_and_dec();
338
bool fix_fields(THD *thd, Item **ref);
339
int64_t val_int() { assert(fixed == 1); return value; }
343
class Item_func_signed :public Item_int_func
346
Item_func_signed(Item *a) :Item_int_func(a) {}
347
const char *func_name() const { return "cast_as_signed"; }
349
int64_t val_int_from_str(int *error);
350
void fix_length_and_dec()
351
{ max_length=args[0]->max_length; unsigned_flag=0; }
352
virtual void print(String *str, enum_query_type query_type);
353
uint decimal_precision() const { return args[0]->decimal_precision(); }
357
class Item_func_unsigned :public Item_func_signed
360
Item_func_unsigned(Item *a) :Item_func_signed(a) {}
361
const char *func_name() const { return "cast_as_unsigned"; }
362
void fix_length_and_dec()
363
{ max_length=args[0]->max_length; unsigned_flag=1; }
365
virtual void print(String *str, enum_query_type query_type);
369
class Item_decimal_typecast :public Item_func
371
my_decimal decimal_value;
373
Item_decimal_typecast(Item *a, int len, int dec) :Item_func(a)
376
max_length= my_decimal_precision_to_length(len, dec, unsigned_flag);
378
String *val_str(String *str);
381
my_decimal *val_decimal(my_decimal*);
382
enum Item_result result_type () const { return DECIMAL_RESULT; }
383
enum_field_types field_type() const { return DRIZZLE_TYPE_NEWDECIMAL; }
384
void fix_length_and_dec() {};
385
const char *func_name() const { return "decimal_typecast"; }
386
virtual void print(String *str, enum_query_type query_type);
390
class Item_func_additive_op :public Item_num_op
393
Item_func_additive_op(Item *a,Item *b) :Item_num_op(a,b) {}
394
void result_precision();
398
class Item_func_plus :public Item_func_additive_op
401
Item_func_plus(Item *a,Item *b) :Item_func_additive_op(a,b) {}
402
const char *func_name() const { return "+"; }
405
my_decimal *decimal_op(my_decimal *);
408
class Item_func_minus :public Item_func_additive_op
411
Item_func_minus(Item *a,Item *b) :Item_func_additive_op(a,b) {}
412
const char *func_name() const { return "-"; }
415
my_decimal *decimal_op(my_decimal *);
416
void fix_length_and_dec();
420
class Item_func_mul :public Item_num_op
423
Item_func_mul(Item *a,Item *b) :Item_num_op(a,b) {}
424
const char *func_name() const { return "*"; }
427
my_decimal *decimal_op(my_decimal *);
428
void result_precision();
432
class Item_func_div :public Item_num_op
436
Item_func_div(Item *a,Item *b) :Item_num_op(a,b) {}
437
int64_t int_op() { assert(0); return 0; }
439
my_decimal *decimal_op(my_decimal *);
440
const char *func_name() const { return "/"; }
441
void fix_length_and_dec();
442
void result_precision();
446
class Item_func_int_div :public Item_int_func
449
Item_func_int_div(Item *a,Item *b) :Item_int_func(a,b)
452
const char *func_name() const { return "DIV"; }
453
void fix_length_and_dec();
455
virtual inline void print(String *str, enum_query_type query_type)
457
print_op(str, query_type);
463
class Item_func_mod :public Item_num_op
466
Item_func_mod(Item *a,Item *b) :Item_num_op(a,b) {}
469
my_decimal *decimal_op(my_decimal *);
470
const char *func_name() const { return "%"; }
471
void result_precision();
472
void fix_length_and_dec();
476
class Item_func_neg :public Item_func_num1
479
Item_func_neg(Item *a) :Item_func_num1(a) {}
482
my_decimal *decimal_op(my_decimal *);
483
const char *func_name() const { return "-"; }
484
enum Functype functype() const { return NEG_FUNC; }
485
void fix_length_and_dec();
486
void fix_num_length_and_dec();
487
uint decimal_precision() const { return args[0]->decimal_precision(); }
491
class Item_func_abs :public Item_func_num1
494
Item_func_abs(Item *a) :Item_func_num1(a) {}
497
my_decimal *decimal_op(my_decimal *);
498
const char *func_name() const { return "abs"; }
499
void fix_length_and_dec();
502
// A class to handle logarithmic and trigonometric functions
504
class Item_dec_func :public Item_real_func
507
Item_dec_func(Item *a) :Item_real_func(a) {}
508
Item_dec_func(Item *a,Item *b) :Item_real_func(a,b) {}
509
void fix_length_and_dec()
511
decimals=NOT_FIXED_DEC; max_length=float_length(decimals);
516
class Item_func_exp :public Item_dec_func
519
Item_func_exp(Item *a) :Item_dec_func(a) {}
521
const char *func_name() const { return "exp"; }
525
class Item_func_ln :public Item_dec_func
528
Item_func_ln(Item *a) :Item_dec_func(a) {}
530
const char *func_name() const { return "ln"; }
534
class Item_func_log :public Item_dec_func
537
Item_func_log(Item *a) :Item_dec_func(a) {}
538
Item_func_log(Item *a,Item *b) :Item_dec_func(a,b) {}
540
const char *func_name() const { return "log"; }
544
class Item_func_log2 :public Item_dec_func
547
Item_func_log2(Item *a) :Item_dec_func(a) {}
549
const char *func_name() const { return "log2"; }
553
class Item_func_log10 :public Item_dec_func
556
Item_func_log10(Item *a) :Item_dec_func(a) {}
558
const char *func_name() const { return "log10"; }
562
class Item_func_sqrt :public Item_dec_func
565
Item_func_sqrt(Item *a) :Item_dec_func(a) {}
567
const char *func_name() const { return "sqrt"; }
571
class Item_func_pow :public Item_dec_func
574
Item_func_pow(Item *a,Item *b) :Item_dec_func(a,b) {}
576
const char *func_name() const { return "pow"; }
580
class Item_func_acos :public Item_dec_func
583
Item_func_acos(Item *a) :Item_dec_func(a) {}
585
const char *func_name() const { return "acos"; }
588
class Item_func_asin :public Item_dec_func
591
Item_func_asin(Item *a) :Item_dec_func(a) {}
593
const char *func_name() const { return "asin"; }
596
class Item_func_atan :public Item_dec_func
599
Item_func_atan(Item *a) :Item_dec_func(a) {}
600
Item_func_atan(Item *a,Item *b) :Item_dec_func(a,b) {}
602
const char *func_name() const { return "atan"; }
605
class Item_func_cos :public Item_dec_func
608
Item_func_cos(Item *a) :Item_dec_func(a) {}
610
const char *func_name() const { return "cos"; }
613
class Item_func_sin :public Item_dec_func
616
Item_func_sin(Item *a) :Item_dec_func(a) {}
618
const char *func_name() const { return "sin"; }
621
class Item_func_tan :public Item_dec_func
624
Item_func_tan(Item *a) :Item_dec_func(a) {}
626
const char *func_name() const { return "tan"; }
629
class Item_func_integer :public Item_int_func
632
inline Item_func_integer(Item *a) :Item_int_func(a) {}
633
void fix_length_and_dec();
637
class Item_func_int_val :public Item_func_num1
640
Item_func_int_val(Item *a) :Item_func_num1(a) {}
641
void fix_num_length_and_dec();
642
void find_num_type();
646
class Item_func_ceiling :public Item_func_int_val
649
Item_func_ceiling(Item *a) :Item_func_int_val(a) {}
650
const char *func_name() const { return "ceiling"; }
653
my_decimal *decimal_op(my_decimal *);
657
class Item_func_floor :public Item_func_int_val
660
Item_func_floor(Item *a) :Item_func_int_val(a) {}
661
const char *func_name() const { return "floor"; }
664
my_decimal *decimal_op(my_decimal *);
667
/* This handles round and truncate */
669
class Item_func_round :public Item_func_num1
673
Item_func_round(Item *a, Item *b, bool trunc_arg)
674
:Item_func_num1(a,b), truncate(trunc_arg) {}
675
const char *func_name() const { return truncate ? "truncate" : "round"; }
678
my_decimal *decimal_op(my_decimal *);
679
void fix_length_and_dec();
683
class Item_func_rand :public Item_real_func
685
struct rand_struct *rand;
687
Item_func_rand(Item *a) :Item_real_func(a), rand(0) {}
688
Item_func_rand() :Item_real_func() {}
690
const char *func_name() const { return "rand"; }
691
bool const_item() const { return 0; }
692
void update_used_tables();
693
bool fix_fields(THD *thd, Item **ref);
695
void seed_random (Item * val);
699
class Item_func_sign :public Item_int_func
702
Item_func_sign(Item *a) :Item_int_func(a) {}
703
const char *func_name() const { return "sign"; }
708
class Item_func_units :public Item_real_func
713
Item_func_units(char *name_arg,Item *a,double mul_arg,double add_arg)
714
:Item_real_func(a),name(name_arg),mul(mul_arg),add(add_arg) {}
716
const char *func_name() const { return name; }
717
void fix_length_and_dec()
718
{ decimals= NOT_FIXED_DEC; max_length= float_length(decimals); }
722
class Item_func_min_max :public Item_func
724
Item_result cmp_type;
727
/* TRUE <=> arguments should be compared in the DATETIME context. */
728
bool compare_as_dates;
729
/* An item used for issuing warnings while string to DATETIME conversion. */
733
enum_field_types cached_field_type;
735
Item_func_min_max(List<Item> &list,int cmp_sign_arg) :Item_func(list),
736
cmp_type(INT_RESULT), cmp_sign(cmp_sign_arg), compare_as_dates(false),
740
String *val_str(String *);
741
my_decimal *val_decimal(my_decimal *);
742
void fix_length_and_dec();
743
enum Item_result result_type () const { return cmp_type; }
744
bool result_as_int64_t() { return compare_as_dates; };
745
uint cmp_datetimes(uint64_t *value);
746
enum_field_types field_type() const { return cached_field_type; }
749
class Item_func_min :public Item_func_min_max
752
Item_func_min(List<Item> &list) :Item_func_min_max(list,1) {}
753
const char *func_name() const { return "least"; }
756
class Item_func_max :public Item_func_min_max
759
Item_func_max(List<Item> &list) :Item_func_min_max(list,-1) {}
760
const char *func_name() const { return "greatest"; }
765
Objects of this class are used for ROLLUP queries to wrap up
766
each constant item referred to in GROUP BY list.
769
class Item_func_rollup_const :public Item_func
772
Item_func_rollup_const(Item *a) :Item_func(a)
775
name_length= a->name_length;
777
double val_real() { return args[0]->val_real(); }
778
int64_t val_int() { return args[0]->val_int(); }
779
String *val_str(String *str) { return args[0]->val_str(str); }
780
my_decimal *val_decimal(my_decimal *dec) { return args[0]->val_decimal(dec); }
781
const char *func_name() const { return "rollup_const"; }
782
bool const_item() const { return 0; }
783
Item_result result_type() const { return args[0]->result_type(); }
784
void fix_length_and_dec()
786
collation= args[0]->collation;
787
max_length= args[0]->max_length;
788
decimals=args[0]->decimals;
789
/* The item could be a NULL constant. */
790
null_value= args[0]->is_null();
795
class Item_func_length :public Item_int_func
799
Item_func_length(Item *a) :Item_int_func(a) {}
801
const char *func_name() const { return "length"; }
802
void fix_length_and_dec() { max_length=10; }
805
class Item_func_bit_length :public Item_func_length
808
Item_func_bit_length(Item *a) :Item_func_length(a) {}
810
{ assert(fixed == 1); return Item_func_length::val_int()*8; }
811
const char *func_name() const { return "bit_length"; }
814
class Item_func_char_length :public Item_int_func
818
Item_func_char_length(Item *a) :Item_int_func(a) {}
820
const char *func_name() const { return "char_length"; }
821
void fix_length_and_dec() { max_length=10; }
824
class Item_func_coercibility :public Item_int_func
827
Item_func_coercibility(Item *a) :Item_int_func(a) {}
829
const char *func_name() const { return "coercibility"; }
830
void fix_length_and_dec() { max_length=10; maybe_null= 0; }
831
table_map not_null_tables() const { return 0; }
834
class Item_func_locate :public Item_int_func
836
String value1,value2;
837
DTCollation cmp_collation;
839
Item_func_locate(Item *a,Item *b) :Item_int_func(a,b) {}
840
Item_func_locate(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {}
841
const char *func_name() const { return "locate"; }
843
void fix_length_and_dec();
844
virtual void print(String *str, enum_query_type query_type);
848
class Item_func_field :public Item_int_func
851
Item_result cmp_type;
852
DTCollation cmp_collation;
854
Item_func_field(List<Item> &list) :Item_int_func(list) {}
856
const char *func_name() const { return "field"; }
857
void fix_length_and_dec();
861
class Item_func_ascii :public Item_int_func
865
Item_func_ascii(Item *a) :Item_int_func(a) {}
867
const char *func_name() const { return "ascii"; }
868
void fix_length_and_dec() { max_length=3; }
871
class Item_func_ord :public Item_int_func
875
Item_func_ord(Item *a) :Item_int_func(a) {}
877
const char *func_name() const { return "ord"; }
880
class Item_func_find_in_set :public Item_int_func
885
DTCollation cmp_collation;
887
Item_func_find_in_set(Item *a,Item *b) :Item_int_func(a,b),enum_value(0) {}
889
const char *func_name() const { return "find_in_set"; }
890
void fix_length_and_dec();
893
/* Base class for all bit functions: '~', '|', '^', '&', '>>', '<<' */
895
class Item_func_bit: public Item_int_func
898
Item_func_bit(Item *a, Item *b) :Item_int_func(a, b) {}
899
Item_func_bit(Item *a) :Item_int_func(a) {}
900
void fix_length_and_dec() { unsigned_flag= 1; }
902
virtual inline void print(String *str, enum_query_type query_type)
904
print_op(str, query_type);
908
class Item_func_bit_or :public Item_func_bit
911
Item_func_bit_or(Item *a, Item *b) :Item_func_bit(a, b) {}
913
const char *func_name() const { return "|"; }
916
class Item_func_bit_and :public Item_func_bit
919
Item_func_bit_and(Item *a, Item *b) :Item_func_bit(a, b) {}
921
const char *func_name() const { return "&"; }
924
class Item_func_bit_count :public Item_int_func
927
Item_func_bit_count(Item *a) :Item_int_func(a) {}
929
const char *func_name() const { return "bit_count"; }
930
void fix_length_and_dec() { max_length=2; }
933
class Item_func_shift_left :public Item_func_bit
936
Item_func_shift_left(Item *a, Item *b) :Item_func_bit(a, b) {}
938
const char *func_name() const { return "<<"; }
941
class Item_func_shift_right :public Item_func_bit
944
Item_func_shift_right(Item *a, Item *b) :Item_func_bit(a, b) {}
946
const char *func_name() const { return ">>"; }
949
class Item_func_bit_neg :public Item_func_bit
952
Item_func_bit_neg(Item *a) :Item_func_bit(a) {}
954
const char *func_name() const { return "~"; }
956
virtual inline void print(String *str, enum_query_type query_type)
958
Item_func::print(str, query_type);
963
class Item_func_last_insert_id :public Item_int_func
966
Item_func_last_insert_id() :Item_int_func() {}
967
Item_func_last_insert_id(Item *a) :Item_int_func(a) {}
969
const char *func_name() const { return "last_insert_id"; }
970
void fix_length_and_dec()
973
max_length= args[0]->max_length;
975
bool fix_fields(THD *thd, Item **ref);
979
class Item_func_benchmark :public Item_int_func
982
Item_func_benchmark(Item *count_expr, Item *expr)
983
:Item_int_func(count_expr, expr)
986
const char *func_name() const { return "benchmark"; }
987
void fix_length_and_dec() { max_length=1; maybe_null=0; }
988
virtual void print(String *str, enum_query_type query_type);
992
class Item_udf_func :public Item_func
996
bool is_expensive_processor(uchar *arg __attribute__((unused)))
1000
Item_udf_func(udf_func *udf_arg)
1001
:Item_func(), udf(udf_arg) {}
1002
Item_udf_func(udf_func *udf_arg, List<Item> &list)
1003
:Item_func(list), udf(udf_arg) {}
1004
const char *func_name() const { return udf.name(); }
1005
enum Functype functype() const { return UDF_FUNC; }
1006
bool fix_fields(THD *thd, Item **ref __attribute__((unused)))
1009
bool res= udf.fix_fields(thd, this, arg_count, args);
1010
used_tables_cache= udf.used_tables_cache;
1011
const_item_cache= udf.const_item_cache;
1015
void update_used_tables()
1018
TODO: Make a member in UDF_INIT and return if a UDF is deterministic or
1020
Currently UDF_INIT has a member (const_item) that is an in/out
1021
parameter to the init() call.
1022
The code in udf_handler::fix_fields also duplicates the arguments
1023
handling code in Item_func::fix_fields().
1025
The lack of information if a UDF is deterministic makes writing
1026
a correct update_used_tables() for UDFs impossible.
1027
One solution to this would be :
1028
- Add a is_deterministic member of UDF_INIT
1029
- (optionally) deprecate the const_item member of UDF_INIT
1030
- Take away the duplicate code from udf_handler::fix_fields() and
1031
make Item_udf_func call Item_func::fix_fields() to process its
1032
arguments as for any other function.
1033
- Store the deterministic flag returned by <udf>_init into the
1035
- Don't implement Item_udf_func::fix_fields, implement
1036
Item_udf_func::fix_length_and_dec() instead (similar to non-UDF
1038
- Override Item_func::update_used_tables to call
1039
Item_func::update_used_tables() and add a RAND_TABLE_BIT to the
1040
result of Item_func::update_used_tables() if the UDF is
1042
- (optionally) rename RAND_TABLE_BIT to NONDETERMINISTIC_BIT to
1043
better describe its usage.
1045
The above would require a change of the UDF API.
1046
Until that change is done here's how the current code works:
1047
We call Item_func::update_used_tables() only when we know that
1048
the function depends on real non-const tables and is deterministic.
1049
This can be done only because we know that the optimizer will
1050
call update_used_tables() only when there's possibly a new const
1051
table. So update_used_tables() can only make a Item_func more
1052
constant than it is currently.
1053
That's why we don't need to do anything if a function is guaranteed
1054
to return non-constant (it's non-deterministic) or is already a
1057
if ((used_tables_cache & ~PSEUDO_TABLE_BITS) &&
1058
!(used_tables_cache & RAND_TABLE_BIT))
1060
Item_func::update_used_tables();
1061
if (!const_item_cache && !used_tables_cache)
1062
used_tables_cache= RAND_TABLE_BIT;
1066
Item_result result_type () const { return udf.result_type(); }
1067
table_map not_null_tables() const { return 0; }
1068
virtual void print(String *str, enum_query_type query_type);
1072
class Item_func_udf_float :public Item_udf_func
1075
Item_func_udf_float(udf_func *udf_arg)
1076
:Item_udf_func(udf_arg) {}
1077
Item_func_udf_float(udf_func *udf_arg,
1079
:Item_udf_func(udf_arg, list) {}
1083
return (int64_t) rint(Item_func_udf_float::val_real());
1085
my_decimal *val_decimal(my_decimal *dec_buf)
1087
double res=val_real();
1090
double2my_decimal(E_DEC_FATAL_ERROR, res, dec_buf);
1094
String *val_str(String *str);
1095
void fix_length_and_dec() { fix_num_length_and_dec(); }
1099
class Item_func_udf_int :public Item_udf_func
1102
Item_func_udf_int(udf_func *udf_arg)
1103
:Item_udf_func(udf_arg) {}
1104
Item_func_udf_int(udf_func *udf_arg,
1106
:Item_udf_func(udf_arg, list) {}
1108
double val_real() { return (double) Item_func_udf_int::val_int(); }
1109
String *val_str(String *str);
1110
enum Item_result result_type () const { return INT_RESULT; }
1111
void fix_length_and_dec() { decimals= 0; max_length= 21; }
1115
class Item_func_udf_decimal :public Item_udf_func
1118
Item_func_udf_decimal(udf_func *udf_arg)
1119
:Item_udf_func(udf_arg) {}
1120
Item_func_udf_decimal(udf_func *udf_arg, List<Item> &list)
1121
:Item_udf_func(udf_arg, list) {}
1124
my_decimal *val_decimal(my_decimal *);
1125
String *val_str(String *str);
1126
enum Item_result result_type () const { return DECIMAL_RESULT; }
1127
void fix_length_and_dec();
1131
class Item_func_udf_str :public Item_udf_func
1134
Item_func_udf_str(udf_func *udf_arg)
1135
:Item_udf_func(udf_arg) {}
1136
Item_func_udf_str(udf_func *udf_arg, List<Item> &list)
1137
:Item_udf_func(udf_arg, list) {}
1138
String *val_str(String *);
1144
res= val_str(&str_value);
1145
return res ? my_strntod(res->charset(),(char*) res->ptr(),
1146
res->length(), &end_not_used, &err_not_used) : 0.0;
1151
String *res; res=val_str(&str_value);
1152
return res ? my_strntoll(res->charset(),res->ptr(),res->length(),10,
1153
(char**) 0, &err_not_used) : (int64_t) 0;
1155
my_decimal *val_decimal(my_decimal *dec_buf)
1157
String *res=val_str(&str_value);
1160
string2my_decimal(E_DEC_FATAL_ERROR, res, dec_buf);
1163
enum Item_result result_type () const { return STRING_RESULT; }
1164
void fix_length_and_dec();
1168
/* replication functions */
1170
class Item_master_pos_wait :public Item_int_func
1174
Item_master_pos_wait(Item *a,Item *b) :Item_int_func(a,b) {}
1175
Item_master_pos_wait(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {}
1177
const char *func_name() const { return "master_pos_wait"; }
1178
void fix_length_and_dec() { max_length=21; maybe_null=1;}
1182
/* Handling of user definable variables */
1184
class user_var_entry;
1186
class Item_func_set_user_var :public Item_func
1188
enum Item_result cached_result_type;
1189
user_var_entry *entry;
1190
char buffer[MAX_FIELD_WIDTH];
1192
my_decimal decimal_buff;
1203
LEX_STRING name; // keep it public
1204
Item_func_set_user_var(LEX_STRING a,Item *b)
1205
:Item_func(b), cached_result_type(INT_RESULT), name(a)
1207
enum Functype functype() const { return SUSERVAR_FUNC; }
1210
String *val_str(String *str);
1211
my_decimal *val_decimal(my_decimal *);
1212
double val_result();
1213
int64_t val_int_result();
1214
String *str_result(String *str);
1215
my_decimal *val_decimal_result(my_decimal *);
1216
bool update_hash(void *ptr, uint length, enum Item_result type,
1217
const CHARSET_INFO * const cs, Derivation dv, bool unsigned_arg);
1218
bool send(Protocol *protocol, String *str_arg);
1219
void make_field(Send_field *tmp_field);
1220
bool check(bool use_result_field);
1222
enum Item_result result_type () const { return cached_result_type; }
1223
bool fix_fields(THD *thd, Item **ref);
1224
void fix_length_and_dec();
1225
virtual void print(String *str, enum_query_type query_type);
1226
void print_as_stmt(String *str, enum_query_type query_type);
1227
const char *func_name() const { return "set_user_var"; }
1228
int save_in_field(Field *field, bool no_conversions,
1229
bool can_use_result_field);
1230
int save_in_field(Field *field, bool no_conversions)
1232
return save_in_field(field, no_conversions, 1);
1234
void save_org_in_field(Field *field) { (void)save_in_field(field, 1, 0); }
1235
bool register_field_in_read_map(uchar *arg);
1239
class Item_func_get_user_var :public Item_func
1241
user_var_entry *var_entry;
1242
Item_result m_cached_result_type;
1245
LEX_STRING name; // keep it public
1246
Item_func_get_user_var(LEX_STRING a):
1247
Item_func(), m_cached_result_type(STRING_RESULT), name(a) {}
1248
enum Functype functype() const { return GUSERVAR_FUNC; }
1249
LEX_STRING get_name() { return name; }
1252
my_decimal *val_decimal(my_decimal*);
1253
String *val_str(String* str);
1254
void fix_length_and_dec();
1255
virtual void print(String *str, enum_query_type query_type);
1256
enum Item_result result_type() const;
1258
We must always return variables as strings to guard against selects of type
1259
select @t1:=1,@t1,@t:="hello",@t from foo where (@t1:= t2.b)
1261
const char *func_name() const { return "get_user_var"; }
1262
bool const_item() const;
1263
table_map used_tables() const
1264
{ return const_item() ? 0 : RAND_TABLE_BIT; }
1265
bool eq(const Item *item, bool binary_cmp) const;
1270
This item represents user variable used as out parameter (e.g in LOAD DATA),
1271
and it is supposed to be used only for this purprose. So it is simplified
1272
a lot. Actually you should never obtain its value.
1274
The only two reasons for this thing being an Item is possibility to store it
1275
in List<Item> and desire to place this code somewhere near other functions
1276
working with user variables.
1278
class Item_user_var_as_out_param :public Item
1281
user_var_entry *entry;
1283
Item_user_var_as_out_param(LEX_STRING a) : name(a) {}
1284
/* We should return something different from FIELD_ITEM here */
1285
enum Type type() const { return STRING_ITEM;}
1288
String *val_str(String *str);
1289
my_decimal *val_decimal(my_decimal *decimal_buffer);
1290
/* fix_fields() binds variable name with its entry structure */
1291
bool fix_fields(THD *thd, Item **ref);
1292
virtual void print(String *str, enum_query_type query_type);
1293
void set_null_value(const CHARSET_INFO * const cs);
1294
void set_value(const char *str, uint length, const CHARSET_INFO * const cs);
1298
/* A system variable */
1300
class Item_func_get_system_var :public Item_func
1303
enum_var_type var_type;
1304
LEX_STRING component;
1306
Item_func_get_system_var(sys_var *var_arg, enum_var_type var_type_arg,
1307
LEX_STRING *component_arg, const char *name_arg,
1308
size_t name_len_arg);
1309
bool fix_fields(THD *thd, Item **ref);
1311
Stubs for pure virtual methods. Should never be called: this
1312
item is always substituted with a constant in fix_fields().
1314
double val_real() { assert(0); return 0.0; }
1315
int64_t val_int() { assert(0); return 0; }
1316
String* val_str(String*) { assert(0); return 0; }
1317
void fix_length_and_dec() { assert(0); }
1318
/* TODO: fix to support views */
1319
const char *func_name() const { return "get_system_var"; }
1321
Indicates whether this system variable is written to the binlog or not.
1323
Variables are written to the binlog as part of "status_vars" in
1324
Query_log_event, as an Intvar_log_event, or a Rand_log_event.
1326
@return true if the variable is written to the binlog, false otherwise.
1328
bool is_written_to_binlog();
1331
class Item_func_bit_xor : public Item_func_bit
1334
Item_func_bit_xor(Item *a, Item *b) :Item_func_bit(a, b) {}
1336
const char *func_name() const { return "^"; }
1339
class Item_func_is_free_lock :public Item_int_func
1343
Item_func_is_free_lock(Item *a) :Item_int_func(a) {}
1345
const char *func_name() const { return "is_free_lock"; }
1346
void fix_length_and_dec() { decimals=0; max_length=1; maybe_null=1;}
1349
class Item_func_is_used_lock :public Item_int_func
1353
Item_func_is_used_lock(Item *a) :Item_int_func(a) {}
1355
const char *func_name() const { return "is_used_lock"; }
1356
void fix_length_and_dec() { decimals=0; max_length=10; maybe_null=1;}
96
1359
/* For type casts */