572
576
func= comparator_matrix[type]
573
[test(owner->functype() == Item_func::EQUAL_FUNC)];
577
[test(owner->functype() == Item_func::EQUAL_FUNC)];
577
uint32_t n= (*a)->cols();
578
if (n != (*b)->cols())
580
my_error(ER_OPERAND_COLUMNS, MYF(0), n);
584
if (!(comparators= new Arg_comparator[n]))
586
for (uint32_t i=0; i < n; i++)
588
if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
590
my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols());
593
comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
582
uint32_t n= (*a)->cols();
583
if (n != (*b)->cols())
585
my_error(ER_OPERAND_COLUMNS, MYF(0), n);
589
if (!(comparators= new Arg_comparator[n]))
591
for (uint32_t i=0; i < n; i++)
593
if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
595
my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols());
598
comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
597
603
case STRING_RESULT:
600
We must set cmp_charset here as we may be called from for an automatic
601
generated item, like in natural join
603
if (cmp_collation.set((*a)->collation, (*b)->collation) ||
604
cmp_collation.derivation == DERIVATION_NONE)
606
my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
609
if (cmp_collation.collation == &my_charset_bin)
612
We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
613
without removing end space
606
We must set cmp_charset here as we may be called from for an automatic
607
generated item, like in natural join
615
if (func == &Arg_comparator::compare_string)
616
func= &Arg_comparator::compare_binary_string;
617
else if (func == &Arg_comparator::compare_e_string)
618
func= &Arg_comparator::compare_e_binary_string;
609
if (cmp_collation.set((*a)->collation, (*b)->collation) ||
610
cmp_collation.derivation == DERIVATION_NONE)
612
my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
615
if (cmp_collation.collation == &my_charset_bin)
618
We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
619
without removing end space
621
if (func == &Arg_comparator::compare_string)
622
func= &Arg_comparator::compare_binary_string;
623
else if (func == &Arg_comparator::compare_e_string)
624
func= &Arg_comparator::compare_e_binary_string;
621
As this is binary compassion, mark all fields that they can't be
622
transformed. Otherwise we would get into trouble with comparisons
624
WHERE col= 'j' AND col LIKE BINARY 'j'
625
which would be transformed to:
627
As this is binary compassion, mark all fields that they can't be
628
transformed. Otherwise we would get into trouble with comparisons
630
WHERE col= 'j' AND col LIKE BINARY 'j'
631
which would be transformed to:
628
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
629
(*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
634
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
635
(*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
635
if (func == &Arg_comparator::compare_int_signed)
637
if ((*a)->unsigned_flag)
638
func= (((*b)->unsigned_flag)?
639
&Arg_comparator::compare_int_unsigned :
640
&Arg_comparator::compare_int_unsigned_signed);
641
else if ((*b)->unsigned_flag)
642
func= &Arg_comparator::compare_int_signed_unsigned;
644
else if (func== &Arg_comparator::compare_e_int)
646
if ((*a)->unsigned_flag ^ (*b)->unsigned_flag)
647
func= &Arg_comparator::compare_e_int_diff_signedness;
641
if (func == &Arg_comparator::compare_int_signed)
643
if ((*a)->unsigned_flag)
644
func= (((*b)->unsigned_flag)?
645
&Arg_comparator::compare_int_unsigned :
646
&Arg_comparator::compare_int_unsigned_signed);
647
else if ((*b)->unsigned_flag)
648
func= &Arg_comparator::compare_int_signed_unsigned;
650
else if (func== &Arg_comparator::compare_e_int)
652
if ((*a)->unsigned_flag ^ (*b)->unsigned_flag)
653
func= &Arg_comparator::compare_e_int_diff_signedness;
651
657
case DECIMAL_RESULT:
653
659
case REAL_RESULT:
655
if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
657
precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
658
if (func == &Arg_comparator::compare_real)
659
func= &Arg_comparator::compare_real_fixed;
660
else if (func == &Arg_comparator::compare_e_real)
661
func= &Arg_comparator::compare_e_real_fixed;
661
if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
663
precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
664
if (func == &Arg_comparator::compare_real)
665
func= &Arg_comparator::compare_real_fixed;
666
else if (func == &Arg_comparator::compare_e_real)
667
func= &Arg_comparator::compare_e_real_fixed;
2124
2129
else if (cmp_type == DECIMAL_RESULT)
2126
my_decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
2131
type::Decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
2127
2132
a_buf, *a_dec, b_buf, *b_dec;
2128
2133
if ((null_value=args[0]->null_value))
2130
2135
a_dec= args[1]->val_decimal(&a_buf);
2131
2136
b_dec= args[2]->val_decimal(&b_buf);
2132
2137
if (!args[1]->null_value && !args[2]->null_value)
2133
return (int64_t) ((my_decimal_cmp(dec, a_dec) >= 0 &&
2134
my_decimal_cmp(dec, b_dec) <= 0) != negated);
2138
return (int64_t) ((class_decimal_cmp(dec, a_dec) >= 0 &&
2139
class_decimal_cmp(dec, b_dec) <= 0) != negated);
2135
2140
if (args[1]->null_value && args[2]->null_value)
2137
2142
else if (args[1]->null_value)
2138
null_value= (my_decimal_cmp(dec, b_dec) <= 0);
2143
null_value= (class_decimal_cmp(dec, b_dec) <= 0);
2140
null_value= (my_decimal_cmp(dec, a_dec) >= 0);
2145
null_value= (class_decimal_cmp(dec, a_dec) >= 0);
3233
3244
in_decimal::in_decimal(uint32_t elements)
3234
:in_vector(elements, sizeof(my_decimal),(qsort2_cmp) cmp_decimal, 0)
3245
:in_vector(elements, sizeof(type::Decimal),(qsort2_cmp) cmp_decimal, 0)
3238
3249
void in_decimal::set(uint32_t pos, Item *item)
3240
/* as far as 'item' is constant, we can store reference on my_decimal */
3241
my_decimal *dec= ((my_decimal *)base) + pos;
3251
/* as far as 'item' is constant, we can store reference on type::Decimal */
3252
type::Decimal *dec= ((type::Decimal *)base) + pos;
3242
3253
dec->len= DECIMAL_BUFF_LENGTH;
3243
3254
dec->fix_buffer_pointer();
3244
my_decimal *res= item->val_decimal(dec);
3255
type::Decimal *res= item->val_decimal(dec);
3245
3256
/* if item->val_decimal() is evaluated to NULL then res == 0 */
3246
3257
if (!item->null_value && res != dec)
3247
my_decimal2decimal(res, dec);
3258
class_decimal2decimal(res, dec);
3251
3262
unsigned char *in_decimal::get_value(Item *item)
3253
my_decimal *result= item->val_decimal(&val);
3264
type::Decimal *result= item->val_decimal(&val);
3254
3265
if (item->null_value)
3256
3267
return (unsigned char *)result;
3408
3421
void cmp_item_decimal::store_value(Item *item)
3410
my_decimal *val= item->val_decimal(&value);
3423
type::Decimal *val= item->val_decimal(&value);
3411
3424
/* val may be zero if item is nnull */
3412
3425
if (val && val != &value)
3413
my_decimal2decimal(val, &value);
3426
class_decimal2decimal(val, &value);
3417
3430
int cmp_item_decimal::cmp(Item *arg)
3419
my_decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
3432
type::Decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
3420
3433
if (arg->null_value)
3422
return my_decimal_cmp(&value, tmp);
3435
return class_decimal_cmp(&value, tmp);
3426
3439
int cmp_item_decimal::compare(cmp_item *arg)
3428
3441
cmp_item_decimal *l_cmp= (cmp_item_decimal*) arg;
3429
return my_decimal_cmp(&value, &l_cmp->value);
3442
return class_decimal_cmp(&value, &l_cmp->value);
4870
4888
Item_equal::Item_equal(Item_field *f1, Item_field *f2)
4871
: Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
4889
: item::function::Boolean(), const_item(0), eval_item(0), cond_false(0)
4873
const_item_cache= 0;
4891
const_item_cache= false;
4874
4892
fields.push_back(f1);
4875
4893
fields.push_back(f2);
4878
4896
Item_equal::Item_equal(Item *c, Item_field *f)
4879
: Item_bool_func(), eval_item(0), cond_false(0)
4897
: item::function::Boolean(), eval_item(0), cond_false(0)
4881
const_item_cache= 0;
4899
const_item_cache= false;
4882
4900
fields.push_back(f);
4887
4905
Item_equal::Item_equal(Item_equal *item_equal)
4888
: Item_bool_func(), eval_item(0), cond_false(0)
4906
: item::function::Boolean(), eval_item(0), cond_false(0)
4890
const_item_cache= 0;
4908
const_item_cache= false;
4891
4909
List_iterator_fast<Item_field> li(item_equal->fields);
4892
4910
Item_field *item;
4893
4911
while ((item= li++))