24
24
#include <drizzled/server_includes.h>
25
25
#include <drizzled/sql_select.h>
26
#include <drizzled/error.h>
29
#if defined(CMATH_NAMESPACE)
30
using namespace CMATH_NAMESPACE;
33
static bool convert_constant_item(Session *, Item_field *, Item **);
27
static bool convert_constant_item(THD *, Item_field *, Item **);
35
29
static Item_result item_store_type(Item_result a, Item *item,
36
30
bool unsigned_flag)
97
91
static int cmp_row_type(Item* item1, Item* item2)
99
uint32_t n= item1->cols();
93
uint n= item1->cols();
100
94
if (item2->check_cols(n))
102
for (uint32_t i=0; i<n; i++)
96
for (uint i=0; i<n; i++)
104
98
if (item2->element_index(i)->check_cols(item1->element_index(i)->cols()) ||
105
99
(item1->element_index(i)->result_type() == ROW_RESULT &&
172
166
@return aggregated field type.
175
enum_field_types agg_field_type(Item **items, uint32_t nitems)
169
enum_field_types agg_field_type(Item **items, uint nitems)
178
172
if (!nitems || items[0]->result_type() == ROW_RESULT )
179
173
return (enum_field_types)-1;
180
174
enum_field_types res= items[0]->field_type();
393
387
if (!(*item)->with_subselect && (*item)->const_item())
395
ulong orig_sql_mode= session->variables.sql_mode;
396
enum_check_fields orig_count_cuted_fields= session->count_cuted_fields;
389
ulong orig_sql_mode= thd->variables.sql_mode;
390
enum_check_fields orig_count_cuted_fields= thd->count_cuted_fields;
397
391
uint64_t orig_field_val= 0; /* original field value if valid */
399
393
/* For comparison purposes allow invalid dates like 2000-01-32 */
400
session->variables.sql_mode= (orig_sql_mode & ~MODE_NO_ZERO_DATE) |
394
thd->variables.sql_mode= (orig_sql_mode & ~MODE_NO_ZERO_DATE) |
401
395
MODE_INVALID_DATES;
402
session->count_cuted_fields= CHECK_FIELD_IGNORE;
396
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
405
399
Store the value of the field if it references an outer field because
412
406
Item *tmp= new Item_int_with_ref(field->val_int(), *item,
413
407
test(field->flags & UNSIGNED_FLAG));
415
session->change_item_tree(item, tmp);
409
thd->change_item_tree(item, tmp);
416
410
result= 1; // Item was replaced
418
412
/* Restore the original field value. */
478
472
if (field_item->field->can_be_compared_as_int64_t() &&
479
473
!(field_item->is_datetime() && args[1]->result_type() == STRING_RESULT))
481
if (convert_constant_item(session, field_item, &args[1]))
475
if (convert_constant_item(thd, field_item, &args[1]))
483
477
cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
484
478
INT_RESULT); // Works for all types.
494
488
!(field_item->is_datetime() &&
495
489
args[0]->result_type() == STRING_RESULT))
497
if (convert_constant_item(session, field_item, &args[0]))
491
if (convert_constant_item(thd, field_item, &args[0]))
499
493
cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
500
494
INT_RESULT); // Works for all types.
567
561
which would be transformed to:
570
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
571
(*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
564
(*a)->walk(&Item::set_no_const_sub, false, (uchar*) 0);
565
(*b)->walk(&Item::set_no_const_sub, false, (uchar*) 0);
597
591
if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
599
precision= 5 / log_10[cmax((*a)->decimals, (*b)->decimals) + 1];
593
precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
600
594
if (func == &Arg_comparator::compare_real)
601
595
func= &Arg_comparator::compare_real_fixed;
602
596
else if (func == &Arg_comparator::compare_e_real)
615
609
@brief Convert date provided in a string to the int representation.
617
@param[in] session thread handle
611
@param[in] thd thread handle
618
612
@param[in] str a string to convert
619
613
@param[in] warn_type type of the timestamp for issuing the warning
620
614
@param[in] warn_name field name for issuing the warning
637
get_date_from_str(Session *session, String *str, enum enum_drizzle_timestamp_type warn_type,
631
get_date_from_str(THD *thd, String *str, timestamp_type warn_type,
638
632
char *warn_name, bool *error_arg)
640
634
uint64_t value= 0;
642
636
DRIZZLE_TIME l_time;
643
enum enum_drizzle_timestamp_type ret;
637
enum_drizzle_timestamp_type ret;
645
639
ret= str_to_datetime(str->ptr(), str->length(), &l_time,
646
640
(TIME_FUZZY_DATE | MODE_INVALID_DATES |
647
(session->variables.sql_mode & MODE_NO_ZERO_DATE)),
641
(thd->variables.sql_mode & MODE_NO_ZERO_DATE)),
650
644
if (ret == DRIZZLE_TIMESTAMP_DATETIME || ret == DRIZZLE_TIMESTAMP_DATE)
740
734
(str_arg->type() != Item::FUNC_ITEM ||
741
735
((Item_func*)str_arg)->functype() != Item_func::GUSERVAR_FUNC))
743
Session *session= current_session;
737
THD *thd= current_thd;
746
740
String tmp, *str_val= 0;
747
enum enum_drizzle_timestamp_type t_type= (date_arg->field_type() == DRIZZLE_TYPE_NEWDATE ?
741
timestamp_type t_type= (date_arg->field_type() == DRIZZLE_TYPE_NEWDATE ?
748
742
DRIZZLE_TIMESTAMP_DATE : DRIZZLE_TIMESTAMP_DATETIME);
750
744
str_val= str_arg->val_str(&tmp);
751
745
if (str_arg->null_value)
752
746
return CMP_DATE_DFLT;
753
value= get_date_from_str(session, str_val, t_type, date_arg->name, &error);
747
value= get_date_from_str(thd, str_val, t_type, date_arg->name, &error);
755
749
return CMP_DATE_DFLT;
790
get_time_value(Session *session __attribute__((unused)),
784
get_time_value(THD *thd __attribute__((unused)),
791
785
Item ***item_arg, Item **cache_arg,
792
786
Item *warn_item __attribute__((unused)),
933
get_datetime_value(Session *session, Item ***item_arg, Item **cache_arg,
927
get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
934
928
Item *warn_item, bool *is_null)
936
930
uint64_t value= 0;
971
965
enum_field_types f_type= warn_item->field_type();
972
enum enum_drizzle_timestamp_type t_type= f_type ==
966
timestamp_type t_type= f_type ==
973
967
DRIZZLE_TYPE_NEWDATE ? DRIZZLE_TIMESTAMP_DATE : DRIZZLE_TIMESTAMP_DATETIME;
974
value= get_date_from_str(session, str, t_type, warn_item->name, &error);
968
value= get_date_from_str(thd, str, t_type, warn_item->name, &error);
976
970
If str did not contain a valid date according to the current
977
971
SQL_MODE, get_date_from_str() has already thrown a warning,
1023
1017
uint64_t a_value, b_value;
1025
1019
/* Get DATE/DATETIME/TIME value of the 'a' item. */
1026
a_value= (*get_value_func)(session, &a, &a_cache, *b, &is_null);
1020
a_value= (*get_value_func)(thd, &a, &a_cache, *b, &is_null);
1027
1021
if (!is_nulls_eq && is_null)
1034
1028
/* Get DATE/DATETIME/TIME value of the 'b' item. */
1035
b_value= (*get_value_func)(session, &b, &b_cache, *a, &is_null);
1029
b_value= (*get_value_func)(thd, &b, &b_cache, *a, &is_null);
1085
1079
if ((res2= (*b)->val_str(&owner->tmp_value2)))
1087
1081
owner->null_value= 0;
1088
uint32_t res1_length= res1->length();
1089
uint32_t res2_length= res2->length();
1090
int cmp= memcmp(res1->ptr(), res2->ptr(), cmin(res1_length,res2_length));
1082
uint res1_length= res1->length();
1083
uint res2_length= res2->length();
1084
int cmp= memcmp(res1->ptr(), res2->ptr(), min(res1_length,res2_length));
1091
1085
return cmp ? cmp : (int) (res1_length - res2_length);
1452
bool Item_in_optimizer::fix_left(Session *session, Item **ref __attribute__((unused)))
1446
bool Item_in_optimizer::fix_left(THD *thd, Item **ref __attribute__((unused)))
1454
if ((!args[0]->fixed && args[0]->fix_fields(session, args)) ||
1448
if ((!args[0]->fixed && args[0]->fix_fields(thd, args)) ||
1455
1449
(!cache && !(cache= Item_cache::get_cache(args[0]))))
1486
bool Item_in_optimizer::fix_fields(Session *session, Item **ref)
1480
bool Item_in_optimizer::fix_fields(THD *thd, Item **ref)
1488
1482
assert(fixed == 0);
1489
if (fix_left(session, ref))
1483
if (fix_left(thd, ref))
1491
1485
if (args[0]->maybe_null)
1494
if (!args[1]->fixed && args[1]->fix_fields(session, args+1))
1488
if (!args[1]->fixed && args[1]->fix_fields(thd, args+1))
1496
1490
Item_in_subselect * sub= (Item_in_subselect *)args[1];
1497
1491
if (args[0]->cols() != sub->engine->cols())
1641
Session::change_item_tree() should be called only if the tree was
1635
THD::change_item_tree() should be called only if the tree was
1642
1636
really transformed, i.e. when a new item has been created.
1643
1637
Otherwise we'll be allocating a lot of unnecessary memory for
1644
1638
change records at each execution.
1646
1640
if ((*args) != new_item)
1647
current_session->change_item_tree(args, new_item);
1641
current_thd->change_item_tree(args, new_item);
1650
1644
Transform the right IN operand which should be an Item_in_subselect or a
1955
bool Item_func_between::fix_fields(Session *session, Item **ref)
1949
bool Item_func_between::fix_fields(THD *thd, Item **ref)
1957
if (Item_func_opt_neg::fix_fields(session, ref))
1951
if (Item_func_opt_neg::fix_fields(thd, ref))
1960
session->lex->current_select->between_count++;
1954
thd->lex->current_select->between_count++;
1962
1956
/* not_null_tables_cache == union(T1(e),T1(e1),T1(e2)) */
1963
1957
if (pred_level && !negated)
2035
2029
The following can't be recoded with || as convert_constant_item
2036
2030
changes the argument
2038
if (convert_constant_item(session, field_item, &args[1]))
2032
if (convert_constant_item(thd, field_item, &args[1]))
2039
2033
cmp_type=INT_RESULT; // Works for all types.
2040
if (convert_constant_item(session, field_item, &args[2]))
2034
if (convert_constant_item(thd, field_item, &args[2]))
2041
2035
cmp_type=INT_RESULT; // Works for all types.
2173
2167
agg_result_type(&hybrid_type, args, 2);
2174
2168
maybe_null=args[1]->maybe_null;
2175
decimals= cmax(args[0]->decimals, args[1]->decimals);
2169
decimals= max(args[0]->decimals, args[1]->decimals);
2176
2170
unsigned_flag= args[0]->unsigned_flag && args[1]->unsigned_flag;
2178
2172
if (hybrid_type == DECIMAL_RESULT || hybrid_type == INT_RESULT)
2183
2177
int len1= args[1]->max_length - args[1]->decimals
2184
2178
- (args[1]->unsigned_flag ? 0 : 1);
2186
max_length= cmax(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
2180
max_length= max(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
2189
max_length= cmax(args[0]->max_length, args[1]->max_length);
2183
max_length= max(args[0]->max_length, args[1]->max_length);
2191
2185
switch (hybrid_type) {
2192
2186
case STRING_RESULT:
2209
uint32_t Item_func_ifnull::decimal_precision() const
2203
uint Item_func_ifnull::decimal_precision() const
2211
int max_int_part=cmax(args[0]->decimal_int_part(),args[1]->decimal_int_part());
2212
return cmin(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2205
int max_int_part=max(args[0]->decimal_int_part(),args[1]->decimal_int_part());
2206
return min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2321
Item_func_if::fix_fields(Session *session, Item **ref)
2315
Item_func_if::fix_fields(THD *thd, Item **ref)
2323
2317
assert(fixed == 0);
2324
2318
args[0]->top_level_item();
2326
if (Item_func::fix_fields(session, ref))
2320
if (Item_func::fix_fields(thd, ref))
2329
2323
not_null_tables_cache= (args[1]->not_null_tables() &
2337
2331
Item_func_if::fix_length_and_dec()
2339
2333
maybe_null=args[1]->maybe_null || args[2]->maybe_null;
2340
decimals= cmax(args[1]->decimals, args[2]->decimals);
2334
decimals= max(args[1]->decimals, args[2]->decimals);
2341
2335
unsigned_flag=args[1]->unsigned_flag && args[2]->unsigned_flag;
2343
2337
enum Item_result arg1_type=args[1]->result_type();
2381
2375
int len2= args[2]->max_length - args[2]->decimals
2382
2376
- (args[2]->unsigned_flag ? 0 : 1);
2384
max_length=cmax(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
2378
max_length=max(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
2387
max_length= cmax(args[1]->max_length, args[2]->max_length);
2381
max_length= max(args[1]->max_length, args[2]->max_length);
2391
uint32_t Item_func_if::decimal_precision() const
2385
uint Item_func_if::decimal_precision() const
2393
int precision=(cmax(args[1]->decimal_int_part(),args[2]->decimal_int_part())+
2387
int precision=(max(args[1]->decimal_int_part(),args[2]->decimal_int_part())+
2395
return cmin(precision, DECIMAL_MAX_PRECISION);
2389
return min(precision, DECIMAL_MAX_PRECISION);
2674
bool Item_func_case::fix_fields(Session *session, Item **ref)
2668
bool Item_func_case::fix_fields(THD *thd, Item **ref)
2677
2671
buff should match stack usage from
2678
2672
Item_func_case::val_int() -> Item_func_case::find_item()
2680
unsigned char buff[MAX_FIELD_WIDTH*2+sizeof(String)*2+sizeof(String*)*2+sizeof(double)*2+sizeof(int64_t)*2];
2681
bool res= Item_func::fix_fields(session, ref);
2674
uchar buff[MAX_FIELD_WIDTH*2+sizeof(String)*2+sizeof(String*)*2+sizeof(double)*2+sizeof(int64_t)*2];
2675
bool res= Item_func::fix_fields(thd, ref);
2683
2677
Call check_stack_overrun after fix_fields to be sure that stack variable
2684
2678
is not optimized away
2686
if (check_stack_overrun(session, STACK_MIN_SIZE, buff))
2680
if (check_stack_overrun(thd, STACK_MIN_SIZE, buff))
2687
2681
return true; // Fatal error flag is set!
2700
2694
void Item_func_case::agg_num_lengths(Item *arg)
2702
uint32_t len= my_decimal_length_to_precision(arg->max_length, arg->decimals,
2696
uint len= my_decimal_length_to_precision(arg->max_length, arg->decimals,
2703
2697
arg->unsigned_flag) - arg->decimals;
2704
2698
set_if_bigger(max_length, len);
2705
2699
set_if_bigger(decimals, arg->decimals);
2772
2766
unsigned_flag= true;
2773
2767
if (cached_result_type == STRING_RESULT)
2775
for (uint32_t i= 0; i < ncases; i+= 2)
2769
for (uint i= 0; i < ncases; i+= 2)
2776
2770
agg_str_lengths(args[i + 1]);
2777
2771
if (else_expr_num != -1)
2778
2772
agg_str_lengths(args[else_expr_num]);
2782
for (uint32_t i= 0; i < ncases; i+= 2)
2776
for (uint i= 0; i < ncases; i+= 2)
2783
2777
agg_num_lengths(args[i + 1]);
2784
2778
if (else_expr_num != -1)
2785
2779
agg_num_lengths(args[else_expr_num]);
2792
uint32_t Item_func_case::decimal_precision() const
2786
uint Item_func_case::decimal_precision() const
2794
2788
int max_int_part=0;
2795
for (uint32_t i=0 ; i < ncases ; i+=2)
2789
for (uint i=0 ; i < ncases ; i+=2)
2796
2790
set_if_bigger(max_int_part, args[i+1]->decimal_int_part());
2798
2792
if (else_expr_num != -1)
2799
2793
set_if_bigger(max_int_part, args[else_expr_num]->decimal_int_part());
2800
return cmin(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2794
return min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
3059
3053
int in_vector::find(Item *item)
3061
unsigned char *result=get_value(item);
3055
uchar *result=get_value(item);
3062
3056
if (!result || !used_count)
3063
3057
return 0; // Null value
3066
3060
start=0; end=used_count-1;
3067
3061
while (start != end)
3069
uint32_t mid=(start+end+1)/2;
3063
uint mid=(start+end+1)/2;
3071
3065
if ((res=(*compare)(collation, base+mid*size, result)) == 0)
3078
3072
return (int) ((*compare)(collation, base+start*size, result) == 0);
3081
in_string::in_string(uint32_t elements,qsort2_cmp cmp_func, const CHARSET_INFO * const cs)
3075
in_string::in_string(uint elements,qsort2_cmp cmp_func, const CHARSET_INFO * const cs)
3082
3076
:in_vector(elements, sizeof(String), cmp_func, cs),
3083
3077
tmp(buff, sizeof(buff), &my_charset_bin)
3090
3084
// base was allocated with help of sql_alloc => following is OK
3091
for (uint32_t i=0 ; i < count ; i++)
3085
for (uint i=0 ; i < count ; i++)
3092
3086
((String*) base)[i].free();
3096
void in_string::set(uint32_t pos,Item *item)
3090
void in_string::set(uint pos,Item *item)
3098
3092
String *str=((String*) base)+pos;
3099
3093
String *res=item->val_str(str);
3119
unsigned char *in_string::get_value(Item *item)
3113
uchar *in_string::get_value(Item *item)
3121
return (unsigned char*) item->val_str(&tmp);
3115
return (uchar*) item->val_str(&tmp);
3124
in_row::in_row(uint32_t elements, Item * item __attribute__((unused)))
3118
in_row::in_row(uint elements, Item * item __attribute__((unused)))
3126
3120
base= (char*) new cmp_item_row[count= elements];
3127
3121
size= sizeof(cmp_item_row);
3140
3134
delete [] (cmp_item_row*) base;
3143
unsigned char *in_row::get_value(Item *item)
3137
uchar *in_row::get_value(Item *item)
3145
3139
tmp.store_value(item);
3146
3140
if (item->is_null())
3148
return (unsigned char *)&tmp;
3142
return (uchar *)&tmp;
3151
void in_row::set(uint32_t pos, Item *item)
3145
void in_row::set(uint pos, Item *item)
3153
3147
((cmp_item_row*) base)[pos].store_value_by_template(&tmp, item);
3157
in_int64_t::in_int64_t(uint32_t elements)
3151
in_int64_t::in_int64_t(uint elements)
3158
3152
:in_vector(elements,sizeof(packed_int64_t),(qsort2_cmp) cmp_int64_t, 0)
3161
void in_int64_t::set(uint32_t pos,Item *item)
3155
void in_int64_t::set(uint pos,Item *item)
3163
3157
struct packed_int64_t *buff= &((packed_int64_t*) base)[pos];
3166
3160
buff->unsigned_flag= item->unsigned_flag;
3169
unsigned char *in_int64_t::get_value(Item *item)
3163
uchar *in_int64_t::get_value(Item *item)
3171
3165
tmp.val= item->val_int();
3172
3166
if (item->null_value)
3174
3168
tmp.unsigned_flag= item->unsigned_flag;
3175
return (unsigned char*) &tmp;
3169
return (uchar*) &tmp;
3178
void in_datetime::set(uint32_t pos,Item *item)
3172
void in_datetime::set(uint pos,Item *item)
3180
3174
Item **tmp_item= &item;
3182
3176
struct packed_int64_t *buff= &((packed_int64_t*) base)[pos];
3184
buff->val= get_datetime_value(session, &tmp_item, 0, warn_item, &is_null);
3178
buff->val= get_datetime_value(thd, &tmp_item, 0, warn_item, &is_null);
3185
3179
buff->unsigned_flag= 1L;
3188
unsigned char *in_datetime::get_value(Item *item)
3182
uchar *in_datetime::get_value(Item *item)
3191
3185
Item **tmp_item= lval_cache ? &lval_cache : &item;
3192
tmp.val= get_datetime_value(session, &tmp_item, &lval_cache, warn_item, &is_null);
3186
tmp.val= get_datetime_value(thd, &tmp_item, &lval_cache, warn_item, &is_null);
3193
3187
if (item->null_value)
3195
3189
tmp.unsigned_flag= 1L;
3196
return (unsigned char*) &tmp;
3190
return (uchar*) &tmp;
3199
in_double::in_double(uint32_t elements)
3193
in_double::in_double(uint elements)
3200
3194
:in_vector(elements,sizeof(double),(qsort2_cmp) cmp_double, 0)
3203
void in_double::set(uint32_t pos,Item *item)
3197
void in_double::set(uint pos,Item *item)
3205
3199
((double*) base)[pos]= item->val_real();
3208
unsigned char *in_double::get_value(Item *item)
3202
uchar *in_double::get_value(Item *item)
3210
3204
tmp= item->val_real();
3211
3205
if (item->null_value)
3212
3206
return 0; /* purecov: inspected */
3213
return (unsigned char*) &tmp;
3207
return (uchar*) &tmp;
3217
in_decimal::in_decimal(uint32_t elements)
3211
in_decimal::in_decimal(uint elements)
3218
3212
:in_vector(elements, sizeof(my_decimal),(qsort2_cmp) cmp_decimal, 0)
3222
void in_decimal::set(uint32_t pos, Item *item)
3216
void in_decimal::set(uint pos, Item *item)
3224
3218
/* as far as 'item' is constant, we can store reference on my_decimal */
3225
3219
my_decimal *dec= ((my_decimal *)base) + pos;
3426
3420
Item **tmp_item= lval_cache ? &lval_cache : &item;
3427
value= get_datetime_value(session, &tmp_item, &lval_cache, warn_item, &is_null);
3421
value= get_datetime_value(thd, &tmp_item, &lval_cache, warn_item, &is_null);
3494
Item_func_in::fix_fields(Session *session, Item **ref)
3488
Item_func_in::fix_fields(THD *thd, Item **ref)
3496
3490
Item **arg, **arg_end;
3498
if (Item_func_opt_neg::fix_fields(session, ref))
3492
if (Item_func_opt_neg::fix_fields(thd, ref))
3501
3495
/* not_null_tables_cache == union(T1(e),union(T1(ei))) */
3514
3508
static int srtcmp_in(const CHARSET_INFO * const cs, const String *x,const String *y)
3516
3510
return cs->coll->strnncollsp(cs,
3517
(unsigned char *) x->ptr(),x->length(),
3518
(unsigned char *) y->ptr(),y->length(), 0);
3511
(uchar *) x->ptr(),x->length(),
3512
(uchar *) y->ptr(),y->length(), 0);
3524
3518
Item **arg, **arg_end;
3525
3519
bool const_itm= 1;
3526
Session *session= current_session;
3520
THD *thd= current_thd;
3527
3521
bool datetime_found= false;
3528
3522
/* true <=> arguments values will be compared as DATETIMEs. */
3529
3523
bool compare_as_datetime= false;
3530
3524
Item *date_arg= 0;
3531
uint32_t found_types= 0;
3532
uint32_t type_cnt= 0, i;
3525
uint found_types= 0;
3526
uint type_cnt= 0, i;
3533
3527
Item_result cmp_type= STRING_RESULT;
3534
3528
left_result_type= args[0]->result_type();
3535
3529
if (!(found_types= collect_cmp_types(args, arg_count)))
3670
3664
bool all_converted= true;
3671
3665
for (arg=args+1, arg_end=args+arg_count; arg != arg_end ; arg++)
3673
if (!convert_constant_item (session, field_item, &arg[0]))
3667
if (!convert_constant_item (thd, field_item, &arg[0]))
3674
3668
all_converted= false;
3676
3670
if (all_converted)
3856
3850
return (int64_t) (arg1 & arg2);
3859
Item_cond::Item_cond(Session *session, Item_cond *item)
3860
:Item_bool_func(session, item),
3853
Item_cond::Item_cond(THD *thd, Item_cond *item)
3854
:Item_bool_func(thd, item),
3861
3855
abort_on_null(item->abort_on_null),
3862
3856
and_tables_cache(item->and_tables_cache)
3870
void Item_cond::copy_andor_arguments(Session *session, Item_cond *item)
3864
void Item_cond::copy_andor_arguments(THD *thd, Item_cond *item)
3872
3866
List_iterator_fast<Item> li(item->list);
3873
3867
while (Item *it= li++)
3874
list.push_back(it->copy_andor_structure(session));
3868
list.push_back(it->copy_andor_structure(thd));
3879
Item_cond::fix_fields(Session *session, Item **ref __attribute__((unused)))
3873
Item_cond::fix_fields(THD *thd, Item **ref __attribute__((unused)))
3881
3875
assert(fixed == 0);
3882
3876
List_iterator<Item> li(list);
3884
void *orig_session_marker= session->session_marker;
3885
unsigned char buff[sizeof(char*)]; // Max local vars in function
3878
void *orig_thd_marker= thd->thd_marker;
3879
uchar buff[sizeof(char*)]; // Max local vars in function
3886
3880
not_null_tables_cache= used_tables_cache= 0;
3887
3881
const_item_cache= 1;
3889
3883
if (functype() == COND_OR_FUNC)
3890
session->session_marker= 0;
3892
3886
and_table_cache is the value that Item_cond_or() returns for
3893
3887
not_null_tables()
3895
3889
and_tables_cache= ~(table_map) 0;
3897
if (check_stack_overrun(session, STACK_MIN_SIZE, buff))
3891
if (check_stack_overrun(thd, STACK_MIN_SIZE, buff))
3898
3892
return true; // Fatal error flag is set!
3900
3894
The following optimization reduces the depth of an AND-OR tree.
3928
3922
// item can be substituted in fix_fields
3929
3923
if ((!item->fixed &&
3930
item->fix_fields(session, li.ref())) ||
3924
item->fix_fields(thd, li.ref())) ||
3931
3925
(item= *li.ref())->check_cols(1))
3932
3926
return true; /* purecov: inspected */
3933
3927
used_tables_cache|= item->used_tables();
4028
Session::change_item_tree() should be called only if the tree was
4022
THD::change_item_tree() should be called only if the tree was
4029
4023
really transformed, i.e. when a new item has been created.
4030
4024
Otherwise we'll be allocating a lot of unnecessary memory for
4031
4025
change records at each execution.
4033
4027
if (new_item != item)
4034
current_session->change_item_tree(li.ref(), new_item);
4028
current_thd->change_item_tree(li.ref(), new_item);
4036
4030
return Item_func::transform(transformer, arg);
4061
4055
Item returned as the result of transformation of the root node
4064
Item *Item_cond::compile(Item_analyzer analyzer, unsigned char **arg_p,
4065
Item_transformer transformer, unsigned char *arg_t)
4058
Item *Item_cond::compile(Item_analyzer analyzer, uchar **arg_p,
4059
Item_transformer transformer, uchar *arg_t)
4067
4061
if (!(this->*analyzer)(arg_p))
4075
4069
The same parameter value of arg_p must be passed
4076
4070
to analyze any argument of the condition formula.
4078
unsigned char *arg_v= *arg_p;
4072
uchar *arg_v= *arg_p;
4079
4073
Item *new_item= item->compile(analyzer, &arg_v, transformer, arg_t);
4080
4074
if (new_item && new_item != item)
4081
4075
li.replace(new_item);
4124
4118
that have or refer (HAVING) to a SUM expression.
4127
void Item_cond::split_sum_func(Session *session, Item **ref_pointer_array,
4121
void Item_cond::split_sum_func(THD *thd, Item **ref_pointer_array,
4128
4122
List<Item> &fields)
4130
4124
List_iterator<Item> li(list);
4132
4126
while ((item= li++))
4133
item->split_sum_func2(session, ref_pointer_array, fields, li.ref(), true);
4127
item->split_sum_func2(thd, ref_pointer_array, fields, li.ref(), true);
4178
void Item_cond::neg_arguments(Session *session)
4172
void Item_cond::neg_arguments(THD *thd)
4180
4174
List_iterator<Item> li(list);
4182
4176
while ((item= li++)) /* Apply not transformation to the arguments */
4184
Item *new_item= item->neg_transformer(session);
4178
Item *new_item= item->neg_transformer(thd);
4187
4181
if (!(new_item= new Item_func_not(item)))
4188
4182
return; // Fatal OEM error
4190
li.replace(new_item);
4184
VOID(li.replace(new_item));
4408
bool Item_func_like::fix_fields(Session *session, Item **ref)
4402
bool Item_func_like::fix_fields(THD *thd, Item **ref)
4410
4404
assert(fixed == 0);
4411
if (Item_bool_func2::fix_fields(session, ref) ||
4412
escape_item->fix_fields(session, &escape_item))
4405
if (Item_bool_func2::fix_fields(thd, ref) ||
4406
escape_item->fix_fields(thd, &escape_item))
4415
4409
if (!escape_item->const_during_execution())
4435
4429
const CHARSET_INFO * const cs= escape_str->charset();
4437
4431
int rc= cs->cset->mb_wc(cs, &wc,
4438
(const unsigned char*) escape_str->ptr(),
4439
(const unsigned char*) escape_str->ptr() +
4432
(const uchar*) escape_str->ptr(),
4433
(const uchar*) escape_str->ptr() +
4440
4434
escape_str->length());
4441
4435
escape= (int) (rc > 0 ? wc : '\\');
4719
4713
turboShift = u - v;
4720
4714
bcShift = bmBc[(uint) likeconv(cs, text[i + j])] - plm1 + i;
4721
4715
shift = (turboShift > bcShift) ? turboShift : bcShift;
4722
shift = cmax(shift, bmGs[i]);
4716
shift = max(shift, bmGs[i]);
4723
4717
if (shift == bmGs[i])
4724
4718
u = (pattern_len - shift < v) ? pattern_len - shift : v;
4727
4721
if (turboShift < bcShift)
4728
shift = cmax(shift, u + 1);
4722
shift = max(shift, u + 1);
4789
4783
IS NOT NULL(a) -> IS NULL(a)
4792
@param session thread handler
4786
@param thd thread handler
4796
4790
NULL if we cannot apply NOT transformation (see Item::neg_transformer()).
4799
Item *Item_func_not::neg_transformer(Session *session __attribute__((unused))) /* NOT(x) -> x */
4793
Item *Item_func_not::neg_transformer(THD *thd __attribute__((unused))) /* NOT(x) -> x */
4801
4795
return args[0];
4805
Item *Item_bool_rowready_func2::neg_transformer(Session *session __attribute__((unused)))
4799
Item *Item_bool_rowready_func2::neg_transformer(THD *thd __attribute__((unused)))
4807
4801
Item *item= negated_item();
4823
4817
a IS NOT NULL -> a IS NULL.
4825
Item *Item_func_isnotnull::neg_transformer(Session *session __attribute__((unused)))
4819
Item *Item_func_isnotnull::neg_transformer(THD *thd __attribute__((unused)))
4827
4821
Item *item= new Item_func_isnull(args[0]);
4832
Item *Item_cond_and::neg_transformer(Session *session) /* NOT(a AND b AND ...) -> */
4826
Item *Item_cond_and::neg_transformer(THD *thd) /* NOT(a AND b AND ...) -> */
4833
4827
/* NOT a OR NOT b OR ... */
4835
neg_arguments(session);
4836
4830
Item *item= new Item_cond_or(list);
4841
Item *Item_cond_or::neg_transformer(Session *session) /* NOT(a OR b OR ...) -> */
4835
Item *Item_cond_or::neg_transformer(THD *thd) /* NOT(a OR b OR ...) -> */
4842
4836
/* NOT a AND NOT b AND ... */
4844
neg_arguments(session);
4845
4839
Item *item= new Item_cond_and(list);
4850
Item *Item_func_nop_all::neg_transformer(Session *session __attribute__((unused)))
4844
Item *Item_func_nop_all::neg_transformer(THD *thd __attribute__((unused)))
4852
4846
/* "NOT (e $cmp$ ANY (SELECT ...)) -> e $rev_cmp$" ALL (SELECT ...) */
4853
4847
Item_func_not_all *new_item= new Item_func_not_all(args[0]);
5188
Session::change_item_tree() should be called only if the tree was
5182
THD::change_item_tree() should be called only if the tree was
5189
5183
really transformed, i.e. when a new item has been created.
5190
5184
Otherwise we'll be allocating a lot of unnecessary memory for
5191
5185
change records at each execution.
5193
5187
if (new_item != item)
5194
current_session->change_item_tree((Item **) it.ref(), new_item);
5188
current_thd->change_item_tree((Item **) it.ref(), new_item);
5196
5190
return Item_func::transform(transformer, arg);