21
21
This file defines all compare functions
24
#ifdef USE_PRAGMA_IMPLEMENTATION
25
#pragma implementation // gcc: Class implementation
28
#include "mysql_priv.h"
30
#include "sql_select.h"
24
#include <drizzled/server_includes.h>
25
#include <drizzled/sql_select.h>
32
27
static bool convert_constant_item(THD *, Item_field *, Item **);
34
29
static Item_result item_store_type(Item_result a, Item *item,
35
my_bool unsigned_flag)
37
32
Item_result b= item->result_type();
50
static void agg_result_type(Item_result *type, Item **items, uint nitems)
45
static void agg_result_type(Item_result *type, Item **items, uint32_t nitems)
52
47
Item **item, **item_end;
53
my_bool unsigned_flag= 0;
48
bool unsigned_flag= 0;
55
50
*type= STRING_RESULT;
56
51
/* Skip beginning NULL items */
96
91
static int cmp_row_type(Item* item1, Item* item2)
98
uint n= item1->cols();
93
uint32_t n= item1->cols();
99
94
if (item2->check_cols(n))
101
for (uint i=0; i<n; i++)
96
for (uint32_t i=0; i<n; i++)
103
98
if (item2->element_index(i)->check_cols(item1->element_index(i)->cols()) ||
104
99
(item1->element_index(i)->result_type() == ROW_RESULT &&
135
static int agg_cmp_type(Item_result *type, Item **items, uint nitems)
130
static int agg_cmp_type(Item_result *type, Item **items, uint32_t nitems)
138
133
type[0]= items[0]->result_type();
139
134
for (i= 1 ; i < nitems ; i++)
171
166
@return aggregated field type.
174
enum_field_types agg_field_type(Item **items, uint nitems)
169
enum_field_types agg_field_type(Item **items, uint32_t nitems)
177
172
if (!nitems || items[0]->result_type() == ROW_RESULT )
178
173
return (enum_field_types)-1;
179
174
enum_field_types res= items[0]->field_type();
199
194
Bitmap of collected types - otherwise
202
static uint collect_cmp_types(Item **items, uint nitems)
197
static uint32_t collect_cmp_types(Item **items, uint32_t nitems)
200
uint32_t found_types;
206
201
Item_result left_result= items[0]->result_type();
207
DBUG_ASSERT(nitems > 1);
209
204
for (i= 1; i < nitems ; i++)
269
264
NULL if some arg is NULL.
272
longlong Item_func_not::val_int()
267
int64_t Item_func_not::val_int()
274
DBUG_ASSERT(fixed == 1);
275
270
bool value= args[0]->val_bool();
276
271
null_value=args[0]->null_value;
277
272
return ((!null_value && value == 0) ? 1 : 0);
339
334
returns some rows it return same value as argument (true/false).
342
longlong Item_func_nop_all::val_int()
337
int64_t Item_func_nop_all::val_int()
344
DBUG_ASSERT(fixed == 1);
345
longlong value= args[0]->val_int();
340
int64_t value= args[0]->val_int();
348
343
return false if there was records in underlying select in max/min
392
387
if (!(*item)->with_subselect && (*item)->const_item())
394
TABLE *table= field->table;
395
389
ulong orig_sql_mode= thd->variables.sql_mode;
396
390
enum_check_fields orig_count_cuted_fields= thd->count_cuted_fields;
397
my_bitmap_map *old_write_map;
398
my_bitmap_map *old_read_map;
399
ulonglong orig_field_val= 0; /* original field value if valid */
391
uint64_t orig_field_val= 0; /* original field value if valid */
403
old_write_map= dbug_tmp_use_all_columns(table, table->write_set);
404
old_read_map= dbug_tmp_use_all_columns(table, table->read_set);
406
393
/* For comparison purposes allow invalid dates like 2000-01-32 */
407
394
thd->variables.sql_mode= (orig_sql_mode & ~MODE_NO_ZERO_DATE) |
408
395
MODE_INVALID_DATES;
428
415
result= field->store(orig_field_val, true);
429
416
/* orig_field_val must be a valid value that can be restored back. */
430
DBUG_ASSERT(!result);
432
419
thd->variables.sql_mode= orig_sql_mode;
433
420
thd->count_cuted_fields= orig_count_cuted_fields;
436
dbug_tmp_restore_column_map(table->write_set, old_write_map);
437
dbug_tmp_restore_column_map(table->read_set, old_read_map);
485
467
thd= current_thd;
486
if (!thd->is_context_analysis_only())
469
if (args[0]->real_item()->type() == FIELD_ITEM)
488
if (args[0]->real_item()->type() == FIELD_ITEM)
471
Item_field *field_item= (Item_field*) (args[0]->real_item());
472
if (field_item->field->can_be_compared_as_int64_t() &&
473
!(field_item->is_datetime() && args[1]->result_type() == STRING_RESULT))
490
Item_field *field_item= (Item_field*) (args[0]->real_item());
491
if (field_item->field->can_be_compared_as_longlong() &&
492
!(field_item->is_datetime() &&
493
args[1]->result_type() == STRING_RESULT))
475
if (convert_constant_item(thd, field_item, &args[1]))
495
if (convert_constant_item(thd, field_item, &args[1]))
497
cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
498
INT_RESULT); // Works for all types.
499
args[0]->cmp_context= args[1]->cmp_context= INT_RESULT;
477
cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
478
INT_RESULT); // Works for all types.
479
args[0]->cmp_context= args[1]->cmp_context= INT_RESULT;
504
484
if (args[1]->real_item()->type() == FIELD_ITEM)
506
486
Item_field *field_item= (Item_field*) (args[1]->real_item());
507
if (field_item->field->can_be_compared_as_longlong() &&
487
if (field_item->field->can_be_compared_as_int64_t() &&
508
488
!(field_item->is_datetime() &&
509
489
args[0]->result_type() == STRING_RESULT))
581
561
which would be transformed to:
584
(*a)->walk(&Item::set_no_const_sub, false, (uchar*) 0);
585
(*b)->walk(&Item::set_no_const_sub, false, (uchar*) 0);
564
(*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
565
(*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
611
591
if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
613
precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
593
precision= 5 / log_10[cmax((*a)->decimals, (*b)->decimals) + 1];
614
594
if (func == &Arg_comparator::compare_real)
615
595
func= &Arg_comparator::compare_real_fixed;
616
596
else if (func == &Arg_comparator::compare_e_real)
647
627
converted value. 0 on error and on zero-dates -- check 'failure'
651
get_date_from_str(THD *thd, String *str, timestamp_type warn_type,
631
get_date_from_str(THD *thd, String *str, enum enum_drizzle_timestamp_type warn_type,
652
632
char *warn_name, bool *error_arg)
657
enum_mysql_timestamp_type ret;
637
enum enum_drizzle_timestamp_type ret;
659
639
ret= str_to_datetime(str->ptr(), str->length(), &l_time,
660
640
(TIME_FUZZY_DATE | MODE_INVALID_DATES |
661
(thd->variables.sql_mode &
662
(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE))),
641
(thd->variables.sql_mode & MODE_NO_ZERO_DATE)),
665
if (ret == MYSQL_TIMESTAMP_DATETIME || ret == MYSQL_TIMESTAMP_DATE)
644
if (ret == DRIZZLE_TIMESTAMP_DATETIME || ret == DRIZZLE_TIMESTAMP_DATE)
668
647
Do not return yet, we may still want to throw a "trailing garbage"
671
650
*error_arg= false;
672
value= TIME_to_ulonglong_datetime(&l_time);
651
value= TIME_to_uint64_t_datetime(&l_time);
681
make_truncated_value_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
660
make_truncated_value_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
682
661
str->ptr(), str->length(),
683
662
warn_type, warn_name);
721
700
enum Arg_comparator::enum_date_cmp_type
722
Arg_comparator::can_compare_as_dates(Item *a, Item *b, ulonglong *const_value)
701
Arg_comparator::can_compare_as_dates(Item *a, Item *b, uint64_t *const_value)
724
703
enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
725
704
Item *str_arg= 0, *date_arg= 0;
756
735
((Item_func*)str_arg)->functype() != Item_func::GUSERVAR_FUNC))
758
737
THD *thd= current_thd;
761
740
String tmp, *str_val= 0;
762
timestamp_type t_type= (date_arg->field_type() == MYSQL_TYPE_DATE ?
763
MYSQL_TIMESTAMP_DATE : MYSQL_TIMESTAMP_DATETIME);
741
enum enum_drizzle_timestamp_type t_type= (date_arg->field_type() == DRIZZLE_TYPE_NEWDATE ?
742
DRIZZLE_TIMESTAMP_DATE : DRIZZLE_TIMESTAMP_DATETIME);
765
744
str_val= str_arg->val_str(&tmp);
766
745
if (str_arg->null_value)
791
770
Retrieves the correct TIME value from given item for comparison by the
792
771
compare_datetime() function.
793
If item's result can be compared as longlong then its int value is used
772
If item's result can be compared as int64_t then its int value is used
794
773
and a value returned by get_time function is used otherwise.
795
774
If an item is a constant one then its value is cached and it isn't
796
775
get parsed again. An Item_cache_int object is used for for cached values.
805
get_time_value(THD *thd, Item ***item_arg, Item **cache_arg,
806
Item *warn_item, bool *is_null)
784
get_time_value(THD *thd __attribute__((unused)),
785
Item ***item_arg, Item **cache_arg,
786
Item *warn_item __attribute__((unused)),
809
790
Item *item= **item_arg;
812
if (item->result_as_longlong())
793
if (item->result_as_int64_t())
814
795
value= item->val_int();
815
796
*is_null= item->null_value;
878
859
get_value_func= &get_datetime_value;
881
else if (type == STRING_RESULT && (*a)->field_type() == MYSQL_TYPE_TIME &&
882
(*b)->field_type() == MYSQL_TYPE_TIME)
862
else if (type == STRING_RESULT && (*a)->field_type() == DRIZZLE_TYPE_TIME &&
863
(*b)->field_type() == DRIZZLE_TYPE_TIME)
884
865
/* Compare TIME values as integers. */
885
866
thd= current_thd;
928
909
Retrieves the correct DATETIME value from given item for comparison by the
929
910
compare_datetime() function.
930
If item's result can be compared as longlong then its int value is used
911
If item's result can be compared as int64_t then its int value is used
931
912
and its string value is used otherwise. Strings are always parsed and
932
913
converted to int values by the get_date_from_str() function.
933
914
This allows us to compare correctly string dates with missed insignificant
946
927
get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
947
928
Item *warn_item, bool *is_null)
950
931
String buf, *str= 0;
951
932
Item *item= **item_arg;
953
if (item->result_as_longlong())
934
if (item->result_as_int64_t())
955
936
value= item->val_int();
956
937
*is_null= item->null_value;
957
938
enum_field_types f_type= item->field_type();
959
Item_date_add_interval may return MYSQL_TYPE_STRING as the result
940
Item_date_add_interval may return DRIZZLE_TYPE_STRING as the result
960
941
field type. To detect that the DATE value has been returned we
961
942
compare it with 100000000L - any DATE value should be less than it.
962
943
Don't shift cached DATETIME values up for the second time.
964
if (f_type == MYSQL_TYPE_DATE ||
965
(f_type != MYSQL_TYPE_DATETIME && value < 100000000L))
945
if (f_type == DRIZZLE_TYPE_NEWDATE ||
946
(f_type != DRIZZLE_TYPE_DATETIME && value < 100000000L))
966
947
value*= 1000000L;
984
965
enum_field_types f_type= warn_item->field_type();
985
timestamp_type t_type= f_type ==
986
MYSQL_TYPE_DATE ? MYSQL_TIMESTAMP_DATE : MYSQL_TIMESTAMP_DATETIME;
966
enum enum_drizzle_timestamp_type t_type= f_type ==
967
DRIZZLE_TYPE_NEWDATE ? DRIZZLE_TIMESTAMP_DATE : DRIZZLE_TIMESTAMP_DATETIME;
987
968
value= get_date_from_str(thd, str, t_type, warn_item->name, &error);
989
970
If str did not contain a valid date according to the current
999
980
if (item->const_item() && cache_arg && (item->type() != Item::FUNC_ITEM ||
1000
981
((Item_func*)item)->functype() != Item_func::GUSERVAR_FUNC))
1002
Item_cache_int *cache= new Item_cache_int(MYSQL_TYPE_DATETIME);
983
Item_cache_int *cache= new Item_cache_int(DRIZZLE_TYPE_DATETIME);
1003
984
/* Mark the cache as non-const to prevent re-caching. */
1004
985
cache->set_used_tables(1);
1005
986
cache->store(item, value);
1033
1014
int Arg_comparator::compare_datetime()
1035
1016
bool is_null= false;
1036
ulonglong a_value, b_value;
1017
uint64_t a_value, b_value;
1038
1019
/* Get DATE/DATETIME/TIME value of the 'a' item. */
1039
1020
a_value= (*get_value_func)(thd, &a, &a_cache, *b, &is_null);
1098
1079
if ((res2= (*b)->val_str(&owner->tmp_value2)))
1100
1081
owner->null_value= 0;
1101
uint res1_length= res1->length();
1102
uint res2_length= res2->length();
1103
int cmp= memcmp(res1->ptr(), res2->ptr(), min(res1_length,res2_length));
1082
uint32_t res1_length= res1->length();
1083
uint32_t res2_length= res2->length();
1084
int cmp= memcmp(res1->ptr(), res2->ptr(), cmin(res1_length,res2_length));
1104
1085
return cmp ? cmp : (int) (res1_length - res2_length);
1284
1265
int Arg_comparator::compare_int_signed_unsigned()
1286
longlong sval1= (*a)->val_int();
1267
int64_t sval1= (*a)->val_int();
1287
1268
if (!(*a)->null_value)
1289
ulonglong uval2= (ulonglong)(*b)->val_int();
1270
uint64_t uval2= (uint64_t)(*b)->val_int();
1290
1271
if (!(*b)->null_value)
1292
1273
owner->null_value= 0;
1293
if (sval1 < 0 || (ulonglong)sval1 < uval2)
1274
if (sval1 < 0 || (uint64_t)sval1 < uval2)
1295
if ((ulonglong)sval1 == uval2)
1276
if ((uint64_t)sval1 == uval2)
1309
1290
int Arg_comparator::compare_int_unsigned_signed()
1311
ulonglong uval1= (ulonglong)(*a)->val_int();
1292
uint64_t uval1= (uint64_t)(*a)->val_int();
1312
1293
if (!(*a)->null_value)
1314
longlong sval2= (*b)->val_int();
1295
int64_t sval2= (*b)->val_int();
1315
1296
if (!(*b)->null_value)
1317
1298
owner->null_value= 0;
1320
if (uval1 < (ulonglong)sval2)
1301
if (uval1 < (uint64_t)sval2)
1322
if (uval1 == (ulonglong)sval2)
1303
if (uval1 == (uint64_t)sval2)
1332
1313
int Arg_comparator::compare_e_int()
1334
longlong val1= (*a)->val_int();
1335
longlong val2= (*b)->val_int();
1315
int64_t val1= (*a)->val_int();
1316
int64_t val2= (*b)->val_int();
1336
1317
if ((*a)->null_value || (*b)->null_value)
1337
1318
return test((*a)->null_value && (*b)->null_value);
1338
1319
return test(val1 == val2);
1344
1325
int Arg_comparator::compare_e_int_diff_signedness()
1346
longlong val1= (*a)->val_int();
1347
longlong val2= (*b)->val_int();
1327
int64_t val1= (*a)->val_int();
1328
int64_t val2= (*b)->val_int();
1348
1329
if ((*a)->null_value || (*b)->null_value)
1349
1330
return test((*a)->null_value && (*b)->null_value);
1350
1331
return (val1 >= 0) && test(val1 == val2);
1459
longlong Item_func_truth::val_int()
1440
int64_t Item_func_truth::val_int()
1461
1442
return (val_bool() ? 1 : 0);
1465
bool Item_in_optimizer::fix_left(THD *thd, Item **ref)
1446
bool Item_in_optimizer::fix_left(THD *thd, Item **ref __attribute__((unused)))
1467
1448
if ((!args[0]->fixed && args[0]->fix_fields(thd, args)) ||
1468
1449
(!cache && !(cache= Item_cache::get_cache(args[0]))))
1481
uint n= cache->cols();
1482
for (uint i= 0; i < n; i++)
1462
uint32_t n= cache->cols();
1463
for (uint32_t i= 0; i < n; i++)
1484
1465
if (args[0]->element_index(i)->used_tables())
1485
1466
((Item_cache *)cache->element_index(i))->set_used_tables(OUTER_REF_TABLE_BIT);
1641
1621
@retval NULL if an error occurred
1644
Item *Item_in_optimizer::transform(Item_transformer transformer, uchar *argument)
1624
Item *Item_in_optimizer::transform(Item_transformer transformer, unsigned char *argument)
1646
1626
Item *new_item;
1648
DBUG_ASSERT(arg_count == 2);
1628
assert(arg_count == 2);
1650
1630
/* Transform the left IN operand. */
1651
1631
new_item= (*args)->transform(transformer, argument);
1667
1647
transformation, we only make both operands the same.
1668
1648
TODO: is it the way it should be?
1670
DBUG_ASSERT((args[1])->type() == Item::SUBSELECT_ITEM &&
1650
assert((args[1])->type() == Item::SUBSELECT_ITEM &&
1671
1651
(((Item_subselect*)(args[1]))->substype() ==
1672
1652
Item_subselect::IN_SUBS ||
1673
1653
((Item_subselect*)(args[1]))->substype() ==
1699
1679
maybe_null=null_value=0;
1702
longlong Item_func_equal::val_int()
1682
int64_t Item_func_equal::val_int()
1704
DBUG_ASSERT(fixed == 1);
1705
1685
return cmp.compare();
1708
longlong Item_func_ne::val_int()
1688
int64_t Item_func_ne::val_int()
1710
DBUG_ASSERT(fixed == 1);
1711
1691
int value= cmp.compare();
1712
1692
return value != 0 && !null_value ? 1 : 0;
1716
longlong Item_func_ge::val_int()
1696
int64_t Item_func_ge::val_int()
1718
DBUG_ASSERT(fixed == 1);
1719
1699
int value= cmp.compare();
1720
1700
return value >= 0 ? 1 : 0;
1724
longlong Item_func_gt::val_int()
1704
int64_t Item_func_gt::val_int()
1726
DBUG_ASSERT(fixed == 1);
1727
1707
int value= cmp.compare();
1728
1708
return value > 0 ? 1 : 0;
1731
longlong Item_func_le::val_int()
1711
int64_t Item_func_le::val_int()
1733
DBUG_ASSERT(fixed == 1);
1734
1714
int value= cmp.compare();
1735
1715
return value <= 0 && !null_value ? 1 : 0;
1739
longlong Item_func_lt::val_int()
1719
int64_t Item_func_lt::val_int()
1741
DBUG_ASSERT(fixed == 1);
1742
1722
int value= cmp.compare();
1743
1723
return value < 0 && !null_value ? 1 : 0;
1747
longlong Item_func_strcmp::val_int()
1727
int64_t Item_func_strcmp::val_int()
1749
DBUG_ASSERT(fixed == 1);
1750
1730
String *a=args[0]->val_str(&tmp_value1);
1751
1731
String *b=args[1]->val_str(&tmp_value2);
1793
1773
bool not_null_consts= true;
1795
for (uint i= 1; not_null_consts && i < rows; i++)
1775
for (uint32_t i= 1; not_null_consts && i < rows; i++)
1797
1777
Item *el= row->element_index(i);
1798
1778
not_null_consts&= el->const_item() & !el->is_null();
1859
1839
- arg_count if higher than biggest argument
1862
longlong Item_func_interval::val_int()
1842
int64_t Item_func_interval::val_int()
1864
DBUG_ASSERT(fixed == 1);
1866
1846
my_decimal dec_buf, *dec= NULL;
1869
1849
if (use_decimal_comparison)
1884
1864
{ // Use binary search to find interval
1887
1867
end= row->cols()-2;
1888
1868
while (start != end)
1890
uint mid= (start + end + 1) / 2;
1870
uint32_t mid= (start + end + 1) / 2;
1891
1871
interval_range *range= intervals + mid;
1894
1874
The values in the range intervall may have different types,
1895
1875
Only do a decimal comparision of the first argument is a decimal
2043
2023
thd->lex->sql_command != SQLCOM_SHOW_CREATE)
2045
2025
Item_field *field_item= (Item_field*) (args[0]->real_item());
2046
if (field_item->field->can_be_compared_as_longlong())
2026
if (field_item->field->can_be_compared_as_int64_t())
2049
2029
The following can't be recoded with || as convert_constant_item
2071
2051
le_res= le_cmp.compare();
2073
2053
if (!args[1]->null_value && !args[2]->null_value)
2074
return (longlong) ((ge_res >= 0 && le_res <=0) != negated);
2054
return (int64_t) ((ge_res >= 0 && le_res <=0) != negated);
2075
2055
else if (args[1]->null_value)
2077
2057
null_value= le_res > 0; // not null if false range.
2090
2070
a=args[1]->val_str(&value1);
2091
2071
b=args[2]->val_str(&value2);
2092
2072
if (!args[1]->null_value && !args[2]->null_value)
2093
return (longlong) ((sortcmp(value,a,cmp_collation.collation) >= 0 &&
2073
return (int64_t) ((sortcmp(value,a,cmp_collation.collation) >= 0 &&
2094
2074
sortcmp(value,b,cmp_collation.collation) <= 0) !=
2096
2076
if (args[1]->null_value && args[2]->null_value)
2109
2089
else if (cmp_type == INT_RESULT)
2111
longlong value=args[0]->val_int(), a, b;
2091
int64_t value=args[0]->val_int(), a, b;
2112
2092
if ((null_value=args[0]->null_value))
2113
2093
return 0; /* purecov: inspected */
2114
2094
a=args[1]->val_int();
2115
2095
b=args[2]->val_int();
2116
2096
if (!args[1]->null_value && !args[2]->null_value)
2117
return (longlong) ((value >= a && value <= b) != negated);
2097
return (int64_t) ((value >= a && value <= b) != negated);
2118
2098
if (args[1]->null_value && args[2]->null_value)
2120
2100
else if (args[1]->null_value)
2135
2115
a_dec= args[1]->val_decimal(&a_buf);
2136
2116
b_dec= args[2]->val_decimal(&b_buf);
2137
2117
if (!args[1]->null_value && !args[2]->null_value)
2138
return (longlong) ((my_decimal_cmp(dec, a_dec) >= 0 &&
2118
return (int64_t) ((my_decimal_cmp(dec, a_dec) >= 0 &&
2139
2119
my_decimal_cmp(dec, b_dec) <= 0) != negated);
2140
2120
if (args[1]->null_value && args[2]->null_value)
2152
2132
a= args[1]->val_real();
2153
2133
b= args[2]->val_real();
2154
2134
if (!args[1]->null_value && !args[2]->null_value)
2155
return (longlong) ((value >= a && value <= b) != negated);
2135
return (int64_t) ((value >= a && value <= b) != negated);
2156
2136
if (args[1]->null_value && args[2]->null_value)
2158
2138
else if (args[1]->null_value)
2187
2167
agg_result_type(&hybrid_type, args, 2);
2188
2168
maybe_null=args[1]->maybe_null;
2189
decimals= max(args[0]->decimals, args[1]->decimals);
2169
decimals= cmax(args[0]->decimals, args[1]->decimals);
2190
2170
unsigned_flag= args[0]->unsigned_flag && args[1]->unsigned_flag;
2192
2172
if (hybrid_type == DECIMAL_RESULT || hybrid_type == INT_RESULT)
2197
2177
int len1= args[1]->max_length - args[1]->decimals
2198
2178
- (args[1]->unsigned_flag ? 0 : 1);
2200
max_length= max(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
2180
max_length= cmax(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
2203
max_length= max(args[0]->max_length, args[1]->max_length);
2183
max_length= cmax(args[0]->max_length, args[1]->max_length);
2205
2185
switch (hybrid_type) {
2206
2186
case STRING_RESULT:
2215
2195
case ROW_RESULT:
2219
2199
cached_field_type= agg_field_type(args, 2);
2223
uint Item_func_ifnull::decimal_precision() const
2203
uint32_t Item_func_ifnull::decimal_precision() const
2225
int max_int_part=max(args[0]->decimal_int_part(),args[1]->decimal_int_part());
2226
return min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2205
int max_int_part=cmax(args[0]->decimal_int_part(),args[1]->decimal_int_part());
2206
return cmin(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2351
2331
Item_func_if::fix_length_and_dec()
2353
2333
maybe_null=args[1]->maybe_null || args[2]->maybe_null;
2354
decimals= max(args[1]->decimals, args[2]->decimals);
2334
decimals= cmax(args[1]->decimals, args[2]->decimals);
2355
2335
unsigned_flag=args[1]->unsigned_flag && args[2]->unsigned_flag;
2357
2337
enum Item_result arg1_type=args[1]->result_type();
2395
2375
int len2= args[2]->max_length - args[2]->decimals
2396
2376
- (args[2]->unsigned_flag ? 0 : 1);
2398
max_length=max(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
2378
max_length=cmax(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
2401
max_length= max(args[1]->max_length, args[2]->max_length);
2381
max_length= cmax(args[1]->max_length, args[2]->max_length);
2405
uint Item_func_if::decimal_precision() const
2385
uint32_t Item_func_if::decimal_precision() const
2407
int precision=(max(args[1]->decimal_int_part(),args[2]->decimal_int_part())+
2387
int precision=(cmax(args[1]->decimal_int_part(),args[2]->decimal_int_part())+
2409
return min(precision, DECIMAL_MAX_PRECISION);
2389
return cmin(precision, DECIMAL_MAX_PRECISION);
2414
2394
Item_func_if::val_real()
2416
DBUG_ASSERT(fixed == 1);
2417
2397
Item *arg= args[0]->val_bool() ? args[1] : args[2];
2418
2398
double value= arg->val_real();
2419
2399
null_value=arg->null_value;
2424
2404
Item_func_if::val_int()
2426
DBUG_ASSERT(fixed == 1);
2427
2407
Item *arg= args[0]->val_bool() ? args[1] : args[2];
2428
longlong value=arg->val_int();
2408
int64_t value=arg->val_int();
2429
2409
null_value=arg->null_value;
2575
Item *Item_func_case::find_item(String *str)
2555
Item *Item_func_case::find_item(String *str __attribute__((unused)))
2577
uint value_added_map= 0;
2557
uint32_t value_added_map= 0;
2579
2559
if (first_expr_num == -1)
2581
for (uint i=0 ; i < ncases ; i+=2)
2561
for (uint32_t i=0 ; i < ncases ; i+=2)
2583
2563
// No expression between CASE and the first WHEN
2584
2564
if (args[i]->val_bool())
2591
2571
/* Compare every WHEN argument with it and return the first match */
2592
for (uint i=0 ; i < ncases ; i+=2)
2572
for (uint32_t i=0 ; i < ncases ; i+=2)
2594
2574
cmp_type= item_cmp_type(left_result_type, args[i]->result_type());
2595
DBUG_ASSERT(cmp_type != ROW_RESULT);
2596
DBUG_ASSERT(cmp_items[(uint)cmp_type]);
2575
assert(cmp_type != ROW_RESULT);
2576
assert(cmp_items[(uint)cmp_type]);
2597
2577
if (!(value_added_map & (1<<(uint)cmp_type)))
2599
2579
cmp_items[(uint)cmp_type]->store_value(args[first_expr_num]);
2631
longlong Item_func_case::val_int()
2611
int64_t Item_func_case::val_int()
2633
DBUG_ASSERT(fixed == 1);
2634
2614
char buff[MAX_FIELD_WIDTH];
2635
2615
String dummy_str(buff,sizeof(buff),default_charset());
2636
2616
Item *item=find_item(&dummy_str);
2668
2648
my_decimal *Item_func_case::val_decimal(my_decimal *decimal_value)
2670
DBUG_ASSERT(fixed == 1);
2671
2651
char buff[MAX_FIELD_WIDTH];
2672
2652
String dummy_str(buff, sizeof(buff), default_charset());
2673
2653
Item *item= find_item(&dummy_str);
2691
2671
buff should match stack usage from
2692
2672
Item_func_case::val_int() -> Item_func_case::find_item()
2694
uchar buff[MAX_FIELD_WIDTH*2+sizeof(String)*2+sizeof(String*)*2+sizeof(double)*2+sizeof(longlong)*2];
2674
unsigned char buff[MAX_FIELD_WIDTH*2+sizeof(String)*2+sizeof(String*)*2+sizeof(double)*2+sizeof(int64_t)*2];
2695
2675
bool res= Item_func::fix_fields(thd, ref);
2697
2677
Call check_stack_overrun after fix_fields to be sure that stack variable
2714
2694
void Item_func_case::agg_num_lengths(Item *arg)
2716
uint len= my_decimal_length_to_precision(arg->max_length, arg->decimals,
2696
uint32_t len= my_decimal_length_to_precision(arg->max_length, arg->decimals,
2717
2697
arg->unsigned_flag) - arg->decimals;
2718
2698
set_if_bigger(max_length, len);
2719
2699
set_if_bigger(decimals, arg->decimals);
2767
2747
if (found_types & (1 << i) && !cmp_items[i])
2769
DBUG_ASSERT((Item_result)i != ROW_RESULT);
2749
assert((Item_result)i != ROW_RESULT);
2770
2750
if ((Item_result)i == STRING_RESULT &&
2771
2751
agg_arg_charsets(cmp_collation, agg, nagg, MY_COLL_CMP_CONV, 1))
2786
2766
unsigned_flag= true;
2787
2767
if (cached_result_type == STRING_RESULT)
2789
for (uint i= 0; i < ncases; i+= 2)
2769
for (uint32_t i= 0; i < ncases; i+= 2)
2790
2770
agg_str_lengths(args[i + 1]);
2791
2771
if (else_expr_num != -1)
2792
2772
agg_str_lengths(args[else_expr_num]);
2796
for (uint i= 0; i < ncases; i+= 2)
2776
for (uint32_t i= 0; i < ncases; i+= 2)
2797
2777
agg_num_lengths(args[i + 1]);
2798
2778
if (else_expr_num != -1)
2799
2779
agg_num_lengths(args[else_expr_num]);
2806
uint Item_func_case::decimal_precision() const
2786
uint32_t Item_func_case::decimal_precision() const
2808
2788
int max_int_part=0;
2809
for (uint i=0 ; i < ncases ; i+=2)
2789
for (uint32_t i=0 ; i < ncases ; i+=2)
2810
2790
set_if_bigger(max_int_part, args[i+1]->decimal_int_part());
2812
2792
if (else_expr_num != -1)
2813
2793
set_if_bigger(max_int_part, args[else_expr_num]->decimal_int_part());
2814
return min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2794
return cmin(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2828
2808
args[first_expr_num]->print(str, query_type);
2829
2809
str->append(' ');
2831
for (uint i=0 ; i < ncases ; i+=2)
2811
for (uint32_t i=0 ; i < ncases ; i+=2)
2833
2813
str->append(STRING_WITH_LEN("when "));
2834
2814
args[i]->print(str, query_type);
2881
longlong Item_func_coalesce::int_op()
2860
int64_t Item_func_coalesce::int_op()
2883
DBUG_ASSERT(fixed == 1);
2885
for (uint i=0 ; i < arg_count ; i++)
2864
for (uint32_t i=0 ; i < arg_count ; i++)
2887
longlong res=args[i]->val_int();
2866
int64_t res=args[i]->val_int();
2888
2867
if (!args[i]->null_value)
2910
2889
my_decimal *Item_func_coalesce::decimal_op(my_decimal *decimal_value)
2912
DBUG_ASSERT(fixed == 1);
2914
for (uint i= 0; i < arg_count; i++)
2893
for (uint32_t i= 0; i < arg_count; i++)
2916
2895
my_decimal *res= args[i]->val_decimal(decimal_value);
2917
2896
if (!args[i]->null_value)
2961
2940
b_val right argument
2964
This function will compare two signed longlong arguments
2943
This function will compare two signed int64_t arguments
2965
2944
and will return -1, 0, or 1 if left argument is smaller than,
2966
2945
equal to or greater than the right argument.
2970
2949
0 left argument is equal to the right argument.
2971
2950
1 left argument is greater than the right argument.
2973
static inline int cmp_longs (longlong a_val, longlong b_val)
2952
static inline int cmp_longs (int64_t a_val, int64_t b_val)
2975
2954
return a_val < b_val ? -1 : a_val == b_val ? 0 : 1;
2980
Determine which of the unsigned longlong arguments is bigger
2959
Determine which of the unsigned int64_t arguments is bigger
2985
2964
b_val right argument
2988
This function will compare two unsigned longlong arguments
2967
This function will compare two unsigned int64_t arguments
2989
2968
and will return -1, 0, or 1 if left argument is smaller than,
2990
2969
equal to or greater than the right argument.
2994
2973
0 left argument is equal to the right argument.
2995
2974
1 left argument is greater than the right argument.
2997
static inline int cmp_ulongs (ulonglong a_val, ulonglong b_val)
2976
static inline int cmp_ulongs (uint64_t a_val, uint64_t b_val)
2999
2978
return a_val < b_val ? -1 : a_val == b_val ? 0 : 1;
3004
Compare two integers in IN value list format (packed_longlong)
2983
Compare two integers in IN value list format (packed_int64_t)
3008
2987
cmp_arg an argument passed to the calling function (my_qsort2)
3009
2988
a left argument
3010
2989
b right argument
3014
2993
format and will return -1, 0, or 1 if left argument is smaller than,
3015
2994
equal to or greater than the right argument.
3016
2995
It's used in sorting the IN values list and finding an element in it.
3017
Depending on the signedness of the arguments cmp_longlong() will
2996
Depending on the signedness of the arguments cmp_int64_t() will
3018
2997
compare them as either signed (using cmp_longs()) or unsigned (using
3023
3002
0 left argument is equal to the right argument.
3024
3003
1 left argument is greater than the right argument.
3026
int cmp_longlong(void *cmp_arg,
3027
in_longlong::packed_longlong *a,
3028
in_longlong::packed_longlong *b)
3005
int cmp_int64_t(void *cmp_arg __attribute__((unused)),
3006
in_int64_t::packed_int64_t *a,
3007
in_int64_t::packed_int64_t *b)
3030
3009
if (a->unsigned_flag != b->unsigned_flag)
3033
3012
One of the args is unsigned and is too big to fit into the
3034
3013
positive signed range. Report no match.
3036
if ((a->unsigned_flag && ((ulonglong) a->val) > (ulonglong) LONGLONG_MAX) ||
3037
(b->unsigned_flag && ((ulonglong) b->val) > (ulonglong) LONGLONG_MAX))
3015
if ((a->unsigned_flag && ((uint64_t) a->val) > (uint64_t) INT64_MAX) ||
3016
(b->unsigned_flag && ((uint64_t) b->val) > (uint64_t) INT64_MAX))
3038
3017
return a->unsigned_flag ? 1 : -1;
3040
3019
Although the signedness differs both args can fit into the signed
3043
3022
return cmp_longs (a->val, b->val);
3045
3024
if (a->unsigned_flag)
3046
return cmp_ulongs ((ulonglong) a->val, (ulonglong) b->val);
3025
return cmp_ulongs ((uint64_t) a->val, (uint64_t) b->val);
3048
3027
return cmp_longs (a->val, b->val);
3051
static int cmp_double(void *cmp_arg, double *a,double *b)
3030
static int cmp_double(void *cmp_arg __attribute__((unused)), double *a,double *b)
3053
3032
return *a < *b ? -1 : *a == *b ? 0 : 1;
3056
static int cmp_row(void *cmp_arg, cmp_item_row *a, cmp_item_row *b)
3035
static int cmp_row(void *cmp_arg __attribute__((unused)), cmp_item_row *a, cmp_item_row *b)
3058
3037
return a->compare(b);
3062
static int cmp_decimal(void *cmp_arg, my_decimal *a, my_decimal *b)
3041
static int cmp_decimal(void *cmp_arg __attribute__((unused)), my_decimal *a, my_decimal *b)
3065
3044
We need call of fixing buffer pointer, because fast sort just copy
3074
3053
int in_vector::find(Item *item)
3076
uchar *result=get_value(item);
3055
unsigned char *result=get_value(item);
3077
3056
if (!result || !used_count)
3078
3057
return 0; // Null value
3081
3060
start=0; end=used_count-1;
3082
3061
while (start != end)
3084
uint mid=(start+end+1)/2;
3063
uint32_t mid=(start+end+1)/2;
3086
3065
if ((res=(*compare)(collation, base+mid*size, result)) == 0)
3093
3072
return (int) ((*compare)(collation, base+start*size, result) == 0);
3096
in_string::in_string(uint elements,qsort2_cmp cmp_func, CHARSET_INFO *cs)
3075
in_string::in_string(uint32_t elements,qsort2_cmp cmp_func, const CHARSET_INFO * const cs)
3097
3076
:in_vector(elements, sizeof(String), cmp_func, cs),
3098
3077
tmp(buff, sizeof(buff), &my_charset_bin)
3105
3084
// base was allocated with help of sql_alloc => following is OK
3106
for (uint i=0 ; i < count ; i++)
3085
for (uint32_t i=0 ; i < count ; i++)
3107
3086
((String*) base)[i].free();
3111
void in_string::set(uint pos,Item *item)
3090
void in_string::set(uint32_t pos,Item *item)
3113
3092
String *str=((String*) base)+pos;
3114
3093
String *res=item->val_str(str);
3134
uchar *in_string::get_value(Item *item)
3113
unsigned char *in_string::get_value(Item *item)
3136
return (uchar*) item->val_str(&tmp);
3115
return (unsigned char*) item->val_str(&tmp);
3139
in_row::in_row(uint elements, Item * item)
3118
in_row::in_row(uint32_t elements, Item * item __attribute__((unused)))
3141
3120
base= (char*) new cmp_item_row[count= elements];
3142
3121
size= sizeof(cmp_item_row);
3155
3134
delete [] (cmp_item_row*) base;
3158
uchar *in_row::get_value(Item *item)
3137
unsigned char *in_row::get_value(Item *item)
3160
3139
tmp.store_value(item);
3161
3140
if (item->is_null())
3163
return (uchar *)&tmp;
3142
return (unsigned char *)&tmp;
3166
void in_row::set(uint pos, Item *item)
3145
void in_row::set(uint32_t pos, Item *item)
3168
DBUG_ENTER("in_row::set");
3169
DBUG_PRINT("enter", ("pos: %u item: 0x%lx", pos, (ulong) item));
3170
3147
((cmp_item_row*) base)[pos].store_value_by_template(&tmp, item);
3174
in_longlong::in_longlong(uint elements)
3175
:in_vector(elements,sizeof(packed_longlong),(qsort2_cmp) cmp_longlong, 0)
3151
in_int64_t::in_int64_t(uint32_t elements)
3152
:in_vector(elements,sizeof(packed_int64_t),(qsort2_cmp) cmp_int64_t, 0)
3178
void in_longlong::set(uint pos,Item *item)
3155
void in_int64_t::set(uint32_t pos,Item *item)
3180
struct packed_longlong *buff= &((packed_longlong*) base)[pos];
3157
struct packed_int64_t *buff= &((packed_int64_t*) base)[pos];
3182
3159
buff->val= item->val_int();
3183
3160
buff->unsigned_flag= item->unsigned_flag;
3186
uchar *in_longlong::get_value(Item *item)
3163
unsigned char *in_int64_t::get_value(Item *item)
3188
3165
tmp.val= item->val_int();
3189
3166
if (item->null_value)
3191
3168
tmp.unsigned_flag= item->unsigned_flag;
3192
return (uchar*) &tmp;
3169
return (unsigned char*) &tmp;
3195
void in_datetime::set(uint pos,Item *item)
3172
void in_datetime::set(uint32_t pos,Item *item)
3197
3174
Item **tmp_item= &item;
3199
struct packed_longlong *buff= &((packed_longlong*) base)[pos];
3176
struct packed_int64_t *buff= &((packed_int64_t*) base)[pos];
3201
3178
buff->val= get_datetime_value(thd, &tmp_item, 0, warn_item, &is_null);
3202
3179
buff->unsigned_flag= 1L;
3205
uchar *in_datetime::get_value(Item *item)
3182
unsigned char *in_datetime::get_value(Item *item)
3208
3185
Item **tmp_item= lval_cache ? &lval_cache : &item;
3210
3187
if (item->null_value)
3212
3189
tmp.unsigned_flag= 1L;
3213
return (uchar*) &tmp;
3190
return (unsigned char*) &tmp;
3216
in_double::in_double(uint elements)
3193
in_double::in_double(uint32_t elements)
3217
3194
:in_vector(elements,sizeof(double),(qsort2_cmp) cmp_double, 0)
3220
void in_double::set(uint pos,Item *item)
3197
void in_double::set(uint32_t pos,Item *item)
3222
3199
((double*) base)[pos]= item->val_real();
3225
uchar *in_double::get_value(Item *item)
3202
unsigned char *in_double::get_value(Item *item)
3227
3204
tmp= item->val_real();
3228
3205
if (item->null_value)
3229
3206
return 0; /* purecov: inspected */
3230
return (uchar*) &tmp;
3207
return (unsigned char*) &tmp;
3234
in_decimal::in_decimal(uint elements)
3211
in_decimal::in_decimal(uint32_t elements)
3235
3212
:in_vector(elements, sizeof(my_decimal),(qsort2_cmp) cmp_decimal, 0)
3239
void in_decimal::set(uint pos, Item *item)
3216
void in_decimal::set(uint32_t pos, Item *item)
3241
3218
/* as far as 'item' is constant, we can store reference on my_decimal */
3242
3219
my_decimal *dec= ((my_decimal *)base) + pos;
3252
uchar *in_decimal::get_value(Item *item)
3229
unsigned char *in_decimal::get_value(Item *item)
3254
3231
my_decimal *result= item->val_decimal(&val);
3255
3232
if (item->null_value)
3257
return (uchar *)result;
3234
return (unsigned char *)result;
3261
3238
cmp_item* cmp_item::get_comparator(Item_result type,
3239
const CHARSET_INFO * const cs)
3264
3241
switch (type) {
3265
3242
case STRING_RESULT:
3304
3281
cmp_item_row::~cmp_item_row()
3306
DBUG_ENTER("~cmp_item_row");
3307
DBUG_PRINT("enter",("this: 0x%lx", (long) this));
3308
3283
if (comparators)
3310
for (uint i= 0; i < n; i++)
3285
for (uint32_t i= 0; i < n; i++)
3312
3287
if (comparators[i])
3313
3288
delete comparators[i];
3399
3373
int cmp_item_row::compare(cmp_item *c)
3401
3375
cmp_item_row *l_cmp= (cmp_item_row *) c;
3402
for (uint i=0; i < n; i++)
3376
for (uint32_t i=0; i < n; i++)
3405
3379
if ((res= comparators[i]->compare(l_cmp->comparators[i])))
3534
static int srtcmp_in(CHARSET_INFO *cs, const String *x,const String *y)
3508
static int srtcmp_in(const CHARSET_INFO * const cs, const String *x,const String *y)
3536
3510
return cs->coll->strnncollsp(cs,
3537
(uchar *) x->ptr(),x->length(),
3538
(uchar *) y->ptr(),y->length(), 0);
3511
(unsigned char *) x->ptr(),x->length(),
3512
(unsigned char *) y->ptr(),y->length(), 0);
3548
3522
/* true <=> arguments values will be compared as DATETIMEs. */
3549
3523
bool compare_as_datetime= false;
3550
3524
Item *date_arg= 0;
3551
uint found_types= 0;
3552
uint type_cnt= 0, i;
3525
uint32_t found_types= 0;
3526
uint32_t type_cnt= 0, i;
3553
3527
Item_result cmp_type= STRING_RESULT;
3554
3528
left_result_type= args[0]->result_type();
3555
3529
if (!(found_types= collect_cmp_types(args, arg_count)))
3605
3579
/* All DATE/DATETIME fields/functions has the STRING result type. */
3606
3580
if (cmp_type == STRING_RESULT || cmp_type == ROW_RESULT)
3608
uint col, cols= args[0]->cols();
3582
uint32_t col, cols= args[0]->cols();
3610
3584
for (col= 0; col < cols; col++)
3685
3659
cmp_type != INT_RESULT)
3687
3661
Item_field *field_item= (Item_field*) (args[0]->real_item());
3688
if (field_item->field->can_be_compared_as_longlong())
3662
if (field_item->field->can_be_compared_as_int64_t())
3690
3664
bool all_converted= true;
3691
3665
for (arg=args+1, arg_end=args+arg_count; arg != arg_end ; arg++)
3720
3694
array= new in_decimal(arg_count - 1);
3727
3701
if (array && !(thd->is_fatal_error)) // If not EOM
3730
for (uint i=1 ; i < arg_count ; i++)
3704
for (uint32_t i=1 ; i < arg_count ; i++)
3732
3706
array->set(j,args[i]);
3733
3707
if (!args[i]->null_value) // Skip NULL values
3802
3776
Value of the function
3805
longlong Item_func_in::val_int()
3779
int64_t Item_func_in::val_int()
3807
3781
cmp_item *in_item;
3808
DBUG_ASSERT(fixed == 1);
3809
uint value_added_map= 0;
3783
uint32_t value_added_map= 0;
3812
3786
int tmp=array->find(args[0]);
3813
3787
null_value=args[0]->null_value || (!tmp && have_null);
3814
return (longlong) (!null_value && tmp != negated);
3788
return (int64_t) (!null_value && tmp != negated);
3817
for (uint i= 1 ; i < arg_count ; i++)
3791
for (uint32_t i= 1 ; i < arg_count ; i++)
3819
3793
Item_result cmp_type= item_cmp_type(left_result_type, args[i]->result_type());
3820
3794
in_item= cmp_items[(uint)cmp_type];
3821
DBUG_ASSERT(in_item);
3822
3796
if (!(value_added_map & (1 << (uint)cmp_type)))
3824
3798
in_item->store_value(args[0]);
3828
3802
value_added_map|= 1 << (uint)cmp_type;
3830
3804
if (!in_item->cmp(args[i]) && !args[i]->null_value)
3831
return (longlong) (!negated);
3805
return (int64_t) (!negated);
3832
3806
have_null|= args[i]->null_value;
3835
3809
null_value= have_null;
3836
return (longlong) (!null_value && negated);
3810
return (int64_t) (!null_value && negated);
3840
longlong Item_func_bit_or::val_int()
3814
int64_t Item_func_bit_or::val_int()
3842
DBUG_ASSERT(fixed == 1);
3843
ulonglong arg1= (ulonglong) args[0]->val_int();
3817
uint64_t arg1= (uint64_t) args[0]->val_int();
3844
3818
if (args[0]->null_value)
3846
3820
null_value=1; /* purecov: inspected */
3847
3821
return 0; /* purecov: inspected */
3849
ulonglong arg2= (ulonglong) args[1]->val_int();
3823
uint64_t arg2= (uint64_t) args[1]->val_int();
3850
3824
if (args[1]->null_value)
3856
return (longlong) (arg1 | arg2);
3830
return (int64_t) (arg1 | arg2);
3860
longlong Item_func_bit_and::val_int()
3834
int64_t Item_func_bit_and::val_int()
3862
DBUG_ASSERT(fixed == 1);
3863
ulonglong arg1= (ulonglong) args[0]->val_int();
3837
uint64_t arg1= (uint64_t) args[0]->val_int();
3864
3838
if (args[0]->null_value)
3866
3840
null_value=1; /* purecov: inspected */
3867
3841
return 0; /* purecov: inspected */
3869
ulonglong arg2= (ulonglong) args[1]->val_int();
3843
uint64_t arg2= (uint64_t) args[1]->val_int();
3870
3844
if (args[1]->null_value)
3872
3846
null_value=1; /* purecov: inspected */
3873
3847
return 0; /* purecov: inspected */
3876
return (longlong) (arg1 & arg2);
3850
return (int64_t) (arg1 & arg2);
3879
3853
Item_cond::Item_cond(THD *thd, Item_cond *item)
3899
Item_cond::fix_fields(THD *thd, Item **ref)
3873
Item_cond::fix_fields(THD *thd, Item **ref __attribute__((unused)))
3901
DBUG_ASSERT(fixed == 0);
3902
3876
List_iterator<Item> li(list);
3904
3878
void *orig_thd_marker= thd->thd_marker;
3905
uchar buff[sizeof(char*)]; // Max local vars in function
3879
unsigned char buff[sizeof(char*)]; // Max local vars in function
3906
3880
not_null_tables_cache= used_tables_cache= 0;
3907
3881
const_item_cache= 1;
4008
bool Item_cond::walk(Item_processor processor, bool walk_subquery, uchar *arg)
3982
bool Item_cond::walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
4010
3984
List_iterator_fast<Item> li(list);
4034
4008
Item returned as the result of transformation of the root node
4037
Item *Item_cond::transform(Item_transformer transformer, uchar *arg)
4011
Item *Item_cond::transform(Item_transformer transformer, unsigned char *arg)
4039
4013
List_iterator<Item> li(list);
4081
4055
Item returned as the result of transformation of the root node
4084
Item *Item_cond::compile(Item_analyzer analyzer, uchar **arg_p,
4085
Item_transformer transformer, uchar *arg_t)
4058
Item *Item_cond::compile(Item_analyzer analyzer, unsigned char **arg_p,
4059
Item_transformer transformer, unsigned char *arg_t)
4087
4061
if (!(this->*analyzer)(arg_p))
4095
4069
The same parameter value of arg_p must be passed
4096
4070
to analyze any argument of the condition formula.
4098
uchar *arg_v= *arg_p;
4072
unsigned char *arg_v= *arg_p;
4099
4073
Item *new_item= item->compile(analyzer, &arg_v, transformer, arg_t);
4100
4074
if (new_item && new_item != item)
4101
4075
li.replace(new_item);
4323
4297
return args[0]->is_null() ? 1: 0;
4326
longlong Item_is_not_null_test::val_int()
4300
int64_t Item_is_not_null_test::val_int()
4328
DBUG_ASSERT(fixed == 1);
4329
DBUG_ENTER("Item_is_not_null_test::val_int");
4330
4303
if (!used_tables_cache && !with_subselect)
4332
4305
owner->was_null|= (!cached_value);
4333
DBUG_PRINT("info", ("cached: %ld", (long) cached_value));
4334
DBUG_RETURN(cached_value);
4306
return(cached_value);
4336
4308
if (args[0]->is_null())
4338
DBUG_PRINT("info", ("null"));
4339
4310
owner->was_null|= 1;
4359
4330
if (!(used_tables_cache=args[0]->used_tables()) && !with_subselect)
4361
4332
/* Remember if the value is always NULL or never NULL */
4362
cached_value= (longlong) !args[0]->is_null();
4333
cached_value= (int64_t) !args[0]->is_null();
4368
longlong Item_func_isnotnull::val_int()
4339
int64_t Item_func_isnotnull::val_int()
4370
DBUG_ASSERT(fixed == 1);
4371
4342
return args[0]->is_null() ? 0 : 1;
4447
4418
String *escape_str= escape_item->val_str(&tmp_value1);
4448
4419
if (escape_str)
4450
if (escape_used_in_parsing && (
4451
(((thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) &&
4452
escape_str->numchars() != 1) ||
4453
escape_str->numchars() > 1)))
4421
if (escape_used_in_parsing && escape_str->numchars() > 1)
4455
4423
my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE");
4459
4427
if (use_mb(cmp.cmp_collation.collation))
4461
CHARSET_INFO *cs= escape_str->charset();
4429
const CHARSET_INFO * const cs= escape_str->charset();
4463
4431
int rc= cs->cset->mb_wc(cs, &wc,
4464
(const uchar*) escape_str->ptr(),
4465
(const uchar*) escape_str->ptr() +
4432
(const unsigned char*) escape_str->ptr(),
4433
(const unsigned char*) escape_str->ptr() +
4466
4434
escape_str->length());
4467
4435
escape= (int) (rc > 0 ? wc : '\\');
4473
4441
code instead of Unicode code as "escape" argument.
4474
4442
Convert to "cs" if charset of escape differs.
4476
CHARSET_INFO *cs= cmp.cmp_collation.collation;
4444
const CHARSET_INFO * const cs= cmp.cmp_collation.collation;
4478
4446
if (escape_str->needs_conversion(escape_str->length(),
4479
4447
escape_str->charset(), cs, &unused))
4483
uint32 cnvlen= copy_and_convert(&ch, 1, cs, escape_str->ptr(),
4451
uint32_t cnvlen= copy_and_convert(&ch, 1, cs, escape_str->ptr(),
4484
4452
escape_str->length(),
4485
4453
escape_str->charset(), &errors);
4486
4454
escape= cnvlen ? ch : '\\';
4496
4464
We could also do boyer-more for non-const items, but as we would have to
4497
4465
recompute the tables for each row it's not worth it.
4499
if (args[1]->const_item() && !use_strnxfrm(collation.collation) &&
4500
!(specialflag & SPECIAL_NO_NEW_FUNC))
4467
if (args[1]->const_item() && !use_strnxfrm(collation.collation))
4502
4469
String* res2 = args[1]->val_str(&tmp_value2);
4547
4512
#ifdef LIKE_CMP_TOUPPER
4548
#define likeconv(cs,A) (uchar) (cs)->toupper(A)
4513
#define likeconv(cs,A) (unsigned char) (cs)->toupper(A)
4550
#define likeconv(cs,A) (uchar) (cs)->sort_order[(uchar) (A)]
4515
#define likeconv(cs,A) (unsigned char) (cs)->sort_order[(unsigned char) (A)]
4661
4626
int *end = bmBc + alphabet_size;
4663
4628
const int plm1 = pattern_len - 1;
4664
CHARSET_INFO *cs= cmp.cmp_collation.collation;
4629
const CHARSET_INFO *const cs= cmp.cmp_collation.collation;
4666
4631
for (i = bmBc; i < end; i++)
4667
4632
*i = pattern_len;
4716
4681
register const int v = plm1 - i;
4717
4682
turboShift = u - v;
4718
bcShift = bmBc[(uint) (uchar) text[i + j]] - plm1 + i;
4719
shift = max(turboShift, bcShift);
4720
shift = max(shift, bmGs[i]);
4683
bcShift = bmBc[(uint) (unsigned char) text[i + j]] - plm1 + i;
4684
shift = (turboShift > bcShift) ? turboShift : bcShift;
4685
shift = (shift > bmGs[i]) ? shift : bmGs[i];
4721
4686
if (shift == bmGs[i])
4722
u = min(pattern_len - shift, v);
4687
u = (pattern_len - shift < v) ? pattern_len - shift : v;
4725
4690
if (turboShift < bcShift)
4726
shift = max(shift, u + 1);
4691
shift = cmax(shift, u + 1);
4747
4712
register const int v = plm1 - i;
4748
4713
turboShift = u - v;
4749
4714
bcShift = bmBc[(uint) likeconv(cs, text[i + j])] - plm1 + i;
4750
shift = max(turboShift, bcShift);
4751
shift = max(shift, bmGs[i]);
4715
shift = (turboShift > bcShift) ? turboShift : bcShift;
4716
shift = cmax(shift, bmGs[i]);
4752
4717
if (shift == bmGs[i])
4753
u = min(pattern_len - shift, v);
4718
u = (pattern_len - shift < v) ? pattern_len - shift : v;
4756
4721
if (turboShift < bcShift)
4757
shift = max(shift, u + 1);
4722
shift = cmax(shift, u + 1);
4825
4790
NULL if we cannot apply NOT transformation (see Item::neg_transformer()).
4828
Item *Item_func_not::neg_transformer(THD *thd) /* NOT(x) -> x */
4793
Item *Item_func_not::neg_transformer(THD *thd __attribute__((unused))) /* NOT(x) -> x */
4830
4795
return args[0];
4834
Item *Item_bool_rowready_func2::neg_transformer(THD *thd)
4799
Item *Item_bool_rowready_func2::neg_transformer(THD *thd __attribute__((unused)))
4836
4801
Item *item= negated_item();
5191
5156
item->collation.collation);
5194
bool Item_equal::walk(Item_processor processor, bool walk_subquery, uchar *arg)
5159
bool Item_equal::walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
5196
5161
List_iterator_fast<Item_field> it(fields);
5203
5168
return Item_func::walk(processor, walk_subquery, arg);
5206
Item *Item_equal::transform(Item_transformer transformer, uchar *arg)
5171
Item *Item_equal::transform(Item_transformer transformer, unsigned char *arg)
5208
5173
List_iterator<Item_field> it(fields);