~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cmpfunc.cc

  • Committer: Olaf van der Spek
  • Date: 2011-02-12 18:24:24 UTC
  • mto: (2167.1.2 build) (2172.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 2168.
  • Revision ID: olafvdspek@gmail.com-20110212182424-kgnm9osi7qo97at2
casts

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
16
 
17
17
/**
463
463
      the call to save_in_field below overrides that value.
464
464
    */
465
465
    if (field_item->depended_from)
 
466
    {
466
467
      orig_field_val= field->val_int();
 
468
    }
 
469
 
467
470
    if (!(*item)->is_null() && !(*item)->save_in_field(field, 1))
468
471
    {
469
472
      Item *tmp= new Item_int_with_ref(field->val_int(), *item,
472
475
        session->change_item_tree(item, tmp);
473
476
      result= 1;                                        // Item was replaced
474
477
    }
 
478
 
475
479
    /* Restore the original field value. */
476
480
    if (field_item->depended_from)
477
481
    {
478
 
      result= field->store(orig_field_val, true);
 
482
      result= field->store(orig_field_val, field->isUnsigned());
479
483
      /* orig_field_val must be a valid value that can be restored back. */
480
484
      assert(!result);
481
485
    }
489
493
void Item_bool_func2::fix_length_and_dec()
490
494
{
491
495
  max_length= 1;                                     // Function returns 0 or 1
492
 
  Session *session;
493
496
 
494
497
  /*
495
498
    As some compare functions are generated after sql_yacc,
527
530
    return;
528
531
  }
529
532
 
530
 
  session= current_session;
531
533
  Item_field *field_item= NULL;
532
534
 
533
535
  if (args[0]->real_item()->type() == FIELD_ITEM)
536
538
    if (field_item->field->can_be_compared_as_int64_t() &&
537
539
        !(field_item->is_datetime() && args[1]->result_type() == STRING_RESULT))
538
540
    {
539
 
      if (convert_constant_item(session, field_item, &args[1]))
 
541
      if (convert_constant_item(&getSession(), field_item, &args[1]))
540
542
      {
541
543
        cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
542
544
                         INT_RESULT);           // Works for all types.
552
554
          !(field_item->is_datetime() &&
553
555
            args[0]->result_type() == STRING_RESULT))
554
556
      {
555
 
        if (convert_constant_item(session, field_item, &args[0]))
 
557
        if (convert_constant_item(&getSession(), field_item, &args[0]))
556
558
        {
557
559
          cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
558
560
                           INT_RESULT); // Works for all types.
570
572
{
571
573
  owner= item;
572
574
  func= comparator_matrix[type]
573
 
                         [test(owner->functype() == Item_func::EQUAL_FUNC)];
 
575
    [test(owner->functype() == Item_func::EQUAL_FUNC)];
 
576
 
574
577
  switch (type) {
575
578
  case ROW_RESULT:
576
 
  {
577
 
    uint32_t n= (*a)->cols();
578
 
    if (n != (*b)->cols())
579
 
    {
580
 
      my_error(ER_OPERAND_COLUMNS, MYF(0), n);
581
 
      comparators= 0;
582
 
      return 1;
583
 
    }
584
 
    if (!(comparators= new Arg_comparator[n]))
585
 
      return 1;
586
 
    for (uint32_t i=0; i < n; i++)
587
 
    {
588
 
      if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
589
 
      {
590
 
        my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols());
591
 
        return 1;
592
 
      }
593
 
      comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
594
 
    }
595
 
    break;
596
 
  }
 
579
    {
 
580
      uint32_t n= (*a)->cols();
 
581
      if (n != (*b)->cols())
 
582
      {
 
583
        my_error(ER_OPERAND_COLUMNS, MYF(0), n);
 
584
        comparators= 0;
 
585
        return 1;
 
586
      }
 
587
      if (!(comparators= new Arg_comparator[n]))
 
588
        return 1;
 
589
      for (uint32_t i=0; i < n; i++)
 
590
      {
 
591
        if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
 
592
        {
 
593
          my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols());
 
594
          return 1;
 
595
        }
 
596
        comparators[i].set_cmp_func(owner, (*a)->addr(i), (*b)->addr(i));
 
597
      }
 
598
      break;
 
599
    }
 
600
 
597
601
  case STRING_RESULT:
598
 
  {
599
 
    /*
600
 
      We must set cmp_charset here as we may be called from for an automatic
601
 
      generated item, like in natural join
602
 
    */
603
 
    if (cmp_collation.set((*a)->collation, (*b)->collation) ||
604
 
        cmp_collation.derivation == DERIVATION_NONE)
605
 
    {
606
 
      my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
607
 
      return 1;
608
 
    }
609
 
    if (cmp_collation.collation == &my_charset_bin)
610
602
    {
611
603
      /*
612
 
        We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
613
 
        without removing end space
 
604
        We must set cmp_charset here as we may be called from for an automatic
 
605
        generated item, like in natural join
614
606
      */
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;
 
607
      if (cmp_collation.set((*a)->collation, (*b)->collation) ||
 
608
          cmp_collation.derivation == DERIVATION_NONE)
 
609
      {
 
610
        my_coll_agg_error((*a)->collation, (*b)->collation, owner->func_name());
 
611
        return 1;
 
612
      }
 
613
      if (cmp_collation.collation == &my_charset_bin)
 
614
      {
 
615
        /*
 
616
          We are using BLOB/BINARY/VARBINARY, change to compare byte by byte,
 
617
          without removing end space
 
618
        */
 
619
        if (func == &Arg_comparator::compare_string)
 
620
          func= &Arg_comparator::compare_binary_string;
 
621
        else if (func == &Arg_comparator::compare_e_string)
 
622
          func= &Arg_comparator::compare_e_binary_string;
619
623
 
620
 
      /*
621
 
        As this is binary compassion, mark all fields that they can't be
622
 
        transformed. Otherwise we would get into trouble with comparisons
623
 
        like:
624
 
        WHERE col= 'j' AND col LIKE BINARY 'j'
625
 
        which would be transformed to:
626
 
        WHERE col= 'j'
 
624
        /*
 
625
          As this is binary compassion, mark all fields that they can't be
 
626
          transformed. Otherwise we would get into trouble with comparisons
 
627
like:
 
628
WHERE col= 'j' AND col LIKE BINARY 'j'
 
629
which would be transformed to:
 
630
WHERE col= 'j'
627
631
      */
628
 
      (*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
629
 
      (*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
 
632
        (*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
 
633
        (*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
 
634
      }
 
635
      break;
630
636
    }
631
 
    break;
632
 
  }
633
637
  case INT_RESULT:
634
 
  {
635
 
    if (func == &Arg_comparator::compare_int_signed)
636
 
    {
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;
643
 
    }
644
 
    else if (func== &Arg_comparator::compare_e_int)
645
 
    {
646
 
      if ((*a)->unsigned_flag ^ (*b)->unsigned_flag)
647
 
        func= &Arg_comparator::compare_e_int_diff_signedness;
648
 
    }
649
 
    break;
650
 
  }
 
638
    {
 
639
      if (func == &Arg_comparator::compare_int_signed)
 
640
      {
 
641
        if ((*a)->unsigned_flag)
 
642
          func= (((*b)->unsigned_flag)?
 
643
                 &Arg_comparator::compare_int_unsigned :
 
644
                 &Arg_comparator::compare_int_unsigned_signed);
 
645
        else if ((*b)->unsigned_flag)
 
646
          func= &Arg_comparator::compare_int_signed_unsigned;
 
647
      }
 
648
      else if (func== &Arg_comparator::compare_e_int)
 
649
      {
 
650
        if ((*a)->unsigned_flag ^ (*b)->unsigned_flag)
 
651
          func= &Arg_comparator::compare_e_int_diff_signedness;
 
652
      }
 
653
      break;
 
654
    }
651
655
  case DECIMAL_RESULT:
652
656
    break;
653
657
  case REAL_RESULT:
654
 
  {
655
 
    if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
656
658
    {
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;
 
659
      if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
 
660
      {
 
661
        precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
 
662
        if (func == &Arg_comparator::compare_real)
 
663
          func= &Arg_comparator::compare_real_fixed;
 
664
        else if (func == &Arg_comparator::compare_e_real)
 
665
          func= &Arg_comparator::compare_e_real_fixed;
 
666
      }
 
667
      break;
662
668
    }
663
 
    break;
664
 
  }
665
 
  default:
666
 
    assert(0);
667
 
  }
 
669
  }
 
670
 
668
671
  return 0;
669
672
}
670
673
 
691
694
    converted value. 0 on error and on zero-dates -- check 'failure'
692
695
*/
693
696
 
694
 
static uint64_t
695
 
get_date_from_str(Session *session, String *str, enum enum_drizzle_timestamp_type warn_type,
 
697
static int64_t
 
698
get_date_from_str(Session *session, String *str, type::timestamp_t warn_type,
696
699
                  char *warn_name, bool *error_arg)
697
700
{
698
 
  uint64_t value= 0;
699
 
  int error;
700
 
  DRIZZLE_TIME l_time;
701
 
  enum enum_drizzle_timestamp_type ret;
702
 
 
703
 
  ret= str_to_datetime(str->ptr(), str->length(), &l_time,
704
 
                       (TIME_FUZZY_DATE | MODE_INVALID_DATES |
705
 
                        (session->variables.sql_mode & MODE_NO_ZERO_DATE)),
706
 
                       &error);
707
 
 
708
 
  if (ret == DRIZZLE_TIMESTAMP_DATETIME || ret == DRIZZLE_TIMESTAMP_DATE)
 
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)
709
711
  {
710
712
    /*
711
713
      Do not return yet, we may still want to throw a "trailing garbage"
712
714
      warning.
713
715
    */
714
716
    *error_arg= false;
715
 
    value= TIME_to_uint64_t_datetime(&l_time);
 
717
    l_time.convert(value);
716
718
  }
717
719
  else
718
720
  {
719
721
    *error_arg= true;
720
 
    error= 1;                                   /* force warning */
 
722
    error= type::CUT;                                   /* force warning */
721
723
  }
722
724
 
723
 
  if (error > 0)
 
725
  if (error != type::VALID)
 
726
  {
724
727
    make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
725
728
                                 str->ptr(), str->length(),
726
729
                                 warn_type, warn_name);
 
730
  }
727
731
 
728
732
  return value;
729
733
}
762
766
*/
763
767
 
764
768
enum Arg_comparator::enum_date_cmp_type
765
 
Arg_comparator::can_compare_as_dates(Item *a, Item *b, uint64_t *const_value)
 
769
Arg_comparator::can_compare_as_dates(Item *in_a, Item *in_b,
 
770
                                     int64_t *const_value)
766
771
{
767
772
  enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
768
773
  Item *str_arg= 0, *date_arg= 0;
769
774
 
770
 
  if (a->type() == Item::ROW_ITEM || b->type() == Item::ROW_ITEM)
 
775
  if (in_a->type() == Item::ROW_ITEM || in_b->type() == Item::ROW_ITEM)
771
776
    return CMP_DATE_DFLT;
772
777
 
773
 
  if (a->is_datetime())
 
778
  if (in_a->is_datetime())
774
779
  {
775
 
    if (b->is_datetime())
 
780
    if (in_b->is_datetime())
 
781
    {
776
782
      cmp_type= CMP_DATE_WITH_DATE;
777
 
    else if (b->result_type() == STRING_RESULT)
 
783
    }
 
784
    else if (in_b->result_type() == STRING_RESULT)
778
785
    {
779
786
      cmp_type= CMP_DATE_WITH_STR;
780
 
      date_arg= a;
781
 
      str_arg= b;
 
787
      date_arg= in_a;
 
788
      str_arg= in_b;
782
789
    }
783
790
  }
784
 
  else if (b->is_datetime() && a->result_type() == STRING_RESULT)
 
791
  else if (in_b->is_datetime() && in_a->result_type() == STRING_RESULT)
785
792
  {
786
793
    cmp_type= CMP_STR_WITH_DATE;
787
 
    date_arg= b;
788
 
    str_arg= a;
 
794
    date_arg= in_b;
 
795
    str_arg= in_a;
789
796
  }
790
797
 
791
798
  if (cmp_type != CMP_DATE_DFLT)
815
822
       * Does a uint64_t conversion really have to happen here?  Fields return int64_t
816
823
       * from val_int(), not uint64_t...
817
824
       */
818
 
      uint64_t value;
 
825
      int64_t value;
819
826
      String *str_val;
820
827
      String tmp;
821
828
      /* DateTime used to pick up as many string conversion possibilities as possible. */
841
848
      }
842
849
 
843
850
      /* String conversion was good.  Convert to an integer for comparison purposes. */
844
 
      int64_t int_value;
845
 
      temporal.to_int64_t(&int_value);
846
 
      value= (uint64_t) int_value;
 
851
      temporal.to_int64_t(&value);
847
852
 
848
853
      if (const_value)
849
854
        *const_value= value;
857
862
                                        Item **a1, Item **a2,
858
863
                                        Item_result type)
859
864
{
860
 
  enum enum_date_cmp_type cmp_type;
861
 
  uint64_t const_value= (uint64_t)-1;
 
865
  enum_date_cmp_type cmp_type;
 
866
  int64_t const_value= -1;
862
867
  a= a1;
863
868
  b= a2;
864
869
 
865
870
  if ((cmp_type= can_compare_as_dates(*a, *b, &const_value)))
866
871
  {
867
 
    session= current_session;
868
872
    owner= owner_arg;
869
873
    a_type= (*a)->field_type();
870
874
    b_type= (*b)->field_type();
871
875
    a_cache= 0;
872
876
    b_cache= 0;
873
877
 
874
 
    if (const_value != (uint64_t)-1)
 
878
    if (const_value != -1)
875
879
    {
876
880
      Item_cache_int *cache= new Item_cache_int();
877
881
      /* Mark the cache as non-const to prevent re-caching. */
892
896
    is_nulls_eq= test(owner && owner->functype() == Item_func::EQUAL_FUNC);
893
897
    func= &Arg_comparator::compare_datetime;
894
898
    get_value_func= &get_datetime_value;
 
899
 
895
900
    return 0;
896
901
  }
897
902
 
901
906
 
902
907
void Arg_comparator::set_datetime_cmp_func(Item **a1, Item **b1)
903
908
{
904
 
  session= current_session;
905
909
  /* A caller will handle null values by itself. */
906
910
  owner= NULL;
907
911
  a= a1;
945
949
    obtained value
946
950
*/
947
951
 
948
 
uint64_t
 
952
int64_t
949
953
get_datetime_value(Session *session, Item ***item_arg, Item **cache_arg,
950
954
                   Item *warn_item, bool *is_null)
951
955
{
952
 
  uint64_t value= 0;
 
956
  int64_t value= 0;
953
957
  String buf, *str= 0;
954
958
  Item *item= **item_arg;
955
959
 
973
977
    str= item->val_str(&buf);
974
978
    *is_null= item->null_value;
975
979
  }
 
980
 
976
981
  if (*is_null)
977
982
    return ~(uint64_t) 0;
 
983
 
978
984
  /*
979
985
    Convert strings to the integer DATE/DATETIME representation.
980
986
    Even if both dates provided in strings we can't compare them directly as
985
991
  {
986
992
    bool error;
987
993
    enum_field_types f_type= warn_item->field_type();
988
 
    enum enum_drizzle_timestamp_type t_type= f_type ==
989
 
      DRIZZLE_TYPE_DATE ? DRIZZLE_TIMESTAMP_DATE : DRIZZLE_TIMESTAMP_DATETIME;
 
994
    type::timestamp_t t_type= f_type == DRIZZLE_TYPE_DATE ? type::DRIZZLE_TIMESTAMP_DATE : type::DRIZZLE_TIMESTAMP_DATETIME;
990
995
    value= get_date_from_str(session, str, t_type, warn_item->name, &error);
991
996
    /*
992
997
      If str did not contain a valid date according to the current
1009
1014
    *cache_arg= cache;
1010
1015
    *item_arg= cache_arg;
1011
1016
  }
 
1017
 
1012
1018
  return value;
1013
1019
}
1014
1020
 
1165
1171
 
1166
1172
int Arg_comparator::compare_decimal()
1167
1173
{
1168
 
  my_decimal value1;
1169
 
  my_decimal *val1= (*a)->val_decimal(&value1);
 
1174
  type::Decimal value1;
 
1175
  type::Decimal *val1= (*a)->val_decimal(&value1);
1170
1176
  if (!(*a)->null_value)
1171
1177
  {
1172
 
    my_decimal value2;
1173
 
    my_decimal *val2= (*b)->val_decimal(&value2);
 
1178
    type::Decimal value2;
 
1179
    type::Decimal *val2= (*b)->val_decimal(&value2);
1174
1180
    if (!(*b)->null_value)
1175
1181
    {
1176
1182
      owner->null_value= 0;
1177
 
      return my_decimal_cmp(val1, val2);
 
1183
      return class_decimal_cmp(val1, val2);
1178
1184
    }
1179
1185
  }
1180
1186
  owner->null_value= 1;
1192
1198
 
1193
1199
int Arg_comparator::compare_e_decimal()
1194
1200
{
1195
 
  my_decimal value1, value2;
1196
 
  my_decimal *val1= (*a)->val_decimal(&value1);
1197
 
  my_decimal *val2= (*b)->val_decimal(&value2);
 
1201
  type::Decimal value1, value2;
 
1202
  type::Decimal *val1= (*a)->val_decimal(&value1);
 
1203
  type::Decimal *val2= (*b)->val_decimal(&value2);
1198
1204
  if ((*a)->null_value || (*b)->null_value)
1199
1205
    return test((*a)->null_value && (*b)->null_value);
1200
 
  return test(my_decimal_cmp(val1, val2) == 0);
 
1206
  return test(class_decimal_cmp(val1, val2) == 0);
1201
1207
}
1202
1208
 
1203
1209
 
1607
1613
 
1608
1614
void Item_in_optimizer::cleanup()
1609
1615
{
1610
 
  Item_bool_func::cleanup();
 
1616
  item::function::Boolean::cleanup();
1611
1617
  if (!save_cache)
1612
1618
    cache= 0;
1613
1619
  return;
1660
1666
    change records at each execution.
1661
1667
  */
1662
1668
  if ((*args) != new_item)
1663
 
    current_session->change_item_tree(args, new_item);
 
1669
    getSession().change_item_tree(args, new_item);
1664
1670
 
1665
1671
  /*
1666
1672
    Transform the right IN operand which should be an Item_in_subselect or a
1815
1821
          {
1816
1822
            range->type= DECIMAL_RESULT;
1817
1823
            range->dec.init();
1818
 
            my_decimal *dec= el->val_decimal(&range->dec);
 
1824
            type::Decimal *dec= el->val_decimal(&range->dec);
1819
1825
            if (dec != &range->dec)
1820
1826
            {
1821
1827
              range->dec= *dec;
1865
1871
{
1866
1872
  assert(fixed == 1);
1867
1873
  double value;
1868
 
  my_decimal dec_buf, *dec= NULL;
 
1874
  type::Decimal dec_buf, *dec= NULL;
1869
1875
  uint32_t i;
1870
1876
 
1871
1877
  if (use_decimal_comparison)
1873
1879
    dec= row->element_index(0)->val_decimal(&dec_buf);
1874
1880
    if (row->element_index(0)->null_value)
1875
1881
      return -1;
1876
 
    my_decimal2double(E_DEC_FATAL_ERROR, dec, &value);
 
1882
    class_decimal2double(E_DEC_FATAL_ERROR, dec, &value);
1877
1883
  }
1878
1884
  else
1879
1885
  {
1898
1904
        and we are comparing against a decimal
1899
1905
      */
1900
1906
      if (dec && range->type == DECIMAL_RESULT)
1901
 
        cmp_result= my_decimal_cmp(&range->dec, dec) <= 0;
 
1907
        cmp_result= class_decimal_cmp(&range->dec, dec) <= 0;
1902
1908
      else
1903
1909
        cmp_result= (range->dbl <= value);
1904
1910
      if (cmp_result)
1908
1914
    }
1909
1915
    interval_range *range= intervals+start;
1910
1916
    return ((dec && range->type == DECIMAL_RESULT) ?
1911
 
            my_decimal_cmp(dec, &range->dec) < 0 :
 
1917
            class_decimal_cmp(dec, &range->dec) < 0 :
1912
1918
            value < range->dbl) ? 0 : start + 1;
1913
1919
  }
1914
1920
 
1919
1925
        ((el->result_type() == DECIMAL_RESULT) ||
1920
1926
         (el->result_type() == INT_RESULT)))
1921
1927
    {
1922
 
      my_decimal e_dec_buf, *e_dec= el->val_decimal(&e_dec_buf);
 
1928
      type::Decimal e_dec_buf, *e_dec= el->val_decimal(&e_dec_buf);
1923
1929
      /* Skip NULL ranges. */
1924
1930
      if (el->null_value)
1925
1931
        continue;
1926
 
      if (my_decimal_cmp(e_dec, dec) > 0)
 
1932
      if (class_decimal_cmp(e_dec, dec) > 0)
1927
1933
        return i - 1;
1928
1934
    }
1929
1935
    else
1994
2000
  int i;
1995
2001
  bool datetime_found= false;
1996
2002
  compare_as_dates= true;
1997
 
  Session *session= current_session;
1998
2003
 
1999
2004
  /*
2000
2005
    As some compare functions are generated after sql_yacc,
2032
2037
    ge_cmp.set_datetime_cmp_func(args, args + 1);
2033
2038
    le_cmp.set_datetime_cmp_func(args, args + 2);
2034
2039
  }
2035
 
  else if (args[0]->real_item()->type() == FIELD_ITEM &&
2036
 
           session->lex->sql_command != SQLCOM_SHOW_CREATE)
 
2040
  else if (args[0]->real_item()->type() == FIELD_ITEM)
2037
2041
  {
2038
2042
    Item_field *field_item= (Item_field*) (args[0]->real_item());
2039
2043
    if (field_item->field->can_be_compared_as_int64_t())
2042
2046
        The following can't be recoded with || as convert_constant_item
2043
2047
        changes the argument
2044
2048
      */
2045
 
      if (convert_constant_item(session, field_item, &args[1]))
 
2049
      if (convert_constant_item(&getSession(), field_item, &args[1]))
2046
2050
        cmp_type=INT_RESULT;                    // Works for all types.
2047
 
      if (convert_constant_item(session, field_item, &args[2]))
 
2051
      if (convert_constant_item(&getSession(), field_item, &args[2]))
2048
2052
        cmp_type=INT_RESULT;                    // Works for all types.
2049
2053
    }
