572
557
func= comparator_matrix[type]
573
[test(owner->functype() == Item_func::EQUAL_FUNC)];
558
[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));
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));
599
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)
602
We must set cmp_charset here as we may be called from for an automatic
603
generated item, like in natural join
597
We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
598
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;
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;
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:
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:
630
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
631
(*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);
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;
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;
653
636
case DECIMAL_RESULT:
655
638
case REAL_RESULT:
640
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;
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;
767
749
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)
750
Arg_comparator::can_compare_as_dates(Item *a, Item *b, uint64_t *const_value)
771
752
enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
772
753
Item *str_arg= 0, *date_arg= 0;
774
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)
775
756
return CMP_DATE_DFLT;
777
if (in_a->is_datetime())
758
if (a->is_datetime())
779
if (in_b->is_datetime())
760
if (b->is_datetime())
780
761
cmp_type= CMP_DATE_WITH_DATE;
781
else if (in_b->result_type() == STRING_RESULT)
762
else if (b->result_type() == STRING_RESULT)
783
764
cmp_type= CMP_DATE_WITH_STR;
788
else if (in_b->is_datetime() && in_a->result_type() == STRING_RESULT)
769
else if (b->is_datetime() && a->result_type() == STRING_RESULT)
790
771
cmp_type= CMP_STR_WITH_DATE;
795
776
if (cmp_type != CMP_DATE_DFLT)