574
557
func= comparator_matrix[type]
575
[test(owner->functype() == Item_func::EQUAL_FUNC)];
558
[test(owner->functype() == Item_func::EQUAL_FUNC)];
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));
562
uint32_t n= (*a)->cols();
563
if (n != (*b)->cols())
565
my_error(ER_OPERAND_COLUMNS, MYF(0), n);
569
if (!(comparators= new Arg_comparator[n]))
571
for (uint32_t i=0; i < n; i++)
573
if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
575
my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols());
578
comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
601
582
case STRING_RESULT:
585
We must set cmp_charset here as we may be called from for an automatic
586
generated item, like in natural join
588
if (cmp_collation.set((*a)->collation, (*b)->collation) ||
589
cmp_collation.derivation == DERIVATION_NONE)
591
my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
594
if (cmp_collation.collation == &my_charset_bin)
604
We must set cmp_charset here as we may be called from for an automatic
605
generated item, like in natural join
597
We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
598
without removing end space
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;
600
if (func == &Arg_comparator::compare_string)
601
func= &Arg_comparator::compare_binary_string;
602
else if (func == &Arg_comparator::compare_e_string)
603
func= &Arg_comparator::compare_e_binary_string;
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:
606
As this is binary compassion, mark all fields that they can't be
607
transformed. Otherwise we would get into trouble with comparisons
609
WHERE col= 'j' AND col LIKE BINARY 'j'
610
which would be transformed to:
632
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
633
(*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
613
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
614
(*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
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;
620
if (func == &Arg_comparator::compare_int_signed)
622
if ((*a)->unsigned_flag)
623
func= (((*b)->unsigned_flag)?
624
&Arg_comparator::compare_int_unsigned :
625
&Arg_comparator::compare_int_unsigned_signed);
626
else if ((*b)->unsigned_flag)
627
func= &Arg_comparator::compare_int_signed_unsigned;
629
else if (func== &Arg_comparator::compare_e_int)
631
if ((*a)->unsigned_flag ^ (*b)->unsigned_flag)
632
func= &Arg_comparator::compare_e_int_diff_signedness;
655
636
case DECIMAL_RESULT:
657
638
case REAL_RESULT:
640
if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
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;
642
precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
643
if (func == &Arg_comparator::compare_real)
644
func= &Arg_comparator::compare_real_fixed;
645
else if (func == &Arg_comparator::compare_e_real)
646
func= &Arg_comparator::compare_e_real_fixed;
694
676
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,
680
get_date_from_str(Session *session, String *str, enum enum_drizzle_timestamp_type warn_type,
699
681
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)
686
enum enum_drizzle_timestamp_type ret;
688
ret= str_to_datetime(str->ptr(), str->length(), &l_time,
689
(TIME_FUZZY_DATE | MODE_INVALID_DATES |
690
(session->variables.sql_mode & MODE_NO_ZERO_DATE)),
693
if (ret == DRIZZLE_TIMESTAMP_DATETIME || ret == DRIZZLE_TIMESTAMP_DATE)
713
696
Do not return yet, we may still want to throw a "trailing garbage"
716
699
*error_arg= false;
717
l_time.convert(value);
700
value= TIME_to_uint64_t_datetime(&l_time);
721
704
*error_arg= true;
722
error= type::CUT; /* force warning */
705
error= 1; /* force warning */
725
if (error != type::VALID)
727
709
make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
728
710
str->ptr(), str->length(),
729
711
warn_type, warn_name);
768
749
enum Arg_comparator::enum_date_cmp_type
769
Arg_comparator::can_compare_as_dates(Item *in_a, Item *in_b,
770
int64_t *const_value)
750
Arg_comparator::can_compare_as_dates(Item *a, Item *b, uint64_t *const_value)
772
752
enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
773
753
Item *str_arg= 0, *date_arg= 0;
775
if (in_a->type() == Item::ROW_ITEM || in_b->type() == Item::ROW_ITEM)
755
if (a->type() == Item::ROW_ITEM || b->type() == Item::ROW_ITEM)
776
756
return CMP_DATE_DFLT;
778
if (in_a->is_datetime())
758
if (a->is_datetime())
780
if (in_b->is_datetime())
760
if (b->is_datetime())
782
761
cmp_type= CMP_DATE_WITH_DATE;
784
else if (in_b->result_type() == STRING_RESULT)
762
else if (b->result_type() == STRING_RESULT)
786
764
cmp_type= CMP_DATE_WITH_STR;
791
else if (in_b->is_datetime() && in_a->result_type() == STRING_RESULT)
769
else if (b->is_datetime() && a->result_type() == STRING_RESULT)
793
771
cmp_type= CMP_STR_WITH_DATE;
798
776
if (cmp_type != CMP_DATE_DFLT)
2126
2107
else if (cmp_type == DECIMAL_RESULT)
2128
type::Decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
2109
my_decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
2129
2110
a_buf, *a_dec, b_buf, *b_dec;
2130
2111
if ((null_value=args[0]->null_value))
2112
return 0; /* purecov: inspected */
2132
2113
a_dec= args[1]->val_decimal(&a_buf);
2133
2114
b_dec= args[2]->val_decimal(&b_buf);
2134
2115
if (!args[1]->null_value && !args[2]->null_value)
2135
return (int64_t) ((class_decimal_cmp(dec, a_dec) >= 0 &&
2136
class_decimal_cmp(dec, b_dec) <= 0) != negated);
2116
return (int64_t) ((my_decimal_cmp(dec, a_dec) >= 0 &&
2117
my_decimal_cmp(dec, b_dec) <= 0) != negated);
2137
2118
if (args[1]->null_value && args[2]->null_value)
2139
2120
else if (args[1]->null_value)
2140
null_value= (class_decimal_cmp(dec, b_dec) <= 0);
2121
null_value= (my_decimal_cmp(dec, b_dec) <= 0);
2142
null_value= (class_decimal_cmp(dec, a_dec) >= 0);
2123
null_value= (my_decimal_cmp(dec, a_dec) >= 0);
2146
2127
double value= args[0]->val_real(),a,b;
2147
2128
if ((null_value=args[0]->null_value))
2129
return 0; /* purecov: inspected */
2149
2130
a= args[1]->val_real();
2150
2131
b= args[2]->val_real();
2151
2132
if (!args[1]->null_value && !args[2]->null_value)
3234
3203
tmp= item->val_real();
3235
3204
if (item->null_value)
3205
return 0; /* purecov: inspected */
3237
3206
return (unsigned char*) &tmp;
3241
3210
in_decimal::in_decimal(uint32_t elements)
3242
:in_vector(elements, sizeof(type::Decimal),(qsort2_cmp) cmp_decimal, 0)
3211
:in_vector(elements, sizeof(my_decimal),(qsort2_cmp) cmp_decimal, 0)
3246
3215
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;
3217
/* as far as 'item' is constant, we can store reference on my_decimal */
3218
my_decimal *dec= ((my_decimal *)base) + pos;
3250
3219
dec->len= DECIMAL_BUFF_LENGTH;
3251
3220
dec->fix_buffer_pointer();
3252
type::Decimal *res= item->val_decimal(dec);
3221
my_decimal *res= item->val_decimal(dec);
3253
3222
/* if item->val_decimal() is evaluated to NULL then res == 0 */
3254
3223
if (!item->null_value && res != dec)
3255
class_decimal2decimal(res, dec);
3224
my_decimal2decimal(res, dec);
3259
3228
unsigned char *in_decimal::get_value(Item *item)
3261
type::Decimal *result= item->val_decimal(&val);
3230
my_decimal *result= item->val_decimal(&val);
3262
3231
if (item->null_value)
3264
3233
return (unsigned char *)result;
3418
3385
void cmp_item_decimal::store_value(Item *item)
3420
type::Decimal *val= item->val_decimal(&value);
3387
my_decimal *val= item->val_decimal(&value);
3421
3388
/* val may be zero if item is nnull */
3422
3389
if (val && val != &value)
3423
class_decimal2decimal(val, &value);
3390
my_decimal2decimal(val, &value);
3427
3394
int cmp_item_decimal::cmp(Item *arg)
3429
type::Decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
3396
my_decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
3430
3397
if (arg->null_value)
3432
return class_decimal_cmp(&value, tmp);
3399
return my_decimal_cmp(&value, tmp);
3436
3403
int cmp_item_decimal::compare(cmp_item *arg)
3438
3405
cmp_item_decimal *l_cmp= (cmp_item_decimal*) arg;
3439
return class_decimal_cmp(&value, &l_cmp->value);
3406
return my_decimal_cmp(&value, &l_cmp->value);
4886
4846
Item_equal::Item_equal(Item_field *f1, Item_field *f2)
4887
: item::function::Boolean(), const_item(0), eval_item(0), cond_false(0)
4847
: Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
4889
const_item_cache= false;
4849
const_item_cache= 0;
4890
4850
fields.push_back(f1);
4891
4851
fields.push_back(f2);
4894
4854
Item_equal::Item_equal(Item *c, Item_field *f)
4895
: item::function::Boolean(), eval_item(0), cond_false(0)
4855
: Item_bool_func(), eval_item(0), cond_false(0)
4897
const_item_cache= false;
4857
const_item_cache= 0;
4898
4858
fields.push_back(f);
4903
4863
Item_equal::Item_equal(Item_equal *item_equal)
4904
: item::function::Boolean(), eval_item(0), cond_false(0)
4864
: Item_bool_func(), eval_item(0), cond_false(0)
4906
const_item_cache= false;
4866
const_item_cache= 0;
4907
4867
List_iterator_fast<Item_field> li(item_equal->fields);
4908
4868
Item_field *item;
4909
4869
while ((item= li++))