2050
2054
  }
2121
2125
  }
2122
2126
  else if (cmp_type == DECIMAL_RESULT)
2123
2127
  {
2124
 
    my_decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
 
2128
    type::Decimal dec_buf, *dec= args[0]->val_decimal(&dec_buf),
2125
2129
               a_buf, *a_dec, b_buf, *b_dec;
2126
2130
    if ((null_value=args[0]->null_value))
2127
2131
      return 0;
2128
2132
    a_dec= args[1]->val_decimal(&a_buf);
2129
2133
    b_dec= args[2]->val_decimal(&b_buf);
2130
2134
    if (!args[1]->null_value && !args[2]->null_value)
2131
 
      return (int64_t) ((my_decimal_cmp(dec, a_dec) >= 0 &&
2132
 
                          my_decimal_cmp(dec, b_dec) <= 0) != negated);
 
2135
      return (int64_t) ((class_decimal_cmp(dec, a_dec) >= 0 &&
 
2136
                          class_decimal_cmp(dec, b_dec) <= 0) != negated);
2133
2137
    if (args[1]->null_value && args[2]->null_value)
2134
2138
      null_value=1;
2135
2139
    else if (args[1]->null_value)
2136
 
      null_value= (my_decimal_cmp(dec, b_dec) <= 0);
 
2140
      null_value= (class_decimal_cmp(dec, b_dec) <= 0);
2137
2141
    else
2138
 
      null_value= (my_decimal_cmp(dec, a_dec) >= 0);
 
2142
      null_value= (class_decimal_cmp(dec, a_dec) >= 0);
2139
2143
  }
