24
24
#include <drizzled/server_includes.h>
25
25
#include <drizzled/sql_select.h>
27
static bool convert_constant_item(Session *, Item_field *, Item **);
27
static bool convert_constant_item(THD *, Item_field *, Item **);
29
29
static Item_result item_store_type(Item_result a, Item *item,
30
30
bool unsigned_flag)
91
91
static int cmp_row_type(Item* item1, Item* item2)
93
uint32_t n= item1->cols();
93
uint n= item1->cols();
94
94
if (item2->check_cols(n))
96
for (uint32_t i=0; i<n; i++)
96
for (uint i=0; i<n; i++)
98
98
if (item2->element_index(i)->check_cols(item1->element_index(i)->cols()) ||
99
99
(item1->element_index(i)->result_type() == ROW_RESULT &&
166
166
@return aggregated field type.
169
enum_field_types agg_field_type(Item **items, uint32_t nitems)
169
enum_field_types agg_field_type(Item **items, uint nitems)
172
172
if (!nitems || items[0]->result_type() == ROW_RESULT )
173
173
return (enum_field_types)-1;
174
174
enum_field_types res= items[0]->field_type();
387
387
if (!(*item)->with_subselect && (*item)->const_item())
389
ulong orig_sql_mode= session->variables.sql_mode;
390
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;
391
391
uint64_t orig_field_val= 0; /* original field value if valid */
393
393
/* For comparison purposes allow invalid dates like 2000-01-32 */
394
session->variables.sql_mode= (orig_sql_mode & ~MODE_NO_ZERO_DATE) |
394
thd->variables.sql_mode= (orig_sql_mode & ~MODE_NO_ZERO_DATE) |
395
395
MODE_INVALID_DATES;
396
session->count_cuted_fields= CHECK_FIELD_IGNORE;
396
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
399
399
Store the value of the field if it references an outer field because
406
406
Item *tmp= new Item_int_with_ref(field->val_int(), *item,
407
407
test(field->flags & UNSIGNED_FLAG));
409
session->change_item_tree(item, tmp);
409
thd->change_item_tree(item, tmp);
410
410
result= 1; // Item was replaced
412
412
/* Restore the original field value. */
472
472
if (field_item->field->can_be_compared_as_int64_t() &&
473
473
!(field_item->is_datetime() && args[1]->result_type() == STRING_RESULT))
475
if (convert_constant_item(session, field_item, &args[1]))
475
if (convert_constant_item(thd, field_item, &args[1]))
477
477
cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
478
478
INT_RESULT); // Works for all types.
488
488
!(field_item->is_datetime() &&
489
489
args[0]->result_type() == STRING_RESULT))
491
if (convert_constant_item(session, field_item, &args[0]))
491
if (convert_constant_item(thd, field_item, &args[0]))
493
493
cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
494
494
INT_RESULT); // Works for all types.
561
561
which would be transformed to:
564
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
565
(*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);
591
591
if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
593
precision= 5 / log_10[cmax((*a)->decimals, (*b)->decimals) + 1];
593
precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
594
594
if (func == &Arg_comparator::compare_real)
595
595
func= &Arg_comparator::compare_real_fixed;
596
596
else if (func == &Arg_comparator::compare_e_real)
609
609
@brief Convert date provided in a string to the int representation.
611
@param[in] session thread handle
611
@param[in] thd thread handle
612
612
@param[in] str a string to convert
613
613
@param[in] warn_type type of the timestamp for issuing the warning
614
614
@param[in] warn_name field name for issuing the warning
631
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,
632
632
char *warn_name, bool *error_arg)
634
634
uint64_t value= 0;
636
636
DRIZZLE_TIME l_time;
637
enum enum_drizzle_timestamp_type ret;
637
enum_drizzle_timestamp_type ret;
639
639
ret= str_to_datetime(str->ptr(), str->length(), &l_time,
640
640
(TIME_FUZZY_DATE | MODE_INVALID_DATES |
641
(session->variables.sql_mode & MODE_NO_ZERO_DATE)),
641
(thd->variables.sql_mode & MODE_NO_ZERO_DATE)),
644
644
if (ret == DRIZZLE_TIMESTAMP_DATETIME || ret == DRIZZLE_TIMESTAMP_DATE)
734
734
(str_arg->type() != Item::FUNC_ITEM ||
735
735
((Item_func*)str_arg)->functype() != Item_func::GUSERVAR_FUNC))
737
Session *session= current_session;
737
THD *thd= current_thd;
740
740
String tmp, *str_val= 0;
741
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 ?
742
742
DRIZZLE_TIMESTAMP_DATE : DRIZZLE_TIMESTAMP_DATETIME);
744
744
str_val= str_arg->val_str(&tmp);
745
745
if (str_arg->null_value)
746
746
return CMP_DATE_DFLT;
747
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);
749
749
return CMP_DATE_DFLT;
784
get_time_value(Session *session __attribute__((unused)),
784
get_time_value(THD *thd __attribute__((unused)),
785
785
Item ***item_arg, Item **cache_arg,
786
786
Item *warn_item __attribute__((unused)),
927
get_datetime_value(Session *session, Item ***item_arg, Item **cache_arg,
927
get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
928
928
Item *warn_item, bool *is_null)
930
930
uint64_t value= 0;
965
965
enum_field_types f_type= warn_item->field_type();
966
enum enum_drizzle_timestamp_type t_type= f_type ==
966
timestamp_type t_type= f_type ==
967
967
DRIZZLE_TYPE_NEWDATE ? DRIZZLE_TIMESTAMP_DATE : DRIZZLE_TIMESTAMP_DATETIME;
968
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);
970
970
If str did not contain a valid date according to the current
971
971
SQL_MODE, get_date_from_str() has already thrown a warning,
1017
1017
uint64_t a_value, b_value;
1019
1019
/* Get DATE/DATETIME/TIME value of the 'a' item. */
1020
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);
1021
1021
if (!is_nulls_eq && is_null)
1028
1028
/* Get DATE/DATETIME/TIME value of the 'b' item. */
1029
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);
1079
1079
if ((res2= (*b)->val_str(&owner->tmp_value2)))
1081
1081
owner->null_value= 0;
1082
uint32_t res1_length= res1->length();
1083
uint32_t res2_length= res2->length();
1084
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));
1085
1085
return cmp ? cmp : (int) (res1_length - res2_length);
1446
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)))
1448
if ((!args[0]->fixed && args[0]->fix_fields(session, args)) ||
1448
if ((!args[0]->fixed && args[0]->fix_fields(thd, args)) ||
1449
1449
(!cache && !(cache= Item_cache::get_cache(args[0]))))
1480
bool Item_in_optimizer::fix_fields(Session *session, Item **ref)
1480
bool Item_in_optimizer::fix_fields(THD *thd, Item **ref)
1482
1482
assert(fixed == 0);
1483
if (fix_left(session, ref))
1483
if (fix_left(thd, ref))
1485
1485
if (args[0]->maybe_null)
1488
if (!args[1]->fixed && args[1]->fix_fields(session, args+1))
1488
if (!args[1]->fixed && args[1]->fix_fields(thd, args+1))
1490
1490
Item_in_subselect * sub= (Item_in_subselect *)args[1];
1491
1491
if (args[0]->cols() != sub->engine->cols())
1635
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
1636
1636
really transformed, i.e. when a new item has been created.
1637
1637
Otherwise we'll be allocating a lot of unnecessary memory for
1638
1638
change records at each execution.
1640
1640
if ((*args) != new_item)
1641
current_session->change_item_tree(args, new_item);
1641
current_thd->change_item_tree(args, new_item);
1644
1644
Transform the right IN operand which should be an Item_in_subselect or a
1949
bool Item_func_between::fix_fields(Session *session, Item **ref)
1949
bool Item_func_between::fix_fields(THD *thd, Item **ref)
1951
if (Item_func_opt_neg::fix_fields(session, ref))
1951
if (Item_func_opt_neg::fix_fields(thd, ref))
1954
session->lex->current_select->between_count++;
1954
thd->lex->current_select->between_count++;
1956
1956
/* not_null_tables_cache == union(T1(e),T1(e1),T1(e2)) */
1957
1957
if (pred_level && !negated)
2029
2029
The following can't be recoded with || as convert_constant_item
2030
2030
changes the argument
2032
if (convert_constant_item(session, field_item, &args[1]))
2032
if (convert_constant_item(thd, field_item, &args[1]))
2033
2033
cmp_type=INT_RESULT; // Works for all types.
2034
if (convert_constant_item(session, field_item, &args[2]))
2034
if (convert_constant_item(thd, field_item, &args[2]))
2035
2035
cmp_type=INT_RESULT; // Works for all types.
2167
2167
agg_result_type(&hybrid_type, args, 2);
2168
2168
maybe_null=args[1]->maybe_null;
2169
decimals= cmax(args[0]->decimals, args[1]->decimals);
2169
decimals= max(args[0]->decimals, args[1]->decimals);
2170
2170
unsigned_flag= args[0]->unsigned_flag && args[1]->unsigned_flag;
2172
2172
if (hybrid_type == DECIMAL_RESULT || hybrid_type == INT_RESULT)
2177
2177
int len1= args[1]->max_length - args[1]->decimals
2178
2178
- (args[1]->unsigned_flag ? 0 : 1);
2180
max_length= cmax(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
2180
max_length= max(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
2183
max_length= cmax(args[0]->max_length, args[1]->max_length);
2183
max_length= max(args[0]->max_length, args[1]->max_length);
2185
2185
switch (hybrid_type) {
2186
2186
case STRING_RESULT:
2203
uint32_t Item_func_ifnull::decimal_precision() const
2203
uint Item_func_ifnull::decimal_precision() const
2205
int max_int_part=cmax(args[0]->decimal_int_part(),args[1]->decimal_int_part());
2206
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);
2315
Item_func_if::fix_fields(Session *session, Item **ref)
2315
Item_func_if::fix_fields(THD *thd, Item **ref)
2317
2317
assert(fixed == 0);
2318
2318
args[0]->top_level_item();
2320
if (Item_func::fix_fields(session, ref))
2320
if (Item_func::fix_fields(thd, ref))
2323
2323
not_null_tables_cache= (args[1]->not_null_tables() &
2331
2331
Item_func_if::fix_length_and_dec()
2333
2333
maybe_null=args[1]->maybe_null || args[2]->maybe_null;
2334
decimals= cmax(args[1]->decimals, args[2]->decimals);
2334
decimals= max(args[1]->decimals, args[2]->decimals);
2335
2335
unsigned_flag=args[1]->unsigned_flag && args[2]->unsigned_flag;
2337
2337
enum Item_result arg1_type=args[1]->result_type();
2375
2375
int len2= args[2]->max_length - args[2]->decimals
2376
2376
- (args[2]->unsigned_flag ? 0 : 1);
2378
max_length=cmax(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
2378
max_length=max(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
2381
max_length= cmax(args[1]->max_length, args[2]->max_length);
2381
max_length= max(args[1]->max_length, args[2]->max_length);
2385
uint32_t Item_func_if::decimal_precision() const
2385
uint Item_func_if::decimal_precision() const
2387
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())+
2389
return cmin(precision, DECIMAL_MAX_PRECISION);
2389
return min(precision, DECIMAL_MAX_PRECISION);
2668
bool Item_func_case::fix_fields(Session *session, Item **ref)
2668
bool Item_func_case::fix_fields(THD *thd, Item **ref)
2671
2671
buff should match stack usage from
2672
2672
Item_func_case::val_int() -> Item_func_case::find_item()
2674
unsigned char 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(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);
2677
2677
Call check_stack_overrun after fix_fields to be sure that stack variable
2678
2678
is not optimized away
2680
if (check_stack_overrun(session, STACK_MIN_SIZE, buff))
2680
if (check_stack_overrun(thd, STACK_MIN_SIZE, buff))
2681
2681
return true; // Fatal error flag is set!
2694
2694
void Item_func_case::agg_num_lengths(Item *arg)
2696
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,
2697
2697
arg->unsigned_flag) - arg->decimals;
2698
2698
set_if_bigger(max_length, len);
2699
2699
set_if_bigger(decimals, arg->decimals);
2766
2766
unsigned_flag= true;
2767
2767
if (cached_result_type == STRING_RESULT)
2769
for (uint32_t i= 0; i < ncases; i+= 2)
2769
for (uint i= 0; i < ncases; i+= 2)
2770
2770
agg_str_lengths(args[i + 1]);
2771
2771
if (else_expr_num != -1)
2772
2772
agg_str_lengths(args[else_expr_num]);
2776
for (uint32_t i= 0; i < ncases; i+= 2)
2776
for (uint i= 0; i < ncases; i+= 2)
2777
2777
agg_num_lengths(args[i + 1]);
2778
2778
if (else_expr_num != -1)
2779
2779
agg_num_lengths(args[else_expr_num]);
2786
uint32_t Item_func_case::decimal_precision() const
2786
uint Item_func_case::decimal_precision() const
2788
2788
int max_int_part=0;
2789
for (uint32_t i=0 ; i < ncases ; i+=2)
2789
for (uint i=0 ; i < ncases ; i+=2)
2790
2790
set_if_bigger(max_int_part, args[i+1]->decimal_int_part());
2792
2792
if (else_expr_num != -1)
2793
2793
set_if_bigger(max_int_part, args[else_expr_num]->decimal_int_part());
2794
return cmin(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2794
return min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
3053
3053
int in_vector::find(Item *item)
3055
unsigned char *result=get_value(item);
3055
uchar *result=get_value(item);
3056
3056
if (!result || !used_count)
3057
3057
return 0; // Null value
3060
3060
start=0; end=used_count-1;
3061
3061
while (start != end)
3063
uint32_t mid=(start+end+1)/2;
3063
uint mid=(start+end+1)/2;
3065
3065
if ((res=(*compare)(collation, base+mid*size, result)) == 0)
3072
3072
return (int) ((*compare)(collation, base+start*size, result) == 0);
3075
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)
3076
3076
:in_vector(elements, sizeof(String), cmp_func, cs),
3077
3077
tmp(buff, sizeof(buff), &my_charset_bin)
3084
3084
// base was allocated with help of sql_alloc => following is OK
3085
for (uint32_t i=0 ; i < count ; i++)
3085
for (uint i=0 ; i < count ; i++)
3086
3086
((String*) base)[i].free();
3090
void in_string::set(uint32_t pos,Item *item)
3090
void in_string::set(uint pos,Item *item)
3092
3092
String *str=((String*) base)+pos;
3093
3093
String *res=item->val_str(str);
3113
unsigned char *in_string::get_value(Item *item)
3113
uchar *in_string::get_value(Item *item)
3115
return (unsigned char*) item->val_str(&tmp);
3115
return (uchar*) item->val_str(&tmp);
3118
in_row::in_row(uint32_t elements, Item * item __attribute__((unused)))
3118
in_row::in_row(uint elements, Item * item __attribute__((unused)))
3120
3120
base= (char*) new cmp_item_row[count= elements];
3121
3121
size= sizeof(cmp_item_row);
3134
3134
delete [] (cmp_item_row*) base;
3137
unsigned char *in_row::get_value(Item *item)
3137
uchar *in_row::get_value(Item *item)
3139
3139
tmp.store_value(item);
3140
3140
if (item->is_null())
3142
return (unsigned char *)&tmp;
3142
return (uchar *)&tmp;
3145
void in_row::set(uint32_t pos, Item *item)
3145
void in_row::set(uint pos, Item *item)
3147
3147
((cmp_item_row*) base)[pos].store_value_by_template(&tmp, item);
3151
in_int64_t::in_int64_t(uint32_t elements)
3151
in_int64_t::in_int64_t(uint elements)
3152
3152
:in_vector(elements,sizeof(packed_int64_t),(qsort2_cmp) cmp_int64_t, 0)
3155
void in_int64_t::set(uint32_t pos,Item *item)
3155
void in_int64_t::set(uint pos,Item *item)
3157
3157
struct packed_int64_t *buff= &((packed_int64_t*) base)[pos];
3160
3160
buff->unsigned_flag= item->unsigned_flag;
3163
unsigned char *in_int64_t::get_value(Item *item)
3163
uchar *in_int64_t::get_value(Item *item)
3165
3165
tmp.val= item->val_int();
3166
3166
if (item->null_value)
3168
3168
tmp.unsigned_flag= item->unsigned_flag;
3169
return (unsigned char*) &tmp;
3169
return (uchar*) &tmp;
3172
void in_datetime::set(uint32_t pos,Item *item)
3172
void in_datetime::set(uint pos,Item *item)
3174
3174
Item **tmp_item= &item;
3176
3176
struct packed_int64_t *buff= &((packed_int64_t*) base)[pos];
3178
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);
3179
3179
buff->unsigned_flag= 1L;
3182
unsigned char *in_datetime::get_value(Item *item)
3182
uchar *in_datetime::get_value(Item *item)
3185
3185
Item **tmp_item= lval_cache ? &lval_cache : &item;
3186
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);
3187
3187
if (item->null_value)
3189
3189
tmp.unsigned_flag= 1L;
3190
return (unsigned char*) &tmp;
3190
return (uchar*) &tmp;
3193
in_double::in_double(uint32_t elements)
3193
in_double::in_double(uint elements)
3194
3194
:in_vector(elements,sizeof(double),(qsort2_cmp) cmp_double, 0)
3197
void in_double::set(uint32_t pos,Item *item)
3197
void in_double::set(uint pos,Item *item)
3199
3199
((double*) base)[pos]= item->val_real();
3202
unsigned char *in_double::get_value(Item *item)
3202
uchar *in_double::get_value(Item *item)
3204
3204
tmp= item->val_real();
3205
3205
if (item->null_value)
3206
3206
return 0; /* purecov: inspected */
3207
return (unsigned char*) &tmp;
3207
return (uchar*) &tmp;
3211
in_decimal::in_decimal(uint32_t elements)
3211
in_decimal::in_decimal(uint elements)
3212
3212
:in_vector(elements, sizeof(my_decimal),(qsort2_cmp) cmp_decimal, 0)
3216
void in_decimal::set(uint32_t pos, Item *item)
3216
void in_decimal::set(uint pos, Item *item)
3218
3218
/* as far as 'item' is constant, we can store reference on my_decimal */
3219
3219
my_decimal *dec= ((my_decimal *)base) + pos;
3420
3420
Item **tmp_item= lval_cache ? &lval_cache : &item;
3421
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);
3488
Item_func_in::fix_fields(Session *session, Item **ref)
3488
Item_func_in::fix_fields(THD *thd, Item **ref)
3490
3490
Item **arg, **arg_end;
3492
if (Item_func_opt_neg::fix_fields(session, ref))
3492
if (Item_func_opt_neg::fix_fields(thd, ref))
3495
3495
/* not_null_tables_cache == union(T1(e),union(T1(ei))) */
3508
3508
static int srtcmp_in(const CHARSET_INFO * const cs, const String *x,const String *y)
3510
3510
return cs->coll->strnncollsp(cs,
3511
(unsigned char *) x->ptr(),x->length(),
3512
(unsigned char *) y->ptr(),y->length(), 0);
3511
(uchar *) x->ptr(),x->length(),
3512
(uchar *) y->ptr(),y->length(), 0);
3518
3518
Item **arg, **arg_end;
3519
3519
bool const_itm= 1;
3520
Session *session= current_session;
3520
THD *thd= current_thd;
3521
3521
bool datetime_found= false;
3522
3522
/* true <=> arguments values will be compared as DATETIMEs. */
3523
3523
bool compare_as_datetime= false;
3524
3524
Item *date_arg= 0;
3525
uint32_t found_types= 0;
3526
uint32_t type_cnt= 0, i;
3525
uint found_types= 0;
3526
uint type_cnt= 0, i;
3527
3527
Item_result cmp_type= STRING_RESULT;
3528
3528
left_result_type= args[0]->result_type();
3529
3529
if (!(found_types= collect_cmp_types(args, arg_count)))
3664
3664
bool all_converted= true;
3665
3665
for (arg=args+1, arg_end=args+arg_count; arg != arg_end ; arg++)
3667
if (!convert_constant_item (session, field_item, &arg[0]))
3667
if (!convert_constant_item (thd, field_item, &arg[0]))
3668
3668
all_converted= false;
3670
3670
if (all_converted)
3850
3850
return (int64_t) (arg1 & arg2);
3853
Item_cond::Item_cond(Session *session, Item_cond *item)
3854
:Item_bool_func(session, item),
3853
Item_cond::Item_cond(THD *thd, Item_cond *item)
3854
:Item_bool_func(thd, item),
3855
3855
abort_on_null(item->abort_on_null),
3856
3856
and_tables_cache(item->and_tables_cache)
3864
void Item_cond::copy_andor_arguments(Session *session, Item_cond *item)
3864
void Item_cond::copy_andor_arguments(THD *thd, Item_cond *item)
3866
3866
List_iterator_fast<Item> li(item->list);
3867
3867
while (Item *it= li++)
3868
list.push_back(it->copy_andor_structure(session));
3868
list.push_back(it->copy_andor_structure(thd));
3873
Item_cond::fix_fields(Session *session, Item **ref __attribute__((unused)))
3873
Item_cond::fix_fields(THD *thd, Item **ref __attribute__((unused)))
3875
3875
assert(fixed == 0);
3876
3876
List_iterator<Item> li(list);
3878
void *orig_session_marker= session->session_marker;
3879
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
3880
3880
not_null_tables_cache= used_tables_cache= 0;
3881
3881
const_item_cache= 1;
3883
3883
if (functype() == COND_OR_FUNC)
3884
session->session_marker= 0;
3886
3886
and_table_cache is the value that Item_cond_or() returns for
3887
3887
not_null_tables()
3889
3889
and_tables_cache= ~(table_map) 0;
3891
if (check_stack_overrun(session, STACK_MIN_SIZE, buff))
3891
if (check_stack_overrun(thd, STACK_MIN_SIZE, buff))
3892
3892
return true; // Fatal error flag is set!
3894
3894
The following optimization reduces the depth of an AND-OR tree.
3922
3922
// item can be substituted in fix_fields
3923
3923
if ((!item->fixed &&
3924
item->fix_fields(session, li.ref())) ||
3924
item->fix_fields(thd, li.ref())) ||
3925
3925
(item= *li.ref())->check_cols(1))
3926
3926
return true; /* purecov: inspected */
3927
3927
used_tables_cache|= item->used_tables();
4022
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
4023
4023
really transformed, i.e. when a new item has been created.
4024
4024
Otherwise we'll be allocating a lot of unnecessary memory for
4025
4025
change records at each execution.
4027
4027
if (new_item != item)
4028
current_session->change_item_tree(li.ref(), new_item);
4028
current_thd->change_item_tree(li.ref(), new_item);
4030
4030
return Item_func::transform(transformer, arg);
4055
4055
Item returned as the result of transformation of the root node
4058
Item *Item_cond::compile(Item_analyzer analyzer, unsigned char **arg_p,
4059
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)
4061
4061
if (!(this->*analyzer)(arg_p))
4069
4069
The same parameter value of arg_p must be passed
4070
4070
to analyze any argument of the condition formula.
4072
unsigned char *arg_v= *arg_p;
4072
uchar *arg_v= *arg_p;
4073
4073
Item *new_item= item->compile(analyzer, &arg_v, transformer, arg_t);
4074
4074
if (new_item && new_item != item)
4075
4075
li.replace(new_item);
4118
4118
that have or refer (HAVING) to a SUM expression.
4121
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,
4122
4122
List<Item> &fields)
4124
4124
List_iterator<Item> li(list);
4126
4126
while ((item= li++))
4127
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);
4172
void Item_cond::neg_arguments(Session *session)
4172
void Item_cond::neg_arguments(THD *thd)
4174
4174
List_iterator<Item> li(list);
4176
4176
while ((item= li++)) /* Apply not transformation to the arguments */
4178
Item *new_item= item->neg_transformer(session);
4178
Item *new_item= item->neg_transformer(thd);
4181
4181
if (!(new_item= new Item_func_not(item)))
4182
4182
return; // Fatal OEM error
4184
li.replace(new_item);
4184
VOID(li.replace(new_item));
4402
bool Item_func_like::fix_fields(Session *session, Item **ref)
4402
bool Item_func_like::fix_fields(THD *thd, Item **ref)
4404
4404
assert(fixed == 0);
4405
if (Item_bool_func2::fix_fields(session, ref) ||
4406
escape_item->fix_fields(session, &escape_item))
4405
if (Item_bool_func2::fix_fields(thd, ref) ||
4406
escape_item->fix_fields(thd, &escape_item))
4409
4409
if (!escape_item->const_during_execution())
4429
4429
const CHARSET_INFO * const cs= escape_str->charset();
4431
4431
int rc= cs->cset->mb_wc(cs, &wc,
4432
(const unsigned char*) escape_str->ptr(),
4433
(const unsigned char*) escape_str->ptr() +
4432
(const uchar*) escape_str->ptr(),
4433
(const uchar*) escape_str->ptr() +
4434
4434
escape_str->length());
4435
4435
escape= (int) (rc > 0 ? wc : '\\');
4713
4713
turboShift = u - v;
4714
4714
bcShift = bmBc[(uint) likeconv(cs, text[i + j])] - plm1 + i;
4715
4715
shift = (turboShift > bcShift) ? turboShift : bcShift;
4716
shift = cmax(shift, bmGs[i]);
4716
shift = max(shift, bmGs[i]);
4717
4717
if (shift == bmGs[i])
4718
4718
u = (pattern_len - shift < v) ? pattern_len - shift : v;
4721
4721
if (turboShift < bcShift)
4722
shift = cmax(shift, u + 1);
4722
shift = max(shift, u + 1);
4783
4783
IS NOT NULL(a) -> IS NULL(a)
4786
@param session thread handler
4786
@param thd thread handler
4790
4790
NULL if we cannot apply NOT transformation (see Item::neg_transformer()).
4793
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 */
4795
4795
return args[0];
4799
Item *Item_bool_rowready_func2::neg_transformer(Session *session __attribute__((unused)))
4799
Item *Item_bool_rowready_func2::neg_transformer(THD *thd __attribute__((unused)))
4801
4801
Item *item= negated_item();
4817
4817
a IS NOT NULL -> a IS NULL.
4819
Item *Item_func_isnotnull::neg_transformer(Session *session __attribute__((unused)))
4819
Item *Item_func_isnotnull::neg_transformer(THD *thd __attribute__((unused)))
4821
4821
Item *item= new Item_func_isnull(args[0]);
4826
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 ...) -> */
4827
4827
/* NOT a OR NOT b OR ... */
4829
neg_arguments(session);
4830
4830
Item *item= new Item_cond_or(list);
4835
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 ...) -> */
4836
4836
/* NOT a AND NOT b AND ... */
4838
neg_arguments(session);
4839
4839
Item *item= new Item_cond_and(list);
4844
Item *Item_func_nop_all::neg_transformer(Session *session __attribute__((unused)))
4844
Item *Item_func_nop_all::neg_transformer(THD *thd __attribute__((unused)))
4846
4846
/* "NOT (e $cmp$ ANY (SELECT ...)) -> e $rev_cmp$" ALL (SELECT ...) */
4847
4847
Item_func_not_all *new_item= new Item_func_not_all(args[0]);
5182
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
5183
5183
really transformed, i.e. when a new item has been created.
5184
5184
Otherwise we'll be allocating a lot of unnecessary memory for
5185
5185
change records at each execution.
5187
5187
if (new_item != item)
5188
current_session->change_item_tree((Item **) it.ref(), new_item);
5188
current_thd->change_item_tree((Item **) it.ref(), new_item);
5190
5190
return Item_func::transform(transformer, arg);