~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

MergeĀ fromĀ Lee.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
class Name_resolution_context;
34
34
class st_select_lex;
35
35
class Item_equal;
36
 
class COND_EQUAL;
37
36
class user_var_entry;
38
37
class Item_sum;
39
38
class Item_in_subselect;
589
588
};
590
589
 
591
590
#include <drizzled/item/basic_constant.h>
 
591
#include <drizzled/item/bin_string.h>
 
592
#include <drizzled/item/blob.h>
 
593
#include <drizzled/item/cache.h>
 
594
#include <drizzled/item/copy_string.h>
592
595
#include <drizzled/item/ident.h>
593
596
#include <drizzled/item/decimal.h>
 
597
#include <drizzled/item/direct_ref.h>
 
598
#include <drizzled/item/empty_string.h>
594
599
#include <drizzled/item/field.h>
 
600
#include <drizzled/item/hex_string.h>
595
601
#include <drizzled/item/ifloat.h>
596
602
#include <drizzled/item/istring.h>
597
603
#include <drizzled/item/int.h>
 
604
#include <drizzled/item/int_with_ref.h>
598
605
#include <drizzled/item/null.h>
599
606
#include <drizzled/item/num.h>
 
607
#include <drizzled/item/outer_ref.h>
600
608
#include <drizzled/item/param.h>
 
609
#include <drizzled/item/ref.h>
 
610
#include <drizzled/item/ref_null_helper.h>
601
611
#include <drizzled/item/return_date_time.h>
 
612
#include <drizzled/item/return_int.h>
602
613
#include <drizzled/item/uint.h>
603
614
 
604
615
void mark_as_dependent(Session *session,
612
623
                                       st_select_lex *select);
613
624
 
614
625
 
615
 
class Item_blob :public Item_string
616
 
{
617
 
public:
618
 
  Item_blob(const char *name, uint32_t length) :
619
 
    Item_string(name, length, &my_charset_bin)
620
 
  { max_length= length; }
621
 
  enum Type type() const { return TYPE_HOLDER; }
622
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_BLOB; }
623
 
};
624
 
 
625
 
 
626
 
/**
627
 
  Item_empty_string -- is a utility class to put an item into List<Item>
628
 
  which is then used in protocol.send_fields() when sending SHOW output to
629
 
  the client.
630
 
*/
631
 
 
632
 
class Item_empty_string :public Item_string
633
 
{
634
 
public:
635
 
  Item_empty_string(const char *header,uint32_t length, const CHARSET_INFO * cs= NULL) :
636
 
    Item_string("",0, cs ? cs : &my_charset_utf8_general_ci)
637
 
    { name=(char*) header; max_length= cs ? length * cs->mbmaxlen : length; }
638
 
  void make_field(Send_field *field);
639
 
};
640
 
 
641
 
 
642
 
class Item_return_int :public Item_int
643
 
{
644
 
  enum_field_types int_field_type;
645
 
public:
646
 
  Item_return_int(const char *name_arg, uint32_t length,
647
 
                  enum_field_types field_type_arg, int64_t value= 0)
648
 
    :Item_int(name_arg, value, length), int_field_type(field_type_arg)
649
 
  {
650
 
    unsigned_flag=1;
651
 
  }
652
 
  enum_field_types field_type() const { return int_field_type; }
653
 
};
654
 
 
655
 
 
656
 
class Item_hex_string: public Item_basic_constant
657
 
{
658
 
public:
659
 
  Item_hex_string() {}
660
 
  Item_hex_string(const char *str,uint32_t str_length);
661
 
  enum Type type() const { return VARBIN_ITEM; }
662
 
  double val_real()
663
 
  {
664
 
    assert(fixed == 1);
665
 
    return (double) (uint64_t) Item_hex_string::val_int();
666
 
  }
667
 
  int64_t val_int();
668
 
  bool basic_const_item() const { return 1; }
669
 
  String *val_str(String*) { assert(fixed == 1); return &str_value; }
670
 
  my_decimal *val_decimal(my_decimal *);
671
 
  int save_in_field(Field *field, bool no_conversions);
672
 
  enum Item_result result_type () const { return STRING_RESULT; }
673
 
  enum Item_result cast_to_int_type() const { return INT_RESULT; }
674
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_VARCHAR; }
675
 
  virtual void print(String *str, enum_query_type query_type);
