572
566
func= comparator_matrix[type]
573
[test(owner->functype() == Item_func::EQUAL_FUNC)];
567
[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));
571
uint32_t n= (*a)->cols();
572
if (n != (*b)->cols())
574
my_error(ER_OPERAND_COLUMNS, MYF(0), n);
578
if (!(comparators= new Arg_comparator[n]))
580
for (uint32_t i=0; i < n; i++)
582
if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
584
my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols());
587
comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
599
591
case STRING_RESULT:
594
We must set cmp_charset here as we may be called from for an automatic
595
generated item, like in natural join
597
if (cmp_collation.set((*a)->collation, (*b)->collation) ||
598
cmp_collation.derivation == DERIVATION_NONE)
600
my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
603
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
606
We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
607
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;
609
if (func == &Arg_comparator::compare_string)
610
func= &Arg_comparator::compare_binary_string;
611
else if (func == &Arg_comparator::compare_e_string)
612
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:
615
As this is binary compassion, mark all fields that they can't be
616
transformed. Otherwise we would get into trouble with comparisons
618
WHERE col= 'j' AND col LIKE BINARY 'j'
619
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);
622
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
623
(*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;
629
if (func == &Arg_comparator::compare_int_signed)
631
if ((*a)->unsigned_flag)
632
func= (((*b)->unsigned_flag)?
633
&Arg_comparator::compare_int_unsigned :
634
&Arg_comparator::compare_int_unsigned_signed);
635
else if ((*b)->unsigned_flag)
636
func= &Arg_comparator::compare_int_signed_unsigned;
638
else if (func== &Arg_comparator::compare_e_int)
640
if ((*a)->unsigned_flag ^ (*b)->unsigned_flag)
641
func= &Arg_comparator::compare_e_int_diff_signedness;
653
645
case DECIMAL_RESULT:
655
647
case REAL_RESULT:
649
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;
651
precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
652
if (func == &Arg_comparator::compare_real)
653
func= &Arg_comparator::compare_real_fixed;
654
else if (func == &Arg_comparator::compare_e_real)
655
func= &Arg_comparator::compare_e_real_fixed;
767
758
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)
759
Arg_comparator::can_compare_as_dates(Item *a, Item *b, uint64_t *const_value)
771
761
enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
772
762
Item *str_arg= 0, *date_arg= 0;
774
if (in_a->type() == Item::ROW_ITEM || in_b->type() == Item::ROW_ITEM)
764
if (a->type() == Item::ROW_ITEM || b->type() == Item::ROW_ITEM)
775
765
return CMP_DATE_DFLT;
777
if (in_a->is_datetime())
767
if (a->is_datetime())
779
if (in_b->is_datetime())
769
if (b->is_datetime())
780
770
cmp_type= CMP_DATE_WITH_DATE;
781
else if (in_b->result_type() == STRING_RESULT)
771
else if (b->result_type() == STRING_RESULT)
783
773
cmp_type= CMP_DATE_WITH_STR;
788
else if (in_b->is_datetime() && in_a->result_type() == STRING_RESULT)
778
else if (b->is_datetime() && a->result_type() == STRING_RESULT)
790
780
cmp_type= CMP_STR_WITH_DATE;
795
785
if (cmp_type != CMP_DATE_DFLT)