572
574
func= comparator_matrix[type]
573
[test(owner->functype() == Item_func::EQUAL_FUNC)];
575
[test(owner->functype() == Item_func::EQUAL_FUNC)];
577
uint32_t n= (*a)->cols();
578
if (n != (*b)->cols())
580
my_error(ER_OPERAND_COLUMNS, MYF(0), n);
584
if (!(comparators= new Arg_comparator[n]))
586
for (uint32_t i=0; i < n; i++)
588
if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
590
my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols());
593
comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
580
uint32_t n= (*a)->cols();
581
if (n != (*b)->cols())
583
my_error(ER_OPERAND_COLUMNS, MYF(0), n);
587
if (!(comparators= new Arg_comparator[n]))
589
for (uint32_t i=0; i < n; i++)
591
if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
593
my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols());
596
comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
597
601
case STRING_RESULT:
600
We must set cmp_charset here as we may be called from for an automatic
601
generated item, like in natural join
603
if (cmp_collation.set((*a)->collation, (*b)->collation) ||
604
cmp_collation.derivation == DERIVATION_NONE)
606
my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
609
if (cmp_collation.collation == &my_charset_bin)
612
We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
613
without removing end space
604
We must set cmp_charset here as we may be called from for an automatic
605
generated item, like in natural join
615
if (func == &Arg_comparator::compare_string)
616
func= &Arg_comparator::compare_binary_string;
617
else if (func == &Arg_comparator::compare_e_string)
618
func= &Arg_comparator::compare_e_binary_string;
607
if (cmp_collation.set((*a)->collation, (*b)->collation) ||
608
cmp_collation.derivation == DERIVATION_NONE)
610
my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
613
if (cmp_collation.collation == &my_charset_bin)
616
We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
617
without removing end space
619
if (func == &Arg_comparator::compare_string)
620
func= &Arg_comparator::compare_binary_string;
621
else if (func == &Arg_comparator::compare_e_string)
622
func= &Arg_comparator::compare_e_binary_string;
621
As this is binary compassion, mark all fields that they can't be
622
transformed. Otherwise we would get into trouble with comparisons
624
WHERE col= 'j' AND col LIKE BINARY 'j'
625
which would be transformed to:
625
As this is binary compassion, mark all fields that they can't be
626
transformed. Otherwise we would get into trouble with comparisons
628
WHERE col= 'j' AND col LIKE BINARY 'j'
629
which would be transformed to:
628
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
629
(*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
632
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
633
(*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
635
if (func == &Arg_comparator::compare_int_signed)
637
if ((*a)->unsigned_flag)
638
func= (((*b)->unsigned_flag)?
639
&Arg_comparator::compare_int_unsigned :
640
&Arg_comparator::compare_int_unsigned_signed);
641
else if ((*b)->unsigned_flag)
642
func= &Arg_comparator::compare_int_signed_unsigned;
644
else if (func== &Arg_comparator::compare_e_int)
646
if ((*a)->unsigned_flag ^ (*b)->unsigned_flag)
647
func= &Arg_comparator::compare_e_int_diff_signedness;
639
if (func == &Arg_comparator::compare_int_signed)
641
if ((*a)->unsigned_flag)
642
func= (((*b)->unsigned_flag)?
643
&Arg_comparator::compare_int_unsigned :
644
&Arg_comparator::compare_int_unsigned_signed);
645
else if ((*b)->unsigned_flag)
646
func= &Arg_comparator::compare_int_signed_unsigned;
648
else if (func== &Arg_comparator::compare_e_int)
650
if ((*a)->unsigned_flag ^ (*b)->unsigned_flag)
651
func= &Arg_comparator::compare_e_int_diff_signedness;
651
655
case DECIMAL_RESULT:
653
657
case REAL_RESULT:
655
if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
657
precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
658
if (func == &Arg_comparator::compare_real)
659
func= &Arg_comparator::compare_real_fixed;
660
else if (func == &Arg_comparator::compare_e_real)
661
func= &Arg_comparator::compare_e_real_fixed;
659
if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
661
precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
662
if (func == &Arg_comparator::compare_real)
663
func= &Arg_comparator::compare_real_fixed;
664
else if (func == &Arg_comparator::compare_e_real)
665
func= &Arg_comparator::compare_e_real_fixed;
691
694
converted value. 0 on error and on zero-dates -- check 'failure'
695
get_date_from_str(Session *session, String *str, enum enum_drizzle_timestamp_type warn_type,
698
get_date_from_str(Session *session, String *str, type::timestamp_t warn_type,
696
699
char *warn_name, bool *error_arg)
701
enum enum_drizzle_timestamp_type ret;
703
ret= str_to_datetime(str->ptr(), str->length(), &l_time,
704
(TIME_FUZZY_DATE | MODE_INVALID_DATES |
705
(session->variables.sql_mode & MODE_NO_ZERO_DATE)),
708
if (ret == DRIZZLE_TIMESTAMP_DATETIME || ret == DRIZZLE_TIMESTAMP_DATE)
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)
711
713
Do not return yet, we may still want to throw a "trailing garbage"
714
716
*error_arg= false;
715
value= TIME_to_uint64_t_datetime(&l_time);
717
l_time.convert(value);
719
721
*error_arg= true;
720
error= 1; /* force warning */
722
error= type::CUT; /* force warning */
725
if (error != type::VALID)
724
727
make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
725
728
str->ptr(), str->length(),
726
729
warn_type, warn_name);
764
768
enum Arg_comparator::enum_date_cmp_type
765
Arg_comparator::can_compare_as_dates(Item *a, Item *b, uint64_t *const_value)
769
Arg_comparator::can_compare_as_dates(Item *in_a, Item *in_b,
770
int64_t *const_value)
767
772
enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
768
773
Item *str_arg= 0, *date_arg= 0;
770
if (a->type() == Item::ROW_ITEM || b->type() == Item::ROW_ITEM)
775
if (in_a->type() == Item::ROW_ITEM || in_b->type() == Item::ROW_ITEM)
771
776
return CMP_DATE_DFLT;
773
if (a->is_datetime())
778
if (in_a->is_datetime())
775
if (b->is_datetime())
780
if (in_b->is_datetime())
776
782
cmp_type= CMP_DATE_WITH_DATE;
777
else if (b->result_type() == STRING_RESULT)
784
else if (in_b->result_type() == STRING_RESULT)
779
786
cmp_type= CMP_DATE_WITH_STR;
784
else if (b->is_datetime() && a->result_type() == STRING_RESULT)
791
else if (in_b->is_datetime() && in_a->result_type() == STRING_RESULT)
786
793
cmp_type= CMP_STR_WITH_DATE;
791
798
if (cmp_type != CMP_DATE_DFLT)
2122
2126
else if (cmp_type == DECIMAL_RESULT)
2124
my_decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
2128
type::Decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
2125
2129
a_buf, *a_dec, b_buf, *b_dec;
2126
2130
if ((null_value=args[0]->null_value))
2128
2132
a_dec= args[1]->val_decimal(&a_buf);
2129
2133
b_dec= args[2]->val_decimal(&b_buf);
2130
2134
if (!args[1]->null_value && !args[2]->null_value)
2131
return (int64_t) ((my_decimal_cmp(dec, a_dec) >= 0 &&
2132
my_decimal_cmp(dec, b_dec) <= 0) != negated);
2135
return (int64_t) ((class_decimal_cmp(dec, a_dec) >= 0 &&
2136
class_decimal_cmp(dec, b_dec) <= 0) != negated);
2133
2137
if (args[1]->null_value && args[2]->null_value)
2135
2139
else if (args[1]->null_value)
2136
null_value= (my_decimal_cmp(dec, b_dec) <= 0);
2140
null_value= (class_decimal_cmp(dec, b_dec) <= 0);
2138
null_value= (my_decimal_cmp(dec, a_dec) >= 0);
2142
null_value= (class_decimal_cmp(dec, a_dec) >= 0);
3231
3241
in_decimal::in_decimal(uint32_t elements)
3232
:in_vector(elements, sizeof(my_decimal),(qsort2_cmp) cmp_decimal, 0)
3242
:in_vector(elements, sizeof(type::Decimal),(qsort2_cmp) cmp_decimal, 0)
3236
3246
void in_decimal::set(uint32_t pos, Item *item)
3238
/* as far as 'item' is constant, we can store reference on my_decimal */
3239
my_decimal *dec= ((my_decimal *)base) + pos;
3248
/* as far as 'item' is constant, we can store reference on type::Decimal */
3249
type::Decimal *dec= ((type::Decimal *)base) + pos;
3240
3250
dec->len= DECIMAL_BUFF_LENGTH;
3241
3251
dec->fix_buffer_pointer();
3242
my_decimal *res= item->val_decimal(dec);
3252
type::Decimal *res= item->val_decimal(dec);
3243
3253
/* if item->val_decimal() is evaluated to NULL then res == 0 */
3244
3254
if (!item->null_value && res != dec)
3245
my_decimal2decimal(res, dec);
3255
class_decimal2decimal(res, dec);
3249
3259
unsigned char *in_decimal::get_value(Item *item)
3251
my_decimal *result= item->val_decimal(&val);
3261
type::Decimal *result= item->val_decimal(&val);
3252
3262
if (item->null_value)
3254
3264
return (unsigned char *)result;
3406
3418
void cmp_item_decimal::store_value(Item *item)
3408
my_decimal *val= item->val_decimal(&value);
3420
type::Decimal *val= item->val_decimal(&value);
3409
3421
/* val may be zero if item is nnull */
3410
3422
if (val && val != &value)
3411
my_decimal2decimal(val, &value);
3423
class_decimal2decimal(val, &value);
3415
3427
int cmp_item_decimal::cmp(Item *arg)
3417
my_decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
3429
type::Decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
3418
3430
if (arg->null_value)
3420
return my_decimal_cmp(&value, tmp);
3432
return class_decimal_cmp(&value, tmp);
3424
3436
int cmp_item_decimal::compare(cmp_item *arg)
3426
3438
cmp_item_decimal *l_cmp= (cmp_item_decimal*) arg;
3427
return my_decimal_cmp(&value, &l_cmp->value);
3439
return class_decimal_cmp(&value, &l_cmp->value);
4869
4886
Item_equal::Item_equal(Item_field *f1, Item_field *f2)
4870
: Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
4887
: item::function::Boolean(), const_item(0), eval_item(0), cond_false(0)
4872
const_item_cache= 0;
4889
const_item_cache= false;
4873
4890
fields.push_back(f1);
4874
4891
fields.push_back(f2);
4877
4894
Item_equal::Item_equal(Item *c, Item_field *f)
4878
: Item_bool_func(), eval_item(0), cond_false(0)
4895
: item::function::Boolean(), eval_item(0), cond_false(0)
4880
const_item_cache= 0;
4897
const_item_cache= false;
4881
4898
fields.push_back(f);
4886
4903
Item_equal::Item_equal(Item_equal *item_equal)
4887
: Item_bool_func(), eval_item(0), cond_false(0)
4904
: item::function::Boolean(), eval_item(0), cond_false(0)
4889
const_item_cache= 0;
4906
const_item_cache= false;
4890
4907
List_iterator_fast<Item_field> li(item_equal->fields);
4891
4908
Item_field *item;
4892
4909
while ((item= li++))