676
 
  bool eq(const Item *item, bool binary_cmp) const;
677
 
  virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
678
 
  bool check_vcol_func_processor(unsigned char *)
679
 
  { return false; }
680
 
};
681
 
 
682
 
 
683
 
class Item_bin_string: public Item_hex_string
684
 
{
685
 
public:
686
 
  Item_bin_string(const char *str,uint32_t str_length);
687
 
};
688
 
 
689
 
class Item_result_field :public Item    /* Item with result field */
690
 
{
691
 
public:
692
 
  Field *result_field;                          /* Save result here */
693
 
  Item_result_field() :result_field(0) {}
694
 
  // Constructor used for Item_sum/Item_cond_and/or (see Item comment)
695
 
  Item_result_field(Session *session, Item_result_field *item):
696
 
    Item(session, item), result_field(item->result_field)
697
 
  {}
698
 
  ~Item_result_field() {}                       /* Required with gcc 2.95 */
699
 
  Field *get_tmp_table_field() { return result_field; }
700
 
  Field *tmp_table_field(Table *)
701
 
  { return result_field; }
702
 
  table_map used_tables() const { return 1; }
703
 
  virtual void fix_length_and_dec()=0;
704
 
  void set_result_field(Field *field) { result_field= field; }
705
 
  bool is_result_field() { return 1; }
706
 
  void save_in_result_field(bool no_conversions)
707
 
  {
708
 
    save_in_field(result_field, no_conversions);
709
 
  }
710
 
  void cleanup();
711
 
  bool check_vcol_func_processor(unsigned char *)
712
 
  { return false; }
713
 
};
714
 
 
715
 
 
716
 
class Item_ref :public Item_ident
717
 
