572
552
func= comparator_matrix[type]
573
[test(owner->functype() == Item_func::EQUAL_FUNC)];
553
[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));
557
uint32_t n= (*a)->cols();
558
if (n != (*b)->cols())
560
my_error(ER_OPERAND_COLUMNS, MYF(0), n);
564
if (!(comparators= new Arg_comparator[n]))
566
for (uint32_t i=0; i < n; i++)
568
if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
570
my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols());
573
comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
599
577
case STRING_RESULT:
580
We must set cmp_charset here as we may be called from for an automatic
581
generated item, like in natural join
583
if (cmp_collation.set((*a)->collation, (*b)->collation) ||
584
cmp_collation.derivation == DERIVATION_NONE)
586
my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
589
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
592
We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
593
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;
595
if (func == &Arg_comparator::compare_string)
596
func= &Arg_comparator::compare_binary_string;
597
else if (func == &Arg_comparator::compare_e_string)
598
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:
601
As this is binary compassion, mark all fields that they can't be
602
transformed. Otherwise we would get into trouble with comparisons
604
WHERE col= 'j' AND col LIKE BINARY 'j'
605
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);
608
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
609
(*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;
615
if (func == &Arg_comparator::compare_int_signed)
617
if ((*a)->unsigned_flag)
618
func= (((*b)->unsigned_flag)?
619
&Arg_comparator::compare_int_unsigned :
620
&Arg_comparator::compare_int_unsigned_signed);
621
else if ((*b)->unsigned_flag)
622
func= &Arg_comparator::compare_int_signed_unsigned;
624
else if (func== &Arg_comparator::compare_e_int)
626
if ((*a)->unsigned_flag ^ (*b)->unsigned_flag)
627
func= &Arg_comparator::compare_e_int_diff_signedness;
653
631
case DECIMAL_RESULT:
655
633
case REAL_RESULT:
635
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;
637
precision= 5 / log_10[cmax((*a)->decimals, (*b)->decimals) + 1];
638
if (func == &Arg_comparator::compare_real)
639
func= &Arg_comparator::compare_real_fixed;
640
else if (func == &Arg_comparator::compare_e_real)
641
func= &Arg_comparator::compare_e_real_fixed;
767
744
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)
745
Arg_comparator::can_compare_as_dates(Item *a, Item *b, uint64_t *const_value)
771
747
enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
772
748
Item *str_arg= 0, *date_arg= 0;
774
if (in_a->type() == Item::ROW_ITEM || in_b->type() == Item::ROW_ITEM)
750
if (a->type() == Item::ROW_ITEM || b->type() == Item::ROW_ITEM)
775
751
return CMP_DATE_DFLT;
777
if (in_a->is_datetime())
753
if (a->is_datetime())
779
if (in_b->is_datetime())
755
if (b->is_datetime())
780
756
cmp_type= CMP_DATE_WITH_DATE;
781
else if (in_b->result_type() == STRING_RESULT)
757
else if (b->result_type() == STRING_RESULT)
783
759
cmp_type= CMP_DATE_WITH_STR;
788
else if (in_b->is_datetime() && in_a->result_type() == STRING_RESULT)
764
else if (b->is_datetime() && a->result_type() == STRING_RESULT)
790
766
cmp_type= CMP_STR_WITH_DATE;
795
771
if (cmp_type != CMP_DATE_DFLT)
837
Retrieves correct TIME value from the given item.
841
session thread handle
842
item_arg [in/out] item to retrieve TIME value from
843
cache_arg [in/out] pointer to place to store the cache item to
844
warn_item [in] unused
845
is_null [out] true <=> the item_arg is null
848
Retrieves the correct TIME value from given item for comparison by the
849
compare_datetime() function.
850
If item's result can be compared as int64_t then its int value is used
851
and a value returned by get_time function is used otherwise.
852
If an item is a constant one then its value is cached and it isn't
853
get parsed again. An Item_cache_int object is used for for cached values.
854
It seamlessly substitutes the original item. The cache item is marked as
855
non-constant to prevent re-caching it again.
862
get_time_value(Session *,
863
Item ***item_arg, Item **cache_arg,
864
Item *, bool *is_null)
867
Item *item= **item_arg;
870
if (item->result_as_int64_t())
872
value= item->val_int();
873
*is_null= item->null_value;
877
*is_null= item->get_time(<ime);
878
value= !*is_null ? TIME_to_uint64_t_datetime(<ime) : 0;
881
Do not cache GET_USER_VAR() function as its const_item() may return true
882
for the current thread but it still may change during the execution.
884
if (item->const_item() && cache_arg && (item->type() != Item::FUNC_ITEM ||
885
((Item_func*)item)->functype() != Item_func::GUSERVAR_FUNC))
887
Item_cache_int *cache= new Item_cache_int();
888
/* Mark the cache as non-const to prevent re-caching. */
889
cache->set_used_tables(1);
890
cache->store(item, value);
892
*item_arg= cache_arg;
860
898
int Arg_comparator::set_cmp_func(Item_bool_func2 *owner_arg,
861
899
Item **a1, Item **a2,
862
900
Item_result type)
2193
2232
int len1= args[1]->max_length - args[1]->decimals
2194
2233
- (args[1]->unsigned_flag ? 0 : 1);
2196
max_length= max(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
2235
max_length= cmax(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
2200
max_length= max(args[0]->max_length, args[1]->max_length);
2238
max_length= cmax(args[0]->max_length, args[1]->max_length);
2203
switch (hybrid_type)
2240
switch (hybrid_type) {
2205
2241
case STRING_RESULT:
2206
2242
agg_arg_charsets(collation, args, arg_count, MY_COLL_CMP_CONV, 1);
2209
2244
case DECIMAL_RESULT:
2210
2245
case REAL_RESULT:
2213
2247
case INT_RESULT:
2217
2250
case ROW_RESULT:
2221
2254
cached_field_type= agg_field_type(args, 2);
2225
2258
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);
2260
int max_int_part=cmax(args[0]->decimal_int_part(),args[1]->decimal_int_part());
2261
return cmin(max_int_part + decimals, DECIMAL_MAX_PRECISION);
3869
int64_t Item_func_bit_or::val_int()
3872
uint64_t arg1= (uint64_t) args[0]->val_int();
3873
if (args[0]->null_value)
3875
null_value=1; /* purecov: inspected */
3876
return 0; /* purecov: inspected */
3878
uint64_t arg2= (uint64_t) args[1]->val_int();
3879
if (args[1]->null_value)
3885
return (int64_t) (arg1 | arg2);
3889
int64_t Item_func_bit_and::val_int()
3892
uint64_t arg1= (uint64_t) args[0]->val_int();
3893
if (args[0]->null_value)
3895
null_value=1; /* purecov: inspected */
3896
return 0; /* purecov: inspected */
3898
uint64_t arg2= (uint64_t) args[1]->val_int();
3899
if (args[1]->null_value)
3901
null_value=1; /* purecov: inspected */
3902
return 0; /* purecov: inspected */
3905
return (int64_t) (arg1 & arg2);
3851
3908
Item_cond::Item_cond(Session *session, Item_cond *item)
3852
3909
:Item_bool_func(session, item),
3853
3910
abort_on_null(item->abort_on_null),
4415
4471
if (escape_item->const_item())
4418
4473
/* If we are on execution stage */
4419
4474
String *escape_str= escape_item->val_str(&tmp_value1);
4420
4475
if (escape_str)
4422
escape= (char *)memory::sql_alloc(escape_str->length());
4423
strcpy(escape, escape_str->ptr());
4477
if (escape_used_in_parsing && escape_str->numchars() > 1)
4479
my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE");
4483
if (use_mb(cmp.cmp_collation.collation))
4485
const CHARSET_INFO * const cs= escape_str->charset();
4487
int rc= cs->cset->mb_wc(cs, &wc,
4488
(const unsigned char*) escape_str->ptr(),
4489
(const unsigned char*) escape_str->ptr() +
4490
escape_str->length());
4491
escape= (int) (rc > 0 ? wc : '\\');
4496
In the case of 8bit character set, we pass native
4497
code instead of Unicode code as "escape" argument.
4498
Convert to "cs" if charset of escape differs.
4500
const CHARSET_INFO * const cs= cmp.cmp_collation.collation;
4502
if (escape_str->needs_conversion(escape_str->length(),
4503
escape_str->charset(), cs, &unused))
4507
uint32_t cnvlen= copy_and_convert(&ch, 1, cs, escape_str->ptr(),
4508
escape_str->length(),
4509
escape_str->charset(), &errors);
4510
escape= cnvlen ? ch : '\\';
4513
escape= *(escape_str->ptr());
4427
escape= (char *)memory::sql_alloc(1);
4428
strcpy(escape, "\\");
4432
4520
We could also do boyer-more for non-const items, but as we would have to
4433
4521
recompute the tables for each row it's not worth it.
4673
4758
register int i = plm1;
4674
4759
while (i >= 0 && likeconv(cs,pattern[i]) == likeconv(cs,text[i + j]))
4677
if (i == plm1 - shift)
4762
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]);
4768
register const int v = plm1 - i;
4770
bcShift = bmBc[(uint32_t) likeconv(cs, text[i + j])] - plm1 + i;
4771
shift = (turboShift > bcShift) ? turboShift : bcShift;
4772
shift = cmax(shift, bmGs[i]);
4690
4773
if (shift == bmGs[i])
4691
u= (pattern_len - shift < v) ? pattern_len - shift : v;
4774
u = (pattern_len - shift < v) ? pattern_len - shift : v;
4694
if (turboShift < bcShift)
4695
shift= max(shift, u + 1);
4777
if (turboShift < bcShift)
4778
shift = cmax(shift, u + 1);