572
551
func= comparator_matrix[type]
573
[test(owner->functype() == Item_func::EQUAL_FUNC)];
552
[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));
556
uint32_t n= (*a)->cols();
557
if (n != (*b)->cols())
559
my_error(ER_OPERAND_COLUMNS, MYF(0), n);
563
if (!(comparators= new Arg_comparator[n]))
565
for (uint32_t i=0; i < n; i++)
567
if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
569
my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols());
572
comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
599
576
case STRING_RESULT:
579
We must set cmp_charset here as we may be called from for an automatic
580
generated item, like in natural join
582
if (cmp_collation.set((*a)->collation, (*b)->collation) ||
583
cmp_collation.derivation == DERIVATION_NONE)
585
my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
588
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
591
We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
592
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;
594
if (func == &Arg_comparator::compare_string)
595
func= &Arg_comparator::compare_binary_string;
596
else if (func == &Arg_comparator::compare_e_string)
597
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:
600
As this is binary compassion, mark all fields that they can't be
601
transformed. Otherwise we would get into trouble with comparisons
603
WHERE col= 'j' AND col LIKE BINARY 'j'
604
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);
607
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
608
(*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;
614
if (func == &Arg_comparator::compare_int_signed)
616
if ((*a)->unsigned_flag)
617
func= (((*b)->unsigned_flag)?
618
&Arg_comparator::compare_int_unsigned :
619
&Arg_comparator::compare_int_unsigned_signed);
620
else if ((*b)->unsigned_flag)
621
func= &Arg_comparator::compare_int_signed_unsigned;
623
else if (func== &Arg_comparator::compare_e_int)
625
if ((*a)->unsigned_flag ^ (*b)->unsigned_flag)
626
func= &Arg_comparator::compare_e_int_diff_signedness;
653
630
case DECIMAL_RESULT:
655
632
case REAL_RESULT:
634
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;
636
precision= 5 / log_10[cmax((*a)->decimals, (*b)->decimals) + 1];
637
if (func == &Arg_comparator::compare_real)
638
func= &Arg_comparator::compare_real_fixed;
639
else if (func == &Arg_comparator::compare_e_real)
640
func= &Arg_comparator::compare_e_real_fixed;
767
743
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)
744
Arg_comparator::can_compare_as_dates(Item *a, Item *b, uint64_t *const_value)
771
746
enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
772
747
Item *str_arg= 0, *date_arg= 0;
774
if (in_a->type() == Item::ROW_ITEM || in_b->type() == Item::ROW_ITEM)
749
if (a->type() == Item::ROW_ITEM || b->type() == Item::ROW_ITEM)
775
750
return CMP_DATE_DFLT;
777
if (in_a->is_datetime())
752
if (a->is_datetime())
779
if (in_b->is_datetime())
754
if (b->is_datetime())
780
755
cmp_type= CMP_DATE_WITH_DATE;
781
else if (in_b->result_type() == STRING_RESULT)
756
else if (b->result_type() == STRING_RESULT)
783
758
cmp_type= CMP_DATE_WITH_STR;
788
else if (in_b->is_datetime() && in_a->result_type() == STRING_RESULT)
763
else if (b->is_datetime() && a->result_type() == STRING_RESULT)
790
765
cmp_type= CMP_STR_WITH_DATE;
795
770
if (cmp_type != CMP_DATE_DFLT)
836
Retrieves correct TIME value from the given item.
840
session thread handle
841
item_arg [in/out] item to retrieve TIME value from
842
cache_arg [in/out] pointer to place to store the cache item to
843
warn_item [in] unused
844
is_null [out] true <=> the item_arg is null
847
Retrieves the correct TIME value from given item for comparison by the
848
compare_datetime() function.
849
If item's result can be compared as int64_t then its int value is used
850
and a value returned by get_time function is used otherwise.
851
If an item is a constant one then its value is cached and it isn't
852
get parsed again. An Item_cache_int object is used for for cached values.
853
It seamlessly substitutes the original item. The cache item is marked as
854
non-constant to prevent re-caching it again.
861
get_time_value(Session *,
862
Item ***item_arg, Item **cache_arg,
863
Item *, bool *is_null)
866
Item *item= **item_arg;
869
if (item->result_as_int64_t())
871
value= item->val_int();
872
*is_null= item->null_value;
876
*is_null= item->get_time(<ime);
877
value= !*is_null ? TIME_to_uint64_t_datetime(<ime) : 0;
880
Do not cache GET_USER_VAR() function as its const_item() may return true
881
for the current thread but it still may change during the execution.
883
if (item->const_item() && cache_arg && (item->type() != Item::FUNC_ITEM ||
884
((Item_func*)item)->functype() != Item_func::GUSERVAR_FUNC))
886
Item_cache_int *cache= new Item_cache_int();
887
/* Mark the cache as non-const to prevent re-caching. */
888
cache->set_used_tables(1);
889
cache->store(item, value);
891
*item_arg= cache_arg;
860
897
int Arg_comparator::set_cmp_func(Item_bool_func2 *owner_arg,
861
898
Item **a1, Item **a2,
862
899
Item_result type)
2193
2231
int len1= args[1]->max_length - args[1]->decimals
2194
2232
- (args[1]->unsigned_flag ? 0 : 1);
2196
max_length= max(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
2234
max_length= cmax(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
2200
max_length= max(args[0]->max_length, args[1]->max_length);
2237
max_length= cmax(args[0]->max_length, args[1]->max_length);
2203
switch (hybrid_type)
2239
switch (hybrid_type) {
2205
2240
case STRING_RESULT:
2206
2241
agg_arg_charsets(collation, args, arg_count, MY_COLL_CMP_CONV, 1);
2209
2243
case DECIMAL_RESULT:
2210
2244
case REAL_RESULT:
2213
2246
case INT_RESULT:
2217
2249
case ROW_RESULT:
2221
2253
cached_field_type= agg_field_type(args, 2);
2225
2257
uint32_t Item_func_ifnull::decimal_precision() const
2227
int max_int_part= max(args[0]->decimal_int_part(),args[1]->decimal_int_part());
2228
return min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2259
int max_int_part=cmax(args[0]->decimal_int_part(),args[1]->decimal_int_part());
2260
return cmin(max_int_part + decimals, DECIMAL_MAX_PRECISION);
4673
4692
register int i = plm1;
4674
4693
while (i >= 0 && likeconv(cs,pattern[i]) == likeconv(cs,text[i + j]))
4677
if (i == plm1 - shift)
4696
if (i == plm1 - shift)
4684
register const int v= plm1 - i;
4686
bcShift= bmBc[(uint32_t) likeconv(cs, text[i + j])] - plm1 + i;
4687
shift= (turboShift > bcShift) ? turboShift : bcShift;
4688
shift= max(shift, bmGs[i]);
4702
register const int v = plm1 - i;
4704
bcShift = bmBc[(uint32_t) likeconv(cs, text[i + j])] - plm1 + i;
4705
shift = (turboShift > bcShift) ? turboShift : bcShift;
4706
shift = cmax(shift, bmGs[i]);
4690
4707
if (shift == bmGs[i])
4691
u= (pattern_len - shift < v) ? pattern_len - shift : v;
4708
u = (pattern_len - shift < v) ? pattern_len - shift : v;
4694
if (turboShift < bcShift)
4695
shift= max(shift, u + 1);
4711
if (turboShift < bcShift)
4712
shift = cmax(shift, u + 1);