{
718
 
protected:
719
 
  void set_properties();
720
 
public:
721
 
  enum Ref_Type { REF, DIRECT_REF, OUTER_REF };
722
 
  Field *result_field;                   /* Save result here */
723
 
  Item **ref;
724
 
  Item_ref(Name_resolution_context *context_arg,
725
 
           const char *db_arg, const char *table_name_arg,
726
 
           const char *field_name_arg)
727
 
    :Item_ident(context_arg, db_arg, table_name_arg, field_name_arg),
728
 
     result_field(0), ref(0) {}
729
 
  /*
730
 
    This constructor is used in two scenarios:
731
 
    A) *item = NULL
732
 
      No initialization is performed, fix_fields() call will be necessary.
733
 
 
734
 
    B) *item points to an Item this Item_ref will refer to. This is
735
 
      used for GROUP BY. fix_fields() will not be called in this case,
736
 
      so we call set_properties to make this item "fixed". set_properties
737
 
      performs a subset of action Item_ref::fix_fields does, and this subset
738
 
      is enough for Item_ref's used in GROUP BY.
739
 
 
740
 
    TODO we probably fix a superset of problems like in BUG#6658. Check this
741
 
         with Bar, and if we have a more broader set of problems like this.
742
 
  */
743
 
  Item_ref(Name_resolution_context *context_arg, Item **item,
744
 
           const char *table_name_arg, const char *field_name_arg,
745
 
           bool alias_name_used_arg= false);
746
 
 
747
 
  /* Constructor need to process subselect with temporary tables (see Item) */
748
 
  Item_ref(Session *session, Item_ref *item)
749
 
    :Item_ident(session, item), result_field(item->result_field), ref(item->ref) {}
750
 
  enum Type type() const                { return REF_ITEM; }
751
 
  bool eq(const Item *item, bool binary_cmp) const
752
 
  {
753
 
    Item *it= ((Item *) item)->real_item();
754
 
    return ref && (*ref)->eq(it, binary_cmp);
755
 
  }
756
 
  double val_real();
757
 
  int64_t val_int();
758
 
  my_decimal *val_decimal(my_decimal *);
759
 
  bool val_bool();
760
 
  String *val_str(String* tmp);
761
 
  bool is_null();
762
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
763
 
  double val_result();
764
 
  int64_t val_int_result();
765
 
  String *str_result(String* tmp);
766
 
  my_decimal *val_decimal_result(my_decimal *);
767
 
  bool val_bool_result();
768
 
  bool send(Protocol *prot, String *tmp);
769
 
  void make_field(Send_field *field);
770
 
  bool fix_fields(Session *, Item **);
771
 
  void fix_after_pullout(st_select_lex *new_parent, Item **ref);
772
 
  int save_in_field(Field *field, bool no_conversions);
773
 
  void save_org_in_field(Field *field);
774
 
  enum Item_result result_type () const { return (*ref)->result_type(); }
775
 
  enum_field_types field_type() const   { return (*ref)->field_type(); }
776
 
  Field *get_tmp_table_field()
777
 
  { return result_field ? result_field : (*ref)->get_tmp_table_field(); }
778
 
  Item *get_tmp_table_item(Session *session);
779
 
  table_map used_tables() const
780
 
  {
781
 
    return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
782
 
  }
783
 
  void update_used_tables()
784
 
  {
785
 
    if (!depended_from)
786
 
      (*ref)->update_used_tables();
787
 
  }
788
 
  table_map not_null_tables() const { return (*ref)->not_null_tables(); }
789
 
  void set_result_field(Field *field)   { result_field= field; }
790
 
  bool is_result_field() { return 1; }
791
 
  void save_in_result_field(bool no_conversions)
792
 
  {
793
 
    (*ref)->save_in_field(result_field, no_conversions);
794
 
  }
795
 
  Item *real_item()
796
 
  {
797
 
    return ref ? (*ref)->real_item() : this;
798
 
  }
799
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
800
 
  { return (*ref)->walk(processor, walk_subquery, arg); }
801
 
  virtual void print(String *str, enum_query_type query_type);
802
 
  bool result_as_int64_t()
803
 
  {
804
 
    return (*ref)->result_as_int64_t();
805
 
  }
806
 
  void cleanup();
807
 
  Item_field *filed_for_view_update()
808
 
    { return (*ref)->filed_for_view_update(); }
809
 
  virtual Ref_Type ref_type() { return REF; }
810
 
 
811
 
  // Row emulation: forwarding of ROW-related calls to ref
812
 
  uint32_t cols()
813
 
  {
814
 
    return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
815
 
  }
816
 
  Item* element_index(uint32_t i)
817
 
  {
818
 
    return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
819
 
  }
820
 
  Item** addr(uint32_t i)
821
 
  {
822
 
    return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
823
 
  }
824
 
  bool check_cols(uint32_t c)
825
 
  {
826
 
    return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
827
 
                                              : Item::check_cols(c);
828
 
  }
829
 
  bool null_inside()
830
 
  {
831
 
    return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
832
 
  }
833
 
  void bring_value()
834
 
  {
835
 
    if (ref && result_type() == ROW_RESULT)
836
 
      (*ref)->bring_value();
837
 
  }
838
 
 
839
 
};
840
 
 
841
 
 
842
 
/*
843
 
  The same as Item_ref, but get value from val_* family of method to get
844
 
  value of item on which it referred instead of result* family.
845
 
*/
846
 
class Item_direct_ref :public Item_ref
847
 