2140
2144
  else
2141
2145
  {
2193
2197
    max_length= max(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
2194
2198
  }
2195
2199
  else
 
2200
  {
2196
2201
    max_length= max(args[0]->max_length, args[1]->max_length);
 
2202
  }
2197
2203
 
2198
2204
  switch (hybrid_type)
2199
2205
  {
2200
2206
  case STRING_RESULT:
2201
2207
    agg_arg_charsets(collation, args, arg_count, MY_COLL_CMP_CONV, 1);
2202
2208
    break;
 
2209
 
2203
2210
  case DECIMAL_RESULT:
2204
2211
  case REAL_RESULT:
2205
2212
    break;
 
2213
 
2206
2214
  case INT_RESULT:
2207
2215
    decimals= 0;
2208
2216
    break;
 
2217
 
2209
2218
  case ROW_RESULT:
2210
 
  default:
2211
2219
    assert(0);
2212
2220
  }
 
2221
 
2213
2222
  cached_field_type= agg_field_type(args, 2);
2214
2223
}
2215
2224
 
2264
2273
}
2265
2274
 
2266
2275
 
2267
 
my_decimal *Item_func_ifnull::decimal_op(my_decimal *decimal_value)
 
2276
type::Decimal *Item_func_ifnull::decimal_op(type::Decimal *decimal_value)
2268
2277
{
2269
2278
  assert(fixed == 1);
2270
 
  my_decimal *value= args[0]->val_decimal(decimal_value);
 
2279
  type::Decimal *value= args[0]->val_decimal(decimal_value);
2271
2280
  if (!args[0]->null_value)
2272
2281
  {
2273
2282
    null_value= 0;
2437
2446
}
2438
2447
 
2439
2448
 
2440
 
my_decimal *
2441
 
Item_func_if::val_decimal(my_decimal *decimal_value)
 
2449
type::Decimal *
 
2450
Item_func_if::val_decimal(type::Decimal *decimal_value)
2442
2451
{
2443
2452
  assert(fixed == 1);
2444
2453
  Item *arg= args[0]->val_bool() ? args[1] : args[2];
2445
 
  my_decimal *value= arg->val_decimal(decimal_value);
 
2454
  type::Decimal *value= arg->val_decimal(decimal_value);
2446
2455
  null_value= arg->null_value;
2447
2456
  return value;
2448
2457
}
2522
2531
}
2523
2532
 
