538
540
if (field_item->field->can_be_compared_as_int64_t() &&
539
541
!(field_item->is_datetime() && args[1]->result_type() == STRING_RESULT))
541
if (convert_constant_item(&getSession(), field_item, &args[1]))
543
if (convert_constant_item(session, field_item, &args[1]))
543
545
cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
544
546
INT_RESULT); // Works for all types.
554
556
!(field_item->is_datetime() &&
555
557
args[0]->result_type() == STRING_RESULT))
557
if (convert_constant_item(&getSession(), field_item, &args[0]))
559
if (convert_constant_item(session, field_item, &args[0]))
559
561
cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
560
562
INT_RESULT); // Works for all types.
694
696
converted value. 0 on error and on zero-dates -- check 'failure'
698
get_date_from_str(Session *session, String *str, type::timestamp_t warn_type,
700
get_date_from_str(Session *session, String *str, enum enum_drizzle_timestamp_type warn_type,
699
701
char *warn_name, bool *error_arg)
702
type::cut_t error= type::VALID;
704
type::timestamp_t ret;
706
ret= l_time.store(str->ptr(), str->length(),
707
(TIME_FUZZY_DATE | MODE_INVALID_DATES | (session->variables.sql_mode & MODE_NO_ZERO_DATE)),
710
if (ret == type::DRIZZLE_TIMESTAMP_DATETIME || ret == type::DRIZZLE_TIMESTAMP_DATE)
706
enum enum_drizzle_timestamp_type ret;
708
ret= str_to_datetime(str->ptr(), str->length(), &l_time,
709
(TIME_FUZZY_DATE | MODE_INVALID_DATES |
710
(session->variables.sql_mode & MODE_NO_ZERO_DATE)),
713
if (ret == DRIZZLE_TIMESTAMP_DATETIME || ret == DRIZZLE_TIMESTAMP_DATE)
713
716
Do not return yet, we may still want to throw a "trailing garbage"
716
719
*error_arg= false;
717
l_time.convert(value);
720
value= TIME_to_uint64_t_datetime(&l_time);
721
724
*error_arg= true;
722
error= type::CUT; /* force warning */
725
error= 1; /* force warning */
725
if (error != type::VALID)
727
730
make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
728
731
str->ptr(), str->length(),
768
771
enum Arg_comparator::enum_date_cmp_type
769
772
Arg_comparator::can_compare_as_dates(Item *in_a, Item *in_b,
770
int64_t *const_value)
773
uint64_t *const_value)
772
775
enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
773
776
Item *str_arg= 0, *date_arg= 0;
862
865
Item **a1, Item **a2,
863
866
Item_result type)
865
enum_date_cmp_type cmp_type;
866
int64_t const_value= -1;
868
enum enum_date_cmp_type cmp_type;
869
uint64_t const_value= (uint64_t)-1;
870
873
if ((cmp_type= can_compare_as_dates(*a, *b, &const_value)))
875
session= current_session;
872
876
owner= owner_arg;
873
877
a_type= (*a)->field_type();
874
878
b_type= (*b)->field_type();
878
if (const_value != -1)
882
if (const_value != (uint64_t)-1)
880
884
Item_cache_int *cache= new Item_cache_int();
881
885
/* Mark the cache as non-const to prevent re-caching. */
993
995
enum_field_types f_type= warn_item->field_type();
994
type::timestamp_t t_type= f_type == DRIZZLE_TYPE_DATE ? type::DRIZZLE_TIMESTAMP_DATE : type::DRIZZLE_TIMESTAMP_DATETIME;
996
enum enum_drizzle_timestamp_type t_type= f_type ==
997
DRIZZLE_TYPE_DATE ? DRIZZLE_TIMESTAMP_DATE : DRIZZLE_TIMESTAMP_DATETIME;
995
998
value= get_date_from_str(session, str, t_type, warn_item->name, &error);
997
1000
If str did not contain a valid date according to the current
1172
1174
int Arg_comparator::compare_decimal()
1174
type::Decimal value1;
1175
type::Decimal *val1= (*a)->val_decimal(&value1);
1177
my_decimal *val1= (*a)->val_decimal(&value1);
1176
1178
if (!(*a)->null_value)
1178
type::Decimal value2;
1179
type::Decimal *val2= (*b)->val_decimal(&value2);
1181
my_decimal *val2= (*b)->val_decimal(&value2);
1180
1182
if (!(*b)->null_value)
1182
1184
owner->null_value= 0;
1199
1201
int Arg_comparator::compare_e_decimal()
1201
type::Decimal value1, value2;
1202
type::Decimal *val1= (*a)->val_decimal(&value1);
1203
type::Decimal *val2= (*b)->val_decimal(&value2);
1203
my_decimal value1, value2;
1204
my_decimal *val1= (*a)->val_decimal(&value1);
1205
my_decimal *val2= (*b)->val_decimal(&value2);
1204
1206
if ((*a)->null_value || (*b)->null_value)
1205
1207
return test((*a)->null_value && (*b)->null_value);
1206
1208
return test(class_decimal_cmp(val1, val2) == 0);
1666
1668
change records at each execution.
1668
1670
if ((*args) != new_item)
1669
getSession().change_item_tree(args, new_item);
1671
current_session->change_item_tree(args, new_item);
1672
1674
Transform the right IN operand which should be an Item_in_subselect or a
1879
1881
dec= row->element_index(0)->val_decimal(&dec_buf);
1880
1882
if (row->element_index(0)->null_value)
1882
class_decimal2double(E_DEC_FATAL_ERROR, dec, &value);
1884
my_decimal2double(E_DEC_FATAL_ERROR, dec, &value);
1925
1927
((el->result_type() == DECIMAL_RESULT) ||
1926
1928
(el->result_type() == INT_RESULT)))
1928
type::Decimal e_dec_buf, *e_dec= el->val_decimal(&e_dec_buf);
1930
my_decimal e_dec_buf, *e_dec= el->val_decimal(&e_dec_buf);
1929
1931
/* Skip NULL ranges. */
1930
1932
if (el->null_value)
2046
2049
The following can't be recoded with || as convert_constant_item
2047
2050
changes the argument
2049
if (convert_constant_item(&getSession(), field_item, &args[1]))
2052
if (convert_constant_item(session, field_item, &args[1]))
2050
2053
cmp_type=INT_RESULT; // Works for all types.
2051
if (convert_constant_item(&getSession(), field_item, &args[2]))
2054
if (convert_constant_item(session, field_item, &args[2]))
2052
2055
cmp_type=INT_RESULT; // Works for all types.
2126
2129
else if (cmp_type == DECIMAL_RESULT)
2128
type::Decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
2131
my_decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
2129
2132
a_buf, *a_dec, b_buf, *b_dec;
2130
2133
if ((null_value=args[0]->null_value))
2276
type::Decimal *Item_func_ifnull::decimal_op(type::Decimal *decimal_value)
2279
my_decimal *Item_func_ifnull::decimal_op(my_decimal *decimal_value)
2278
2281
assert(fixed == 1);
2279
type::Decimal *value= args[0]->val_decimal(decimal_value);
2282
my_decimal *value= args[0]->val_decimal(decimal_value);
2280
2283
if (!args[0]->null_value)
2450
Item_func_if::val_decimal(type::Decimal *decimal_value)
2453
Item_func_if::val_decimal(my_decimal *decimal_value)
2452
2455
assert(fixed == 1);
2453
2456
Item *arg= args[0]->val_bool() ? args[1] : args[2];
2454
type::Decimal *value= arg->val_decimal(decimal_value);
2457
my_decimal *value= arg->val_decimal(decimal_value);
2455
2458
null_value= arg->null_value;
2671
type::Decimal *Item_func_case::val_decimal(type::Decimal *decimal_value)
2674
my_decimal *Item_func_case::val_decimal(my_decimal *decimal_value)
2673
2676
assert(fixed == 1);
2674
2677
char buff[MAX_FIELD_WIDTH];
2675
2678
String dummy_str(buff, sizeof(buff), default_charset());
2676
2679
Item *item= find_item(&dummy_str);
2910
type::Decimal *Item_func_coalesce::decimal_op(type::Decimal *decimal_value)
2913
my_decimal *Item_func_coalesce::decimal_op(my_decimal *decimal_value)
2912
2915
assert(fixed == 1);
2914
2917
for (uint32_t i= 0; i < arg_count; i++)
2916
type::Decimal *res= args[i]->val_decimal(decimal_value);
2919
my_decimal *res= args[i]->val_decimal(decimal_value);
2917
2920
if (!args[i]->null_value)
3065
static int cmp_decimal(void *, type::Decimal *a, type::Decimal *b)
3068
static int cmp_decimal(void *, my_decimal *a, my_decimal *b)
3068
3071
We need call of fixing buffer pointer, because fast sort just copy
3181
in_int64_t::in_int64_t(uint32_t elements) :
3182
in_vector(elements, sizeof(packed_int64_t),(qsort2_cmp) cmp_int64_t, 0)
3184
in_int64_t::in_int64_t(uint32_t elements)
3185
:in_vector(elements,sizeof(packed_int64_t),(qsort2_cmp) cmp_int64_t, 0)
3185
3188
void in_int64_t::set(uint32_t pos,Item *item)
3241
3244
in_decimal::in_decimal(uint32_t elements)
3242
:in_vector(elements, sizeof(type::Decimal),(qsort2_cmp) cmp_decimal, 0)
3245
:in_vector(elements, sizeof(my_decimal),(qsort2_cmp) cmp_decimal, 0)
3246
3249
void in_decimal::set(uint32_t pos, Item *item)
3248
/* as far as 'item' is constant, we can store reference on type::Decimal */
3249
type::Decimal *dec= ((type::Decimal *)base) + pos;
3251
/* as far as 'item' is constant, we can store reference on my_decimal */
3252
my_decimal *dec= ((my_decimal *)base) + pos;
3250
3253
dec->len= DECIMAL_BUFF_LENGTH;
3251
3254
dec->fix_buffer_pointer();
3252
type::Decimal *res= item->val_decimal(dec);
3255
my_decimal *res= item->val_decimal(dec);
3253
3256
/* if item->val_decimal() is evaluated to NULL then res == 0 */
3254
3257
if (!item->null_value && res != dec)
3255
class_decimal2decimal(res, dec);
3258
my_decimal2decimal(res, dec);
3259
3262
unsigned char *in_decimal::get_value(Item *item)
3261
type::Decimal *result= item->val_decimal(&val);
3264
my_decimal *result= item->val_decimal(&val);
3262
3265
if (item->null_value)
3264
3267
return (unsigned char *)result;
3418
3421
void cmp_item_decimal::store_value(Item *item)
3420
type::Decimal *val= item->val_decimal(&value);
3423
my_decimal *val= item->val_decimal(&value);
3421
3424
/* val may be zero if item is nnull */
3422
3425
if (val && val != &value)
3423
class_decimal2decimal(val, &value);
3426
my_decimal2decimal(val, &value);
3427
3430
int cmp_item_decimal::cmp(Item *arg)
3429
type::Decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
3432
my_decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
3430
3433
if (arg->null_value)
3432
3435
return class_decimal_cmp(&value, tmp);
3696
3700
bool all_converted= true;
3697
3701
for (arg=args+1, arg_end=args+arg_count; arg != arg_end ; arg++)
3699
if (!convert_constant_item (&getSession(), field_item, &arg[0]))
3703
if (!convert_constant_item (session, field_item, &arg[0]))
3700
3704
all_converted= false;
3702
3706
if (all_converted)
3851
3855
Item_cond::Item_cond(Session *session, Item_cond *item)
3852
:item::function::Boolean(session, item),
3856
:Item_bool_func(session, item),
3853
3857
abort_on_null(item->abort_on_null),
3854
3858
and_tables_cache(item->and_tables_cache)
3876
3880
void *orig_session_marker= session->session_marker;
3877
3881
unsigned char buff[sizeof(char*)]; // Max local vars in function
3878
3882
not_null_tables_cache= used_tables_cache= 0;
3879
const_item_cache= true;
3883
const_item_cache= 1;
3881
3885
if (functype() == COND_OR_FUNC)
3882
3886
session->session_marker= 0;
4023
4027
change records at each execution.
4025
4029
if (new_item != item)
4026
getSession().change_item_tree(li.ref(), new_item);
4030
current_session->change_item_tree(li.ref(), new_item);
4028
4032
return Item_func::transform(transformer, arg);
4464
4468
pattern = first + 1;
4465
4469
pattern_len = (int) len - 2;
4466
int *suff = (int*) session->getMemRoot()->allocate((int) (sizeof(int)*
4467
((pattern_len + 1)*2+
4470
int *suff = (int*) session->alloc((int) (sizeof(int)*
4471
((pattern_len + 1)*2+
4469
4473
bmGs = suff + pattern_len + 1;
4470
4474
bmBc = bmGs + pattern_len + 1;
4471
4475
turboBM_compute_good_suffix_shifts(suff);
4482
4486
Item_bool_func2::cleanup();
4485
static unsigned char likeconv(const CHARSET_INFO *cs, unsigned char a)
4487
4489
#ifdef LIKE_CMP_TOUPPER
4488
return cs->toupper(a);
4490
#define likeconv(cs,A) (unsigned char) (cs)->toupper(A)
4490
return cs->sort_order[a];
4492
#define likeconv(cs,A) (unsigned char) (cs)->sort_order[(unsigned char) (A)]
4495
4497
Precomputation dependent only on pattern_len.
4886
4888
Item_equal::Item_equal(Item_field *f1, Item_field *f2)
4887
: item::function::Boolean(), const_item(0), eval_item(0), cond_false(0)
4889
: Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
4889
const_item_cache= false;
4891
const_item_cache= 0;
4890
4892
fields.push_back(f1);
4891
4893
fields.push_back(f2);
4894
4896
Item_equal::Item_equal(Item *c, Item_field *f)
4895
: item::function::Boolean(), eval_item(0), cond_false(0)
4897
: Item_bool_func(), eval_item(0), cond_false(0)
4897
const_item_cache= false;
4899
const_item_cache= 0;
4898
4900
fields.push_back(f);
4903
4905
Item_equal::Item_equal(Item_equal *item_equal)
4904
: item::function::Boolean(), eval_item(0), cond_false(0)
4906
: Item_bool_func(), eval_item(0), cond_false(0)
4906
const_item_cache= false;
4908
const_item_cache= 0;
4907
4909
List_iterator_fast<Item_field> li(item_equal->fields);
4908
4910
Item_field *item;
4909
4911
while ((item= li++))
5111
5113
List_iterator_fast<Item_field> it(fields);
5112
5114
Item *item= const_item ? const_item : it++;
5115
if ((null_value= item->null_value))
5113
5117
eval_item->store_value(item);
5114
if ((null_value= item->null_value))
5116
5118
while ((item_field= it++))
5118
5120
/* Skip fields of non-const tables. They haven't been read yet */
5119
5121
if (item_field->field->getTable()->const_table)
5121
if (eval_item->cmp(item_field) || (null_value= item_field->null_value))
5123
if ((null_value= item_field->null_value) || eval_item->cmp(item_field))
5161
5163
change records at each execution.
5163
5165
if (new_item != item)
5164
getSession().change_item_tree((Item **) it.ref(), new_item);
5166
current_session->change_item_tree((Item **) it.ref(), new_item);
5166
5168
return Item_func::transform(transformer, arg);