{
848
 
public:
849
 
  Item_direct_ref(Name_resolution_context *context_arg, Item **item,
850
 
                  const char *table_name_arg,
851
 
                  const char *field_name_arg,
852
 
                  bool alias_name_used_arg= false)
853
 
    :Item_ref(context_arg, item, table_name_arg,
854
 
              field_name_arg, alias_name_used_arg)
855
 
  {}
856
 
  /* Constructor need to process subselect with temporary tables (see Item) */
857
 
  Item_direct_ref(Session *session, Item_direct_ref *item) : Item_ref(session, item) {}
858
 
 
859
 
  double val_real();
860
 
  int64_t val_int();
861
 
  String *val_str(String* tmp);
862
 
  my_decimal *val_decimal(my_decimal *);
863
 
  bool val_bool();
864
 
  bool is_null();
865
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
866
 
  virtual Ref_Type ref_type() { return DIRECT_REF; }
867
 
};
868
 
 
869
 
/*
870
 
  Class for outer fields.
871
 
  An object of this class is created when the select where the outer field was
872
 
  resolved is a grouping one. After it has been fixed the ref field will point
873
 
  to either an Item_ref or an Item_direct_ref object which will be used to
874
 
  access the field.
875
 
  See also comments for the fix_inner_refs() and the
876
 
  Item_field::fix_outer_field() functions.
877
 
*/
878
 
 
879
 
class Item_outer_ref :public Item_direct_ref
880
 
{
881
 
public:
882
 
  Item *outer_ref;
883
 
  /* The aggregate function under which this outer ref is used, if any. */
884
 
  Item_sum *in_sum_func;
885
 
  /*
886
 
    true <=> that the outer_ref is already present in the select list
887
 
    of the outer select.
888
 
  */
889
 
  bool found_in_select_list;
890
 
  Item_outer_ref(Name_resolution_context *context_arg,
891
 
                 Item_field *outer_field_arg)
892
 
    :Item_direct_ref(context_arg, 0, outer_field_arg->table_name,
893
 
                     outer_field_arg->field_name),
894
 
    outer_ref(outer_field_arg), in_sum_func(0),
895
 
    found_in_select_list(0)
896
 
  {
897
 
    ref= &outer_ref;
898
 
    set_properties();
899
 
    fixed= 0;
900
 
  }
901
 
  Item_outer_ref(Name_resolution_context *context_arg, Item **item,
902
 
                 const char *table_name_arg, const char *field_name_arg,
903
 
                 bool alias_name_used_arg)
904
 
    :Item_direct_ref(context_arg, item, table_name_arg, field_name_arg,
905
 
                     alias_name_used_arg),
906
 
    outer_ref(0), in_sum_func(0), found_in_select_list(1)
907
 
  {}
908
 
  void save_in_result_field(bool)
909
 
  {
910
 
    outer_ref->save_org_in_field(result_field);
911
 
  }
912
 
  bool fix_fields(Session *, Item **);
913
 
  void fix_after_pullout(st_select_lex *new_parent, Item **ref);
914
 
  table_map used_tables() const
915
 
  {
916
 
    return (*ref)->const_item() ? 0 : OUTER_REF_TABLE_BIT;
917
 
  }
918
 
  virtual Ref_Type ref_type() { return OUTER_REF; }
919
 
};
920
 
 
921
 
 
922
 
 
923
 
/*
924
 
  An object of this class:
925
 
   - Converts val_XXX() calls to ref->val_XXX_result() calls, like Item_ref.
926
 
   - Sets owner->was_null=true if it has returned a NULL value from any
927
 
     val_XXX() function. This allows to inject an Item_ref_null_helper
928
 
     object into subquery and then check if the subquery has produced a row
929
 
     with NULL value.
930
 
*/
931
 
 
932
 
class Item_ref_null_helper: public Item_ref
933
 
{
934
 
protected:
935
 
  Item_in_subselect* owner;
936
 
public:
937
 
  Item_ref_null_helper(Name_resolution_context *context_arg,
938
 
                       Item_in_subselect* master, Item **item,
939
 
                       const char *table_name_arg, const char *field_name_arg)
940
 
    :Item_ref(context_arg, item, table_name_arg, field_name_arg),
941
 
     owner(master) {}
942
 
  double val_real();
943
 
  int64_t val_int();
944
 
  String* val_str(String* s);
945
 
  my_decimal *val_decimal(my_decimal *);
946
 
  bool val_bool();
947
 
  bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate);
