572
567
func= comparator_matrix[type]
573
[test(owner->functype() == Item_func::EQUAL_FUNC)];
568
[test(owner->functype() == Item_func::EQUAL_FUNC)];
578
uint32_t n= (*a)->cols();
579
if (n != (*b)->cols())
581
my_error(ER_OPERAND_COLUMNS, MYF(0), n);
585
if (!(comparators= new Arg_comparator[n]))
587
for (uint32_t i=0; i < n; i++)
589
if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
591
my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols());
594
comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
572
uint32_t n= (*a)->cols();
573
if (n != (*b)->cols())
575
my_error(ER_OPERAND_COLUMNS, MYF(0), n);
579
if (!(comparators= new Arg_comparator[n]))
581
for (uint32_t i=0; i < n; i++)
583
if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
585
my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols());
588
comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
599
592
case STRING_RESULT:
595
We must set cmp_charset here as we may be called from for an automatic
596
generated item, like in natural join
598
if (cmp_collation.set((*a)->collation, (*b)->collation) ||
599
cmp_collation.derivation == DERIVATION_NONE)
601
my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
604
if (cmp_collation.collation == &my_charset_bin)
602
We must set cmp_charset here as we may be called from for an automatic
603
generated item, like in natural join
607
We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
608
without removing end space
605
if (cmp_collation.set((*a)->collation, (*b)->collation) ||
606
cmp_collation.derivation == DERIVATION_NONE)
608
my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
611
if (cmp_collation.collation == &my_charset_bin)
614
We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
615
without removing end space
617
if (func == &Arg_comparator::compare_string)
618
func= &Arg_comparator::compare_binary_string;
619
else if (func == &Arg_comparator::compare_e_string)
620
func= &Arg_comparator::compare_e_binary_string;
610
if (func == &Arg_comparator::compare_string)
611
func= &Arg_comparator::compare_binary_string;
612
else if (func == &Arg_comparator::compare_e_string)
613
func= &Arg_comparator::compare_e_binary_string;
623
As this is binary compassion, mark all fields that they can't be
624
transformed. Otherwise we would get into trouble with comparisons
626
WHERE col= 'j' AND col LIKE BINARY 'j'
627
which would be transformed to:
616
As this is binary compassion, mark all fields that they can't be
617
transformed. Otherwise we would get into trouble with comparisons
619
WHERE col= 'j' AND col LIKE BINARY 'j'
620
which would be transformed to:
630
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
631
(*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
623
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
624
(*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
637
if (func == &Arg_comparator::compare_int_signed)
639
if ((*a)->unsigned_flag)
640
func= (((*b)->unsigned_flag)?
641
&Arg_comparator::compare_int_unsigned :
642
&Arg_comparator::compare_int_unsigned_signed);
643
else if ((*b)->unsigned_flag)
644
func= &Arg_comparator::compare_int_signed_unsigned;
646
else if (func== &Arg_comparator::compare_e_int)
648
if ((*a)->unsigned_flag ^ (*b)->unsigned_flag)
649
func= &Arg_comparator::compare_e_int_diff_signedness;
630
if (func == &Arg_comparator::compare_int_signed)
632
if ((*a)->unsigned_flag)
633
func= (((*b)->unsigned_flag)?
634
&Arg_comparator::compare_int_unsigned :
635
&Arg_comparator::compare_int_unsigned_signed);
636
else if ((*b)->unsigned_flag)
637
func= &Arg_comparator::compare_int_signed_unsigned;
639
else if (func== &Arg_comparator::compare_e_int)
641
if ((*a)->unsigned_flag ^ (*b)->unsigned_flag)
642
func= &Arg_comparator::compare_e_int_diff_signedness;
653
646
case DECIMAL_RESULT:
655
648
case REAL_RESULT:
650
if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
657
if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
659
precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
660
if (func == &Arg_comparator::compare_real)
661
func= &Arg_comparator::compare_real_fixed;
662
else if (func == &Arg_comparator::compare_e_real)
663
func= &Arg_comparator::compare_e_real_fixed;
652
precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
653
if (func == &Arg_comparator::compare_real)
654
func= &Arg_comparator::compare_real_fixed;
655
else if (func == &Arg_comparator::compare_e_real)
656
func= &Arg_comparator::compare_e_real_fixed;
767
759
enum Arg_comparator::enum_date_cmp_type
768
Arg_comparator::can_compare_as_dates(Item *in_a, Item *in_b,
769
uint64_t *const_value)
760
Arg_comparator::can_compare_as_dates(Item *a, Item *b, uint64_t *const_value)
771
762
enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
772
763
Item *str_arg= 0, *date_arg= 0;
774
if (in_a->type() == Item::ROW_ITEM || in_b->type() == Item::ROW_ITEM)
765
if (a->type() == Item::ROW_ITEM || b->type() == Item::ROW_ITEM)
775
766
return CMP_DATE_DFLT;
777
if (in_a->is_datetime())
768
if (a->is_datetime())
779
if (in_b->is_datetime())
770
if (b->is_datetime())
780
771
cmp_type= CMP_DATE_WITH_DATE;
781
else if (in_b->result_type() == STRING_RESULT)
772
else if (b->result_type() == STRING_RESULT)
783
774
cmp_type= CMP_DATE_WITH_STR;
788
else if (in_b->is_datetime() && in_a->result_type() == STRING_RESULT)
779
else if (b->is_datetime() && a->result_type() == STRING_RESULT)
790
781
cmp_type= CMP_STR_WITH_DATE;
795
786
if (cmp_type != CMP_DATE_DFLT)