~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cmpfunc.cc

  • Committer: Brian Aker
  • Date: 2010-12-25 00:28:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2031.
  • Revision ID: brian@tangent.org-20101225002849-g73mg6ihulajis0o
First pass in refactoring of the name of my_decimal.

Show diffs side-by-side

added added

removed removed

Lines of Context:
493
493
void Item_bool_func2::fix_length_and_dec()
494
494
{
495
495
  max_length= 1;                                     // Function returns 0 or 1
 
496
  Session *session;
496
497
 
497
498
  /*
498
499
    As some compare functions are generated after sql_yacc,
530
531
    return;
531
532
  }
532
533
 
 
534
  session= current_session;
533
535
  Item_field *field_item= NULL;
534
536
 
535
537
  if (args[0]->real_item()->type() == FIELD_ITEM)
538
540
    if (field_item->field->can_be_compared_as_int64_t() &&
539
541
        !(field_item->is_datetime() && args[1]->result_type() == STRING_RESULT))
540
542
    {
541
 
      if (convert_constant_item(&getSession(), field_item, &args[1]))
 
543
      if (convert_constant_item(session, field_item, &args[1]))
542
544
      {
543
545
        cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
544
546
                         INT_RESULT);           // Works for all types.
554
556
          !(field_item->is_datetime() &&
555
557
            args[0]->result_type() == STRING_RESULT))
556
558
      {
557
 
        if (convert_constant_item(&getSession(), field_item, &args[0]))
 
559
        if (convert_constant_item(session, field_item, &args[0]))
558
560
        {
559
561
          cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
560
562
                           INT_RESULT); // Works for all types.
694
696
    converted value. 0 on error and on zero-dates -- check 'failure'
695
697
*/
696
698
 
697
 
static int64_t
698
 
get_date_from_str(Session *session, String *str, type::timestamp_t warn_type,
 
699
static uint64_t
 
700
get_date_from_str(Session *session, String *str, enum enum_drizzle_timestamp_type warn_type,
699
701
                  char *warn_name, bool *error_arg)
700
702
{
701
 
  int64_t value= 0;
702
 
  type::cut_t error= type::VALID;
703
 
  type::Time l_time;
704
 
  type::timestamp_t ret;
705
 
 
706
 
  ret= l_time.store(str->ptr(), str->length(),
707
 
                    (TIME_FUZZY_DATE | MODE_INVALID_DATES | (session->variables.sql_mode & MODE_NO_ZERO_DATE)),
708
 
                    error);
709
 
 
710
 
  if (ret == type::DRIZZLE_TIMESTAMP_DATETIME || ret == type::DRIZZLE_TIMESTAMP_DATE)
 
703
  uint64_t value= 0;
 
704
  int error;
 
705
  DRIZZLE_TIME l_time;
 
706
  enum enum_drizzle_timestamp_type ret;
 
707
 
 
708
  ret= str_to_datetime(str->ptr(), str->length(), &l_time,
 
709
                       (TIME_FUZZY_DATE | MODE_INVALID_DATES |
 
710
                        (session->variables.sql_mode & MODE_NO_ZERO_DATE)),
 
711
                       &error);
 
712
 
 
713
  if (ret == DRIZZLE_TIMESTAMP_DATETIME || ret == DRIZZLE_TIMESTAMP_DATE)
711
714
  {
712
715
    /*
713
716
      Do not return yet, we may still want to throw a "trailing garbage"
714
717
      warning.
715
718
    */
716
719
    *error_arg= false;
717
 
    l_time.convert(value);
 
720
    value= TIME_to_uint64_t_datetime(&l_time);
718
721
  }
719
722
  else
720
723
  {
721
724
    *error_arg= true;
722
 
    error= type::CUT;                                   /* force warning */
 
725
    error= 1;                                   /* force warning */
723
726
  }
724
727
 
725
 
  if (error != type::VALID)
 
728
  if (error > 0)
726
729
  {
727
730
    make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
728
731
                                 str->ptr(), str->length(),
767
770
 
768
771
enum Arg_comparator::enum_date_cmp_type
769
772
Arg_comparator::can_compare_as_dates(Item *in_a, Item *in_b,
770
 
                                     int64_t *const_value)
 
773
                                     uint64_t *const_value)
771
774
{
772
775
  enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
773
776
  Item *str_arg= 0, *date_arg= 0;
778
781
  if (in_a->is_datetime())
779
782
  {
780
783
    if (in_b->is_datetime())
781
 
    {
782
784
      cmp_type= CMP_DATE_WITH_DATE;
783
 
    }
784
785
    else if (in_b->result_type() == STRING_RESULT)
785
786
    {
786
787
      cmp_type= CMP_DATE_WITH_STR;
822
823
       * Does a uint64_t conversion really have to happen here?  Fields return int64_t
823
824
       * from val_int(), not uint64_t...
824
825
       */
825
 
      int64_t value;
 
826
      uint64_t value;
826
827
      String *str_val;
827
828
      String tmp;
828
829
      /* DateTime used to pick up as many string conversion possibilities as possible. */
848
849
      }
849
850
 
850
851
      /* String conversion was good.  Convert to an integer for comparison purposes. */
851
 
      temporal.to_int64_t(&value);
 
852
      int64_t int_value;
 
853
      temporal.to_int64_t(&int_value);
 
854
      value= (uint64_t) int_value;
852
855
 
853
856
      if (const_value)
854
857
        *const_value= value;
862
865
                                        Item **a1, Item **a2,
863
866
                                        Item_result type)
864
867
{
865
 
  enum_date_cmp_type cmp_type;
866
 
  int64_t const_value= -1;
 
868
  enum enum_date_cmp_type cmp_type;
 
869
  uint64_t const_value= (uint64_t)-1;
867
870
  a= a1;
868
871
  b= a2;
869
872
 
870
873
  if ((cmp_type= can_compare_as_dates(*a, *b, &const_value)))
871
874
  {
 
875
    session= current_session;
872
876
    owner= owner_arg;
873
877
    a_type= (*a)->field_type();
874
878
    b_type= (*b)->field_type();
875
879
    a_cache= 0;
876
880
    b_cache= 0;
877
881
 
878
 
    if (const_value != -1)
 
882
    if (const_value != (uint64_t)-1)
879
883
    {
880
884
      Item_cache_int *cache= new Item_cache_int();
881
885
      /* Mark the cache as non-const to prevent re-caching. */
896
900
    is_nulls_eq= test(owner && owner->functype() == Item_func::EQUAL_FUNC);
897
901
    func= &Arg_comparator::compare_datetime;
898
902
    get_value_func= &get_datetime_value;
899
 
 
900
903
    return 0;
901
904
  }
902
905
 
906
909
 
907
910
void Arg_comparator::set_datetime_cmp_func(Item **a1, Item **b1)
908
911
{
 
912
  session= current_session;
909
913
  /* A caller will handle null values by itself. */
910
914
  owner= NULL;
911
915
  a= a1;
949
953
    obtained value
950
954
*/
951
955
 
952
 
int64_t
 
956
uint64_t
953
957
get_datetime_value(Session *session, Item ***item_arg, Item **cache_arg,
954
958
                   Item *warn_item, bool *is_null)
955
959
{
956
 
  int64_t value= 0;
 
960
  uint64_t value= 0;
957
961
  String buf, *str= 0;
958
962
  Item *item= **item_arg;
959
963
 
977
981
    str= item->val_str(&buf);
978
982
    *is_null= item->null_value;
979
983
  }
980
 
 
981
984
  if (*is_null)
982
985
    return ~(uint64_t) 0;
983
 
 
984
986
  /*
985
987
    Convert strings to the integer DATE/DATETIME representation.
986
988
    Even if both dates provided in strings we can't compare them directly as
991
993
  {
992
994
    bool error;
993
995
    enum_field_types f_type= warn_item->field_type();
994
 
    type::timestamp_t t_type= f_type == DRIZZLE_TYPE_DATE ? type::DRIZZLE_TIMESTAMP_DATE : type::DRIZZLE_TIMESTAMP_DATETIME;
 
996
    enum enum_drizzle_timestamp_type t_type= f_type ==
 
997
      DRIZZLE_TYPE_DATE ? DRIZZLE_TIMESTAMP_DATE : DRIZZLE_TIMESTAMP_DATETIME;
995
998
    value= get_date_from_str(session, str, t_type, warn_item->name, &error);
996
999
    /*
997
1000
      If str did not contain a valid date according to the current
1014
1017
    *cache_arg= cache;
1015
1018
    *item_arg= cache_arg;
1016
1019
  }
1017
 
 
1018
1020
  return value;
1019
1021
}
1020
1022
 
1171
1173
 
1172
1174
int Arg_comparator::compare_decimal()
1173
1175
{
1174
 
  type::Decimal value1;
1175
 
  type::Decimal *val1= (*a)->val_decimal(&value1);
 
1176
  my_decimal value1;
 
1177
  my_decimal *val1= (*a)->val_decimal(&value1);
1176
1178
  if (!(*a)->null_value)
1177
1179
  {
1178
 
    type::Decimal value2;
1179
 
    type::Decimal *val2= (*b)->val_decimal(&value2);
 
1180
    my_decimal value2;
 
1181
    my_decimal *val2= (*b)->val_decimal(&value2);
1180
1182
    if (!(*b)->null_value)
1181
1183
    {
1182
1184
      owner->null_value= 0;
1198
1200
 
1199
1201
int Arg_comparator::compare_e_decimal()
1200
1202
{
1201
 
  type::Decimal value1, value2;
1202
 
  type::Decimal *val1= (*a)->val_decimal(&value1);
1203
 
  type::Decimal *val2= (*b)->val_decimal(&value2);
 
1203
  my_decimal value1, value2;
 
1204
  my_decimal *val1= (*a)->val_decimal(&value1);
 
1205
  my_decimal *val2= (*b)->val_decimal(&value2);
1204
1206
  if ((*a)->null_value || (*b)->null_value)
1205
1207
    return test((*a)->null_value && (*b)->null_value);
1206
1208
  return test(class_decimal_cmp(val1, val2) == 0);
1613
1615
 
1614
1616
void Item_in_optimizer::cleanup()
1615
1617
{
1616
 
  item::function::Boolean::cleanup();
 
1618
  Item_bool_func::cleanup();
1617
1619
  if (!save_cache)
1618
1620
    cache= 0;
1619
1621
  return;
1666
1668
    change records at each execution.
1667
1669
  */
1668
1670
  if ((*args) != new_item)
1669
 
    getSession().change_item_tree(args, new_item);
 
1671
    current_session->change_item_tree(args, new_item);
1670
1672
 
1671
1673
  /*
1672
1674
    Transform the right IN operand which should be an Item_in_subselect or a
1821
1823
          {
1822
1824
            range->type= DECIMAL_RESULT;
1823
1825
            range->dec.init();
1824
 
            type::Decimal *dec= el->val_decimal(&range->dec);
 
1826
            my_decimal *dec= el->val_decimal(&range->dec);
1825
1827
            if (dec != &range->dec)
1826
1828
            {
1827
1829
              range->dec= *dec;
1871
1873
{
1872
1874
  assert(fixed == 1);
1873
1875
  double value;
1874
 
  type::Decimal dec_buf, *dec= NULL;
 
1876
  my_decimal dec_buf, *dec= NULL;
1875
1877
  uint32_t i;
1876
1878
 
1877
1879
  if (use_decimal_comparison)
1879
1881
    dec= row->element_index(0)->val_decimal(&dec_buf);
1880
1882
    if (row->element_index(0)->null_value)
1881
1883
      return -1;
1882
 
    class_decimal2double(E_DEC_FATAL_ERROR, dec, &value);
 
1884
    my_decimal2double(E_DEC_FATAL_ERROR, dec, &value);
1883
1885
  }
1884
1886
  else
1885
1887
  {
1925
1927
        ((el->result_type() == DECIMAL_RESULT) ||
1926
1928
         (el->result_type() == INT_RESULT)))
1927
1929
    {
1928
 
      type::Decimal e_dec_buf, *e_dec= el->val_decimal(&e_dec_buf);
 
1930
      my_decimal e_dec_buf, *e_dec= el->val_decimal(&e_dec_buf);
1929
1931
      /* Skip NULL ranges. */
1930
1932
      if (el->null_value)
1931
1933
        continue;
2000
2002
  int i;
2001
2003
  bool datetime_found= false;
2002
2004
  compare_as_dates= true;
 
2005
  Session *session= current_session;
2003
2006
 
2004
2007
  /*
2005
2008
    As some compare functions are generated after sql_yacc,
2046
2049
        The following can't be recoded with || as convert_constant_item
2047
2050
        changes the argument
2048
2051
      */
2049
 
      if (convert_constant_item(&getSession(), field_item, &args[1]))
 
2052
      if (convert_constant_item(session, field_item, &args[1]))
2050
2053
        cmp_type=INT_RESULT;                    // Works for all types.
2051
 
      if (convert_constant_item(&getSession(), field_item, &args[2]))
 
2054
      if (convert_constant_item(session, field_item, &args[2]))
2052
2055
        cmp_type=INT_RESULT;                    // Works for all types.
2053
2056
    }
2054
2057
  }
2125
2128
  }
2126
2129
  else if (cmp_type == DECIMAL_RESULT)
2127
2130
  {
2128
 
    type::Decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
 
2131
    my_decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
2129
2132
               a_buf, *a_dec, b_buf, *b_dec;
2130
2133
    if ((null_value=args[0]->null_value))
2131
2134
      return 0;
2273
2276
}
2274
2277
 
2275
2278
 
2276
 
type::Decimal *Item_func_ifnull::decimal_op(type::Decimal *decimal_value)
 
2279
my_decimal *Item_func_ifnull::decimal_op(my_decimal *decimal_value)
2277
2280
{
2278
2281
  assert(fixed == 1);
2279
 
  type::Decimal *value= args[0]->val_decimal(decimal_value);
 
2282
  my_decimal *value= args[0]->val_decimal(decimal_value);
2280
2283
  if (!args[0]->null_value)
2281
2284
  {
2282
2285
    null_value= 0;
2446
2449
}
2447
2450
 
2448
2451
 
2449
 
type::Decimal *
2450
 
Item_func_if::val_decimal(type::Decimal *decimal_value)
 
2452
my_decimal *
 
2453
Item_func_if::val_decimal(my_decimal *decimal_value)
2451
2454
{
2452
2455
  assert(fixed == 1);
2453
2456
  Item *arg= args[0]->val_bool() ? args[1] : args[2];
2454
 
  type::Decimal *value= arg->val_decimal(decimal_value);
 
2457
  my_decimal *value= arg->val_decimal(decimal_value);
2455
2458
  null_value= arg->null_value;
2456
2459
  return value;
2457
2460
}
2531
2534
}
2532
2535
 
2533
2536
 
2534
 
type::Decimal *
2535
 
Item_func_nullif::val_decimal(type::Decimal * decimal_value)
 
2537
my_decimal *
 
2538
Item_func_nullif::val_decimal(my_decimal * decimal_value)
2536
2539
{
2537
2540
  assert(fixed == 1);
2538
 
  type::Decimal *res;
 
2541
  my_decimal *res;
2539
2542
  if (!cmp.compare())
2540
2543
  {
2541
2544
    null_value=1;
2668
2671
}
2669
2672
 
2670
2673
 
2671
 
type::Decimal *Item_func_case::val_decimal(type::Decimal *decimal_value)
 
2674
my_decimal *Item_func_case::val_decimal(my_decimal *decimal_value)
2672
2675
{
2673
2676
  assert(fixed == 1);
2674
2677
  char buff[MAX_FIELD_WIDTH];
2675
2678
  String dummy_str(buff, sizeof(buff), default_charset());
2676
2679
  Item *item= find_item(&dummy_str);
2677
 
  type::Decimal *res;
 
2680
  my_decimal *res;
2678
2681
 
2679
2682
  if (!item)
2680
2683
  {
2907
2910
}
2908
2911
 
2909
2912
 
2910
 
type::Decimal *Item_func_coalesce::decimal_op(type::Decimal *decimal_value)
 
2913
my_decimal *Item_func_coalesce::decimal_op(my_decimal *decimal_value)
2911
2914
{
2912
2915
  assert(fixed == 1);
2913
2916
  null_value= 0;
2914
2917
  for (uint32_t i= 0; i < arg_count; i++)
2915
2918
  {
2916
 
    type::Decimal *res= args[i]->val_decimal(decimal_value);
 
2919
    my_decimal *res= args[i]->val_decimal(decimal_value);
2917
2920
    if (!args[i]->null_value)
2918
2921
      return res;
2919
2922
  }
3062
3065
}
3063
3066
 
3064
3067
 
3065
 
static int cmp_decimal(void *, type::Decimal *a, type::Decimal *b)
 
3068
static int cmp_decimal(void *, my_decimal *a, my_decimal *b)
3066
3069
{
3067
3070
  /*
3068
3071
    We need call of fixing buffer pointer, because fast sort just copy
3178
3181
  return;
3179
3182
}
3180
3183
 
3181
 
in_int64_t::in_int64_t(uint32_t elements) :
3182
 
  in_vector(elements, sizeof(packed_int64_t),(qsort2_cmp) cmp_int64_t, 0)
 
3184
in_int64_t::in_int64_t(uint32_t elements)
 
3185
  :in_vector(elements,sizeof(packed_int64_t),(qsort2_cmp) cmp_int64_t, 0)
3183
3186
{}
3184
3187
 
3185
3188
void in_int64_t::set(uint32_t pos,Item *item)
3199
3202
  return (unsigned char*) &tmp;
3200
3203
}
3201
3204
 
3202
 
void in_datetime::set(uint32_t pos, Item *item)
 
3205
void in_datetime::set(uint32_t pos,Item *item)
3203
3206
{
3204
3207
  Item **tmp_item= &item;
3205
3208
  bool is_null;
3239
3242
 
3240
3243
 
3241
3244
in_decimal::in_decimal(uint32_t elements)
3242
 
  :in_vector(elements, sizeof(type::Decimal),(qsort2_cmp) cmp_decimal, 0)
 
3245
  :in_vector(elements, sizeof(my_decimal),(qsort2_cmp) cmp_decimal, 0)
3243
3246
{}
3244
3247
 
3245
3248
 
3246
3249
void in_decimal::set(uint32_t pos, Item *item)
3247
3250
{
3248
 
  /* as far as 'item' is constant, we can store reference on type::Decimal */
3249
 
  type::Decimal *dec= ((type::Decimal *)base) + pos;
 
3251
  /* as far as 'item' is constant, we can store reference on my_decimal */
 
3252
  my_decimal *dec= ((my_decimal *)base) + pos;
3250
3253
  dec->len= DECIMAL_BUFF_LENGTH;
3251
3254
  dec->fix_buffer_pointer();
3252
 
  type::Decimal *res= item->val_decimal(dec);
 
3255
  my_decimal *res= item->val_decimal(dec);
3253
3256
  /* if item->val_decimal() is evaluated to NULL then res == 0 */
3254
3257
  if (!item->null_value && res != dec)
3255
 
    class_decimal2decimal(res, dec);
 
3258
    my_decimal2decimal(res, dec);
3256
3259
}
3257
3260
 
3258
3261
 
3259
3262
unsigned char *in_decimal::get_value(Item *item)
3260
3263
{
3261
 
  type::Decimal *result= item->val_decimal(&val);
 
3264
  my_decimal *result= item->val_decimal(&val);
3262
3265
  if (item->null_value)
3263
3266
    return 0;
3264
3267
  return (unsigned char *)result;
3417
3420
 
3418
3421
void cmp_item_decimal::store_value(Item *item)
3419
3422
{
3420
 
  type::Decimal *val= item->val_decimal(&value);
 
3423
  my_decimal *val= item->val_decimal(&value);
3421
3424
  /* val may be zero if item is nnull */
3422
3425
  if (val && val != &value)
3423
 
    class_decimal2decimal(val, &value);
 
3426
    my_decimal2decimal(val, &value);
3424
3427
}
3425
3428
 
3426
3429
 
3427
3430
int cmp_item_decimal::cmp(Item *arg)
3428
3431
{
3429
 
  type::Decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
 
3432
  my_decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
3430
3433
  if (arg->null_value)
3431
3434
    return 1;
3432
3435
  return class_decimal_cmp(&value, tmp);
3549
3552
{
3550
3553
  Item **arg, **arg_end;
3551
3554
  bool const_itm= 1;
 
3555
  Session *session= current_session;
3552
3556
  bool datetime_found= false;
3553
3557
  /* true <=> arguments values will be compared as DATETIMEs. */
3554
3558
  bool compare_as_datetime= false;
3696
3700
          bool all_converted= true;
3697
3701
          for (arg=args+1, arg_end=args+arg_count; arg != arg_end ; arg++)
3698
3702
          {
3699
 
            if (!convert_constant_item (&getSession(), field_item, &arg[0]))
 
3703
            if (!convert_constant_item (session, field_item, &arg[0]))
3700
3704
              all_converted= false;
3701
3705
          }
3702
3706
          if (all_converted)
3733
3737
      }
3734
3738
    }
3735
3739
 
3736
 
    if (array && !(getSession().is_fatal_error))                // If not EOM
 
3740
    if (array && !(session->is_fatal_error))            // If not EOM
3737
3741
    {
3738
3742
      uint32_t j=0;
3739
3743
      for (uint32_t arg_num=1 ; arg_num < arg_count ; arg_num++)
3849
3853
 
3850
3854
 
3851
3855
Item_cond::Item_cond(Session *session, Item_cond *item)
3852
 
  :item::function::Boolean(session, item),
 
3856
  :Item_bool_func(session, item),
3853
3857
   abort_on_null(item->abort_on_null),
3854
3858
   and_tables_cache(item->and_tables_cache)
3855
3859
{
3876
3880
  void *orig_session_marker= session->session_marker;
3877
3881
  unsigned char buff[sizeof(char*)];                    // Max local vars in function
3878
3882
  not_null_tables_cache= used_tables_cache= 0;
3879
 
  const_item_cache= true;
 
3883
  const_item_cache= 1;
3880
3884
 
3881
3885
  if (functype() == COND_OR_FUNC)
3882
3886
    session->session_marker= 0;
3951
3955
  Item *item;
3952
3956
 
3953
3957
  used_tables_cache=0;
3954
 
  const_item_cache= true;
 
3958
  const_item_cache=1;
3955
3959
 
3956
3960
  and_tables_cache= ~(table_map) 0; // Here and below we do as fix_fields does
3957
3961
  not_null_tables_cache= 0;
4023
4027
      change records at each execution.
4024
4028
    */
4025
4029
    if (new_item != item)
4026
 
      getSession().change_item_tree(li.ref(), new_item);
 
4030
      current_session->change_item_tree(li.ref(), new_item);
4027
4031
  }
4028
4032
  return Item_func::transform(transformer, arg);
4029
4033
}
4140
4144
  Item *item;
4141
4145
 
4142
4146
  used_tables_cache=0;
4143
 
  const_item_cache= true;
 
4147
  const_item_cache=1;
4144
4148
  while ((item=li++))
4145
4149
  {
4146
4150
    item->update_used_tables();
4463
4467
      {
4464
4468
        pattern     = first + 1;
4465
4469
        pattern_len = (int) len - 2;
4466
 
        int *suff = (int*) session->getMemRoot()->allocate((int) (sizeof(int)*
4467
 
                                                                  ((pattern_len + 1)*2+
4468
 
                                                                   alphabet_size)));
 
4470
        int *suff = (int*) session->alloc((int) (sizeof(int)*
 
4471
                                      ((pattern_len + 1)*2+
 
4472
                                      alphabet_size)));
4469
4473
        bmGs      = suff + pattern_len + 1;
4470
4474
        bmBc      = bmGs + pattern_len + 1;
4471
4475
        turboBM_compute_good_suffix_shifts(suff);
4482
4486
  Item_bool_func2::cleanup();
4483
4487
}
4484
4488
 
4485
 
static unsigned char likeconv(const CHARSET_INFO *cs, unsigned char a)
4486
 
{
4487
4489
#ifdef LIKE_CMP_TOUPPER
4488
 
  return cs->toupper(a);
 
4490
#define likeconv(cs,A) (unsigned char) (cs)->toupper(A)
4489
4491
#else
4490
 
  return cs->sort_order[a];
 
4492
#define likeconv(cs,A) (unsigned char) (cs)->sort_order[(unsigned char) (A)]
4491
4493
#endif
4492
 
}
 
4494
 
4493
4495
 
4494
4496
/**
4495
4497
  Precomputation dependent only on pattern_len.
4884
4886
}
4885
4887
 
4886
4888
Item_equal::Item_equal(Item_field *f1, Item_field *f2)
4887
 
  : item::function::Boolean(), const_item(0), eval_item(0), cond_false(0)
 
4889
  : Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
4888
4890
{
4889
 
  const_item_cache= false;
 
4891
  const_item_cache= 0;
4890
4892
  fields.push_back(f1);
4891
4893
  fields.push_back(f2);
4892
4894
}
4893
4895
 
4894
4896
Item_equal::Item_equal(Item *c, Item_field *f)
4895
 
  : item::function::Boolean(), eval_item(0), cond_false(0)
 
4897
  : Item_bool_func(), eval_item(0), cond_false(0)
4896
4898
{
4897
 
  const_item_cache= false;
 
4899
  const_item_cache= 0;
4898
4900
  fields.push_back(f);
4899
4901
  const_item= c;
4900
4902
}
4901
4903
 
4902
4904
 
4903
4905
Item_equal::Item_equal(Item_equal *item_equal)
4904
 
  : item::function::Boolean(), eval_item(0), cond_false(0)
 
4906
  : Item_bool_func(), eval_item(0), cond_false(0)
4905
4907
{
4906
 
  const_item_cache= false;
 
4908
  const_item_cache= 0;
4907
4909
  List_iterator_fast<Item_field> li(item_equal->fields);
4908
4910
  Item_field *item;
4909
4911
  while ((item= li++))
4927
4929
  func->set_cmp_func();
4928
4930
  func->quick_fix_field();
4929
4931
  if ((cond_false= !func->val_int()))
4930
 
    const_item_cache= true;
 
4932
    const_item_cache= 1;
4931
4933
}
4932
4934
 
4933
4935
void Item_equal::add(Item_field *f)
5073
5075
  List_iterator_fast<Item_field> li(fields);
5074
5076
  Item *item;
5075
5077
  not_null_tables_cache= used_tables_cache= 0;
5076
 
  const_item_cache= false;
 
5078
  const_item_cache= 0;
5077
5079
  while ((item= li++))
5078
5080
  {
5079
5081
    table_map tmp_table_map;
5110
5112
    return 0;
5111
5113
  List_iterator_fast<Item_field> it(fields);
5112
5114
  Item *item= const_item ? const_item : it++;
 
5115
  if ((null_value= item->null_value))
 
5116
    return 0;
5113
5117
  eval_item->store_value(item);
5114
 
  if ((null_value= item->null_value))
5115
 
    return 0;
5116
5118
  while ((item_field= it++))
5117
5119
  {
5118
5120
    /* Skip fields of non-const tables. They haven't been read yet */
5119
5121
    if (item_field->field->getTable()->const_table)
5120
5122
    {
5121
 
      if (eval_item->cmp(item_field) || (null_value= item_field->null_value))
 
5123
      if ((null_value= item_field->null_value) || eval_item->cmp(item_field))
5122
5124
        return 0;
5123
5125
    }
5124
5126
  }
5161
5163
      change records at each execution.
5162
5164
    */
5163
5165
    if (new_item != item)
5164
 
      getSession().change_item_tree((Item **) it.ref(), new_item);
 
5166
      current_session->change_item_tree((Item **) it.ref(), new_item);
5165
5167
  }
5166
5168
  return Item_func::transform(transformer, arg);
5167
5169
}