948
 
  virtual void print(String *str, enum_query_type query_type);
949
 
  /*
950
 
    we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
951
 
  */
952
 
  table_map used_tables() const
953
 
  {
954
 
    return (depended_from ?
955
 
            OUTER_REF_TABLE_BIT :
956
 
            (*ref)->used_tables() | RAND_TABLE_BIT);
957
 
  }
958
 
};
959
 
 
960
 
/*
961
 
  The following class is used to optimize comparing of date and bigint columns
962
 
  We need to save the original item ('ref') to be able to call
963
 
  ref->save_in_field(). This is used to create index search keys.
964
 
 
965
 
  An instance of Item_int_with_ref may have signed or unsigned integer value.
966
 
 
967
 
*/
968
 
 
969
 
class Item_int_with_ref :public Item_int
970
 
{
971
 
  Item *ref;
972
 
public:
973
 
  Item_int_with_ref(int64_t i, Item *ref_arg, bool unsigned_arg) :
974
 
    Item_int(i), ref(ref_arg)
975
 
  {
976
 
    unsigned_flag= unsigned_arg;
977
 
  }
978
 
  int save_in_field(Field *field, bool no_conversions)
979
 
  {
980
 
    return ref->save_in_field(field, no_conversions);
981
 
  }
982
 
  Item *clone_item();
983
 
  virtual Item *real_item() { return ref; }
984
 
};
985
 
 
986
 
 
987
 
class Item_copy_string :public Item
988
 
{
989
 
  enum enum_field_types cached_field_type;
990
 
public:
991
 
  Item *item;
992
 
  Item_copy_string(Item *i) :item(i)
993
 
  {
994
 
    null_value= maybe_null= item->maybe_null;
995
 
    decimals=item->decimals;
996
 
    max_length=item->max_length;
997
 
    name=item->name;
998
 
    cached_field_type= item->field_type();
999
 
  }
1000
 
  enum Type type() const { return COPY_STR_ITEM; }
1001
 
  enum Item_result result_type () const { return STRING_RESULT; }
1002
 
  enum_field_types field_type() const { return cached_field_type; }
1003
 
  double val_real()
1004
 
  {
1005
 
    int err_not_used;
1006
 
    char *end_not_used;
1007
 
    return (null_value ? 0.0 :
1008
 
            my_strntod(str_value.charset(), (char*) str_value.ptr(),
1009
 
                       str_value.length(), &end_not_used, &err_not_used));
1010
 
  }
1011
 
  int64_t val_int()
1012
 
  {
1013
 
    int err;
1014
 
    return null_value ? 0 : my_strntoll(str_value.charset(),str_value.ptr(),
1015
 
                                        str_value.length(),10, (char**) 0,
1016
 
                                        &err);
1017
 
  }
1018
 
  String *val_str(String*);
1019
 
  my_decimal *val_decimal(my_decimal *);
1020
 
  void make_field(Send_field *field) { item->make_field(field); }
1021
 
  void copy();
1022
 
  int save_in_field(Field *field, bool)
1023
 
  {
1024
 
    return save_str_value_in_field(field, &str_value);
1025
 
  }
1026
 
  table_map used_tables() const { return (table_map) 1L; }
1027
 
  bool const_item() const { return 0; }
1028
 
  bool is_null() { return null_value; }
1029
 
};
1030
 
class Item_default_value : public Item_field
1031
 