2524
2533
 
2525
 
my_decimal *
2526
 
Item_func_nullif::val_decimal(my_decimal * decimal_value)
 
2534
type::Decimal *
 
2535
Item_func_nullif::val_decimal(type::Decimal * decimal_value)
2527
2536
{
2528
2537
  assert(fixed == 1);
2529
 
  my_decimal *res;
 
2538
  type::Decimal *res;
2530
2539
  if (!cmp.compare())
2531
2540
  {
2532
2541
    null_value=1;
2659
2668
}
2660
2669
 
2661
2670
 
2662
 
my_decimal *Item_func_case::val_decimal(my_decimal *decimal_value)
 
2671
type::Decimal *Item_func_case::val_decimal(type::Decimal *decimal_value)
2663
2672
{
2664
2673
  assert(fixed == 1);
2665
2674
  char buff[MAX_FIELD_WIDTH];
2666
2675
  String dummy_str(buff, sizeof(buff), default_charset());
2667
2676
  Item *item= find_item(&dummy_str);
2668
 
  my_decimal *res;
 
2677
  type::Decimal *res;
2669
2678
 
2670
2679
  if (!item)
2671
2680
  {
2708
2717
 
2709
2718
void Item_func_case::agg_num_lengths(Item *arg)
2710
2719
{
2711
 
  uint32_t len= my_decimal_length_to_precision(arg->max_length, arg->decimals,
 
2720
  uint32_t len= class_decimal_length_to_precision(arg->max_length, arg->decimals,
2712
2721
                                           arg->unsigned_flag) - arg->decimals;
2713
2722
  set_if_bigger(max_length, len);
2714
2723
  set_if_bigger(decimals, arg->decimals);
2747
2756
  */
2748
2757
  if (first_expr_num != -1)
2749
2758
  {
2750
 
    uint32_t i;
2751
2759
    agg[0]= args[first_expr_num];
2752
2760
    left_result_type= agg[0]->result_type();
2753
2761
 
2757
2765
    if (!(found_types= collect_cmp_types(agg, nagg)))
2758
2766
      return;
2759
2767
 
2760
 
    for (i= 0; i <= (uint32_t)DECIMAL_RESULT; i++)
 
2768
    for (int i= STRING_RESULT; i <= DECIMAL_RESULT; i++)
2761
2769
    {
2762
2770
      if (found_types & (1 << i) && !cmp_items[i])
2763
2771
      {
2792
2800
      agg_num_lengths(args[i + 1]);
2793
2801
    if (else_expr_num != -1)
2794
2802
      agg_num_lengths(args[else_expr_num]);
2795
 
    max_length= my_decimal_precision_to_length(max_length + decimals, decimals,
 
2803
    max_length= class_decimal_precision_to_length(max_length + decimals, decimals,
2796
2804
                                               unsigned_flag);
2797
2805
  }
2798
2806
}
2843
2851
 
2844
2852
void Item_func_case::cleanup()
2845
2853
{
2846
 
  uint32_t i;
2847
2854
  Item_func::cleanup();
2848
 
  for (i= 0; i <= (uint32_t)DECIMAL_RESULT; i++)
 
2855
  for (int i= STRING_RESULT; i <= DECIMAL_RESULT; i++)
2849
2856
  {
2850
2857
    delete cmp_items[i];
2851
2858
    cmp_items[i]= 0;
2852
2859
  }
2853
 
  return;
2854
2860
}
2855
2861
 
2856
2862
 
2901
2907
}
2902
2908
 
2903
2909
 
2904
 
my_decimal *Item_func_coalesce::decimal_op(my_decimal *decimal_value)
 
2910
type::Decimal *Item_func_coalesce::decimal_op(type::Decimal *decimal_value)
2905
2911
{
2906
2912
  assert(fixed == 1);
2907
2913
  null_value= 0;
2908
2914
  for (uint32_t i= 0; i < arg_count; i++)
2909
2915
  {
2910
 
    my_decimal *res= args[i]->val_decimal(decimal_value);
 
2916
    type::Decimal *res= args[i]->val_decimal(decimal_value);
2911
2917
    if (!args[i]->null_value)
2912
2918
      return res;
2913
2919
  }
2920
2926
{
2921
2927
  cached_field_type= agg_field_type(args, arg_count);
2922
2928
  agg_result_type(&hybrid_type, args, arg_count);
 
2929
 
2923
2930
  switch (hybrid_type) {
2924
2931
  case STRING_RESULT:
2925
2932
    count_only_length();
2926
2933
    decimals= NOT_FIXED_DEC;
2927
2934
    agg_arg_charsets(collation, args, arg_count, MY_COLL_ALLOW_CONV, 1);
2928
2935
    break;
 
2936
 
2929
2937
  case DECIMAL_RESULT:
2930
2938
    count_decimal_length();
2931
2939
    break;
 
2940
 
2932
2941
  case REAL_RESULT:
2933
2942
    count_real_length();
2934
2943
    break;
 
2944
 
2935
2945
  case INT_RESULT:
2936
2946
    count_only_length();
2937
2947
    decimals= 0;
2938
2948
    break;
 
2949
 
2939
2950
  case ROW_RESULT:
2940
 
  default:
2941
2951
    assert(0);
2942
2952
  }
2943
2953
}
3052
3062
}
3053
3063
 
3054
3064
 
3055
 
static int cmp_decimal(void *, my_decimal *a, my_decimal *b)
 
3065
static int cmp_decimal(void *, type::Decimal *a, type::Decimal *b)
3056
3066
{
3057
3067
  /*
3058
3068
    We need call of fixing buffer pointer, because fast sort just copy
3060
3070
  */
3061
3071
  a->fix_buffer_pointer();
3062
3072
  b->fix_buffer_pointer();
3063
 
  return my_decimal_cmp(a, b);
 
3073
  return class_decimal_cmp(a, b);
3064
3074
}
3065
3075
 
3066
3076
 
3168
3178
  return;
3169
3179
}
3170
3180
 
3171
 
in_int64_t::in_int64_t(uint32_t elements)
3172
 
  :in_vector(elements,sizeof(packed_int64_t),(qsort2_cmp) cmp_int64_t, 0)
 
3181
in_int64_t::in_int64_t(uint32_t elements) :
 
3182
  in_vector(elements, sizeof(packed_int64_t),(qsort2_cmp) cmp_int64_t, 0)
3173
3183
{}
3174
3184
 
3175
3185
void in_int64_t::set(uint32_t pos,Item *item)
3189
3199
  return (unsigned char*) &tmp;
3190
3200
}
3191
3201
 
3192
 
void in_datetime::set(uint32_t pos,Item *item)
 
3202
void in_datetime::set(uint32_t pos, Item *item)
3193
3203
{
3194
3204
  Item **tmp_item= &item;
3195
3205
  bool is_null;
3229
3239
 
3230
3240
 
3231
3241
in_decimal::in_decimal(uint32_t elements)
3232
 
  :in_vector(elements, sizeof(my_decimal),(qsort2_cmp) cmp_decimal, 0)
 
3242
  :in_vector(elements, sizeof(type::Decimal),(qsort2_cmp) cmp_decimal, 0)
3233
3243
{}
3234
3244
 
3235
3245
 
3236
3246
void in_decimal::set(uint32_t pos, Item *item)
3237
3247
{
3238
 
  /* as far as 'item' is constant, we can store reference on my_decimal */
3239
 
  my_decimal *dec= ((my_decimal *)base) + pos;
 
3248
  /* as far as 'item' is constant, we can store reference on type::Decimal */
 
3249
  type::Decimal *dec= ((type::Decimal *)base) + pos;
3240
3250
  dec->len= DECIMAL_BUFF_LENGTH;
3241
3251
  dec->fix_buffer_pointer();
3242
 
  my_decimal *res= item->val_decimal(dec);
 
3252
  type::Decimal *res= item->val_decimal(dec);
3243
3253
  /* if item->val_decimal() is evaluated to NULL then res == 0 */
3244
3254
  if (!item->null_value && res != dec)
3245
 
    my_decimal2decimal(res, dec);
 
3255
    class_decimal2decimal(res, dec);
3246
3256
}
3247
3257
 
3248
3258
 
3249
3259
unsigned char *in_decimal::get_value(Item *item)
3250
3260
{
3251
 
  my_decimal *result= item->val_decimal(&val);
 
3261
  type::Decimal *result= item->val_decimal(&val);
3252
3262
  if (item->null_value)
3253
3263
    return 0;
3254
3264
  return (unsigned char *)result;
3261
3271
  switch (type) {
3262
3272
  case STRING_RESULT:
3263
3273
    return new cmp_item_sort_string(cs);
 
3274
 
3264
3275
  case INT_RESULT:
3265
3276
    return new cmp_item_int;
 
3277
 
3266
3278
  case REAL_RESULT:
3267
3279
    return new cmp_item_real;
 
3280
 
3268
3281
  case ROW_RESULT:
3269
3282
    return new cmp_item_row;
 
3283
 
3270
3284
  case DECIMAL_RESULT:
3271
3285
    return new cmp_item_decimal;
3272
 
  default:
3273
 
    assert(0);
3274
 
    break;
3275
3286
  }
 
3287
 
3276
3288
  return 0; // to satisfy compiler :)
3277
3289
}
3278
3290
 
3405
3417
 
3406
3418
void cmp_item_decimal::store_value(Item *item)
3407
3419
{
3408
 
  my_decimal *val= item->val_decimal(&value);
 
3420
  type::Decimal *val= item->val_decimal(&value);
3409
3421
  /* val may be zero if item is nnull */
3410
3422
  if (val && val != &value)
3411
 
    my_decimal2decimal(val, &value);
 
3423
    class_decimal2decimal(val, &value);
3412
3424
}
3413
3425
 
3414
3426
 
3415
3427
int cmp_item_decimal::cmp(Item *arg)
3416
3428
{
3417
 
  my_decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
 
3429
  type::Decimal tmp_buf, *tmp= arg->val_decimal(&tmp_buf);
3418
3430
  if (arg->null_value)
3419
3431
    return 1;
3420
 
  return my_decimal_cmp(&value, tmp);
 
3432
  return class_decimal_cmp(&value, tmp);
3421
3433
}
3422
3434
 
3423
3435
 
3424
3436
int cmp_item_decimal::compare(cmp_item *arg)
3425
3437
{
3426
3438
  cmp_item_decimal *l_cmp= (cmp_item_decimal*) arg;
3427
 
  return my_decimal_cmp(&value, &l_cmp->value);
 
3439
  return class_decimal_cmp(&value, &l_cmp->value);
3428
3440
}
3429
3441
 
3430
3442
 
3537
3549
{
3538
3550
  Item **arg, **arg_end;
3539
3551
  bool const_itm= 1;
3540
 
  Session *session= current_session;
3541
3552
  bool datetime_found= false;
3542
3553
  /* true <=> arguments values will be compared as DATETIMEs. */
3543
3554
  bool compare_as_datetime= false;
3544
3555
  Item *date_arg= 0;
3545
3556
  uint32_t found_types= 0;
3546
 
  uint32_t type_cnt= 0, i;
 
3557
  uint32_t type_cnt= 0;
3547
3558
  Item_result cmp_type= STRING_RESULT;
3548
3559
  left_result_type= args[0]->result_type();
3549
3560
  if (!(found_types= collect_cmp_types(args, arg_count, true)))
3557
3568
      break;
3558
3569
    }
3559
3570
  }
3560
 
  for (i= 0; i <= (uint32_t)DECIMAL_RESULT; i++)
 
3571
  for (int i= STRING_RESULT; i <= DECIMAL_RESULT; i++)
3561
3572
  {
3562
3573
    if (found_types & 1 << i)
3563
3574
    {
3664
3675
  if (type_cnt == 1 && const_itm && !nulls_in_row())
3665
3676
  {
3666
3677
    if (compare_as_datetime)
 
3678
    {
3667
3679
      array= new in_datetime(date_arg, arg_count - 1);
 
3680
    }
3668
3681
    else
3669
3682
    {
3670
3683
      /*
3675
3688
        comparison type accordingly.
3676
3689
      */
3677
3690
      if (args[0]->real_item()->type() == FIELD_ITEM &&
3678
 
          session->lex->sql_command != SQLCOM_SHOW_CREATE &&
3679
3691
          cmp_type != INT_RESULT)
3680
3692
      {
3681
3693
        Item_field *field_item= (Item_field*) (args[0]->real_item());
3684
3696
          bool all_converted= true;
3685
3697
          for (arg=args+1, arg_end=args+arg_count; arg != arg_end ; arg++)
3686
3698
          {
3687
 
            if (!convert_constant_item (session, field_item, &arg[0]))
 
3699
            if (!convert_constant_item (&getSession(), field_item, &arg[0]))
3688
3700
              all_converted= false;
3689
3701
          }
3690
3702
          if (all_converted)
3691
3703
            cmp_type= INT_RESULT;
3692
3704
        }
3693
3705
      }
 
3706
 
3694
3707
      switch (cmp_type) {
3695
3708
      case STRING_RESULT:
3696
3709
        array=new in_string(arg_count-1,(qsort2_cmp) srtcmp_in,
3697
3710
                            cmp_collation.collation);
3698
3711
        break;
 
3712
 
3699
3713
      case INT_RESULT:
3700
3714
        array= new in_int64_t(arg_count-1);
3701
3715
        break;
 
3716
 
3702
3717
      case REAL_RESULT:
3703
3718
        array= new in_double(arg_count-1);
3704
3719
        break;
 
3720
 
3705
3721
      case ROW_RESULT:
3706
3722
        /*
3707
3723
          The row comparator was created at the beginning but only DATETIME
3710
3726
        */
3711
3727
        ((in_row*)array)->tmp.store_value(args[0]);
3712
3728
        break;
 
3729
 
3713
3730
      case DECIMAL_RESULT:
3714
3731
        array= new in_decimal(arg_count - 1);
3715
3732
        break;
3716
 
      default:
3717
 
        assert(0);
3718
 
        return;
3719
3733
      }
3720
3734
    }
3721
 
    if (array && !(session->is_fatal_error))            // If not EOM
 
3735
 
 
3736
    if (array && !(getSession().is_fatal_error))                // If not EOM
3722
3737
    {
3723
3738
      uint32_t j=0;
3724
3739
      for (uint32_t arg_num=1 ; arg_num < arg_count ; arg_num++)
3725
3740
      {
3726
 
        if (!args[arg_num]->null_value)                 // Skip NULL values
 
3741
        if (!args[arg_num]->null_value)                 // Skip NULL values
3727
3742
        {
3728
3743
          array->set(j,args[arg_num]);
3729
 
          j++;
 
3744
          j++;
3730
3745
        }
3731
 
        else
3732
 
          have_null= 1;
 
3746
        else
 
3747
          have_null= 1;
3733
3748
      }
3734
3749
      if ((array->used_count= j))
3735
 
        array->sort();
 
3750
        array->sort();
3736
3751
    }
3737
3752
  }
3738
3753
  else
3741
3756
      cmp_items[STRING_RESULT]= new cmp_item_datetime(date_arg);
3742
3757
    else
3743
3758
    {
3744
 
      for (i= 0; i <= (uint32_t) DECIMAL_RESULT; i++)
 
3759
      for (int i= STRING_RESULT; i <= DECIMAL_RESULT; i++)
3745
3760
      {
3746
3761
        if (found_types & (1 << i) && !cmp_items[i])
3747
3762
        {
3834
3849
 
3835
3850
 
3836
3851
Item_cond::Item_cond(Session *session, Item_cond *item)
3837
 
  :Item_bool_func(session, item),
 
3852
  :item::function::Boolean(session, item),
3838
3853
   abort_on_null(item->abort_on_null),
3839
3854
   and_tables_cache(item->and_tables_cache)
3840
3855
{
3861
3876
  void *orig_session_marker= session->session_marker;
3862
3877
  unsigned char buff[sizeof(char*)];                    // Max local vars in function
3863
3878
  not_null_tables_cache= used_tables_cache= 0;
3864
 
  const_item_cache= 1;
 
3879
  const_item_cache= true;
3865
3880
 
3866
3881
  if (functype() == COND_OR_FUNC)
3867
3882
    session->session_marker= 0;
3936
3951
  Item *item;
3937
3952
 
3938
3953
  used_tables_cache=0;
3939
 
  const_item_cache=1;
 
3954
  const_item_cache= true;
3940
3955
 
3941
3956
  and_tables_cache= ~(table_map) 0; // Here and below we do as fix_fields does
3942
3957
  not_null_tables_cache= 0;
4008
4023
      change records at each execution.
4009
4024
    */
4010
4025
    if (new_item != item)
4011
 
      current_session->change_item_tree(li.ref(), new_item);
 
4026
      getSession().change_item_tree(li.ref(), new_item);
4012
4027
  }
4013
4028
  return Item_func::transform(transformer, arg);
4014
4029
}
4125
4140
  Item *item;
4126
4141
 
4127
4142
  used_tables_cache=0;
4128
 
  const_item_cache=1;
 
4143
  const_item_cache= true;
4129
4144
  while ((item=li++))
4130
4145
  {
4131
4146
    item->update_used_tables();
4467
4482
  Item_bool_func2::cleanup();
4468
4483
}
4469
4484
 
 
4485
static unsigned char likeconv(const CHARSET_INFO *cs, unsigned char a)
 
4486
{
4470
4487
#ifdef LIKE_CMP_TOUPPER
4471
 
#define likeconv(cs,A) (unsigned char) (cs)->toupper(A)
 
4488
  return cs->toupper(a);
4472
4489
#else
4473
 
#define likeconv(cs,A) (unsigned char) (cs)->sort_order[(unsigned char) (A)]
 
4490
  return cs->sort_order[a];
4474
4491
#endif
4475
 
 
 
4492
}
4476
4493
 
4477
4494
/**
4478
4495
  Precomputation dependent only on pattern_len.
4867
4884
}
4868
4885
 
4869
4886
Item_equal::Item_equal(Item_field *f1, Item_field *f2)
4870
 
  : Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
 
4887
  : item::function::Boolean(), const_item(0), eval_item(0), cond_false(0)
4871
4888
{
4872
 
  const_item_cache= 0;
 
4889
  const_item_cache= false;
4873
4890
  fields.push_back(f1);
4874
4891
  fields.push_back(f2);
4875
4892
}
4876
4893
 
4877
4894
Item_equal::Item_equal(Item *c, Item_field *f)
4878
 
  : Item_bool_func(), eval_item(0), cond_false(0)
 
4895
  : item::function::Boolean(), eval_item(0), cond_false(0)
4879
4896
{
4880
 
  const_item_cache= 0;
 
4897
  const_item_cache= false;
4881
4898
  fields.push_back(f);
4882
4899
  const_item= c;
4883
4900
}
4884
4901
 
4885
4902
 
4886
4903
Item_equal::Item_equal(Item_equal *item_equal)
4887
 
  : Item_bool_func(), eval_item(0), cond_false(0)
 
4904
  : item::function::Boolean(), eval_item(0), cond_false(0)
4888
4905
{
4889
 
  const_item_cache= 0;
 
4906
  const_item_cache= false;
4890
4907
  List_iterator_fast<Item_field> li(item_equal->fields);
4891
4908
  Item_field *item;
4892
4909
  while ((item= li++))
4910
4927
  func->set_cmp_func();
4911
4928
  func->quick_fix_field();
4912
4929
  if ((cond_false= !func->val_int()))
4913
 
    const_item_cache= 1;
 
4930
    const_item_cache= true;
4914
4931
}
4915
4932
 
4916
4933
void Item_equal::add(Item_field *f)
5056
5073
  List_iterator_fast<Item_field> li(fields);
5057
5074
  Item *item;
5058
5075
  not_null_tables_cache= used_tables_cache= 0;
5059
 
  const_item_cache= 0;
 
5076
  const_item_cache= false;
5060
5077
  while ((item= li++))
5061
5078
  {
5062
5079
    table_map tmp_table_map;
5093
5110
    return 0;
5094
5111
  List_iterator_fast<Item_field> it(fields);
5095
5112
  Item *item= const_item ? const_item : it++;
 
5113
  eval_item->store_value(item);
5096
5114
  if ((null_value= item->null_value))
5097
5115
    return 0;
5098
 
  eval_item->store_value(item);
5099
5116
  while ((item_field= it++))
5100
5117
  {
5101
5118
    /* Skip fields of non-const tables. They haven't been read yet */
5102
 
    if (item_field->field->table->const_table)
 
5119
    if (item_field->field->getTable()->const_table)
5103
5120
    {
5104
 
      if ((null_value= item_field->null_value) || eval_item->cmp(item_field))
 
5121
      if (eval_item->cmp(item_field) || (null_value= item_field->null_value))
5105
5122
        return 0;
5106
5123
    }
5107
5124
  }
5144
5161
      change records at each execution.
5145
5162
    */
5146
5163
    if (new_item != item)
5147
 
      current_session->change_item_tree((Item **) it.ref(), new_item);
 
5164
      getSession().change_item_tree((Item **) it.ref(), new_item);
5148
5165
  }
5149
5166
  return Item_func::transform(transformer, arg);
5150
5167
}