{
1032
 
public:
1033
 
  Item *arg;
1034
 
  Item_default_value(Name_resolution_context *context_arg)
1035
 
    :Item_field(context_arg, (const char *)NULL, (const char *)NULL,
1036
 
               (const char *)NULL),
1037
 
     arg(NULL) {}
1038
 
  Item_default_value(Name_resolution_context *context_arg, Item *a)
1039
 
    :Item_field(context_arg, (const char *)NULL, (const char *)NULL,
1040
 
                (const char *)NULL),
1041
 
     arg(a) {}
1042
 
  enum Type type() const { return DEFAULT_VALUE_ITEM; }
1043
 
  bool eq(const Item *item, bool binary_cmp) const;
1044
 
  bool fix_fields(Session *, Item **);
1045
 
  virtual void print(String *str, enum_query_type query_type);
1046
 
  int save_in_field(Field *field_arg, bool no_conversions);
1047
 
  table_map used_tables() const { return (table_map)0L; }
1048
 
 
1049
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
1050
 
  {
1051
 
    return arg->walk(processor, walk_subquery, args) ||
1052
 
      (this->*processor)(args);
1053
 
  }
1054
 
 
1055
 
  Item *transform(Item_transformer transformer, unsigned char *args);
1056
 
};
1057
 
 
1058
 
/*
1059
 
  Item_insert_value -- an implementation of VALUES() function.
1060
 
  You can use the VALUES(col_name) function in the UPDATE clause
1061
 
  to refer to column values from the INSERT portion of the INSERT
1062
 
  ... UPDATE statement. In other words, VALUES(col_name) in the
1063
 
  UPDATE clause refers to the value of col_name that would be
1064
 
  inserted, had no duplicate-key conflict occurred.
1065
 
  In all other places this function returns NULL.
1066
 
*/
1067
 
 
1068
 
class Item_insert_value : public Item_field
1069
 
{
1070
 
public:
1071
 
  Item *arg;
1072
 
  Item_insert_value(Name_resolution_context *context_arg, Item *a)
1073
 
    :Item_field(context_arg, (const char *)NULL, (const char *)NULL,
1074
 
               (const char *)NULL),
1075
 
     arg(a) {}
1076
 
  bool eq(const Item *item, bool binary_cmp) const;
1077
 
  bool fix_fields(Session *, Item **);
1078
 
  virtual void print(String *str, enum_query_type query_type);
1079
 
  int save_in_field(Field *field_arg, bool no_conversions)
1080
 
  {
1081
 
    return Item_field::save_in_field(field_arg, no_conversions);
1082
 
  }
1083
 
  /*
1084
 
   We use RAND_TABLE_BIT to prevent Item_insert_value from
1085
 
   being treated as a constant and precalculated before execution
1086
 
  */
1087
 
  table_map used_tables() const { return RAND_TABLE_BIT; }
1088
 
 
1089
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
1090
 
  {
1091
 
    return arg->walk(processor, walk_subquery, args) ||
1092
 
            (this->*processor)(args);
1093
 
  }
1094
 
  bool check_vcol_func_processor(unsigned char *)
1095
 
  { return true; }
1096
 
};
1097
 
 
1098
 
 
1099
 
class Item_cache: public Item_basic_constant
1100
 
{
1101
 
protected:
1102
 
  Item *example;
1103
 
  table_map used_table_map;
1104
 
  /*
1105
 
    Field that this object will get value from. This is set/used by
1106
 
    index-based subquery engines to detect and remove the equality injected
1107
 
    by IN->EXISTS transformation.
1108
 
    For all other uses of Item_cache, cached_field doesn't matter.
1109
 
  */
1110
 
  Field *cached_field;
1111
 
  enum enum_field_types cached_field_type;
1112
 
public:
1113
 
  Item_cache():
1114
 
    example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR)
1115
 
  {
1116
 
    fixed= 1;
1117
 
    null_value= 1;
1118
 
  }
1119
 
  Item_cache(enum_field_types field_type_arg):
1120
 
    example(0), used_table_map(0), cached_field(0), cached_field_type(field_type_arg)
1121
 
  {
1122
 
    fixed= 1;
1123
 
    null_value= 1;
1124
 
  }
1125
 
 
1126
 
  void set_used_tables(table_map map) { used_table_map= map; }
1127
 
 
1128
 
  virtual bool allocate(uint32_t)
1129
 
  { return 0; }
1130
 
  virtual bool setup(Item *item)
1131
 
  {
1132
 
    example= item;
1133
 
    max_length= item->max_length;
1134
 
    decimals= item->decimals;
1135
 
    collation.set(item->collation);
1136
 
    unsigned_flag= item->unsigned_flag;
1137
 
    if (item->type() == FIELD_ITEM)
1138
 
      cached_field= ((Item_field *)item)->field;
1139
 
    return 0;
1140
 
  };
1141
 
  virtual void store(Item *)= 0;
1142
 
  enum Type type() const { return CACHE_ITEM; }
1143
 
  enum_field_types field_type() const { return cached_field_type; }
1144
 
  static Item_cache* get_cache(const Item *item);
1145
 
  table_map used_tables() const { return used_table_map; }
1146
 
  virtual void keep_array() {}
1147
 
  virtual void print(String *str, enum_query_type query_type);
1148
 
  bool eq_def(Field *field);
1149
 
  bool eq(const Item *item, bool) const
1150
 
  {
1151
 
    return this == item;
1152
 
  }
1153
 
};
1154
 
 
1155
 
 
1156
 
class Item_cache_int: public Item_cache
1157
 
{
1158
 
protected:
1159
 
  int64_t value;
1160
 
public:
1161
 
  Item_cache_int(): Item_cache(), value(0) {}
1162
 
  Item_cache_int(enum_field_types field_type_arg):
1163
 
    Item_cache(field_type_arg), value(0) {}
1164
 
 
1165
 
  void store(Item *item);
1166
 
  void store(Item *item, int64_t val_arg);
1167
 
  double val_real() { assert(fixed == 1); return (double) value; }
1168
 
  int64_t val_int() { assert(fixed == 1); return value; }
1169
 
  String* val_str(String *str);
1170
 
  my_decimal *val_decimal(my_decimal *);
1171
 
  enum Item_result result_type() const { return INT_RESULT; }
1172
 
  bool result_as_int64_t() { return true; }
1173
 
};
1174
 
 
1175
 
 
1176
 
class Item_cache_real: public Item_cache
1177
 
{
1178
 
  double value;
1179
 
public:
1180
 
  Item_cache_real(): Item_cache(), value(0) {}
1181
 
 
1182
 
  void store(Item *item);
1183
 
  double val_real() { assert(fixed == 1); return value; }
1184
 
  int64_t val_int();
1185
 
  String* val_str(String *str);
1186
 
  my_decimal *val_decimal(my_decimal *);
1187
 
  enum Item_result result_type() const { return REAL_RESULT; }
1188
 
};
1189
 
 
1190
 
 
1191
 
class Item_cache_decimal: public Item_cache
1192
 
{
1193
 
protected:
1194
 
  my_decimal decimal_value;
1195
 
public:
1196
 
  Item_cache_decimal(): Item_cache() {}
1197
 
 
1198
 
  void store(Item *item);
1199
 
  double val_real();
1200
 
  int64_t val_int();
1201
 
  String* val_str(String *str);
1202
 
  my_decimal *val_decimal(my_decimal *);
1203
 
  enum Item_result result_type() const { return DECIMAL_RESULT; }
1204
 
};
1205
 
 
1206
 
 
1207
 
class Item_cache_str: public Item_cache
1208
 
{
1209
 
  char buffer[STRING_BUFFER_USUAL_SIZE];
1210
 
  String *value, value_buff;
1211
 
  bool is_varbinary;
1212
 
 
1213
 
public:
1214
 
  Item_cache_str(const Item *item);
1215
 
  void store(Item *item);
1216
 
  double val_real();
1217
 
  int64_t val_int();
1218
 
  String* val_str(String *) { assert(fixed == 1); return value; }
1219
 
  my_decimal *val_decimal(my_decimal *);
1220
 
  enum Item_result result_type() const { return STRING_RESULT; }
1221
 
  const CHARSET_INFO *charset() const { return value->charset(); };
1222
 
  int save_in_field(Field *field, bool no_conversions);
1223
 
};
1224
 
 
1225
 
 
1226
 
 
1227
626
void mark_select_range_as_dependent(Session *session,
1228
627
                                    st_select_lex *last_select,
1229
628
                                    st_select_lex *current_sel,