612
623
st_select_lex *select);
615
class Item_blob :public Item_string
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; }
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
632
class Item_empty_string :public Item_string
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);
642
class Item_return_int :public Item_int
644
enum_field_types int_field_type;
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)
652
enum_field_types field_type() const { return int_field_type; }
656
class Item_hex_string: public Item_basic_constant
660
Item_hex_string(const char *str,uint32_t str_length);
661
enum Type type() const { return VARBIN_ITEM; }
665
return (double) (uint64_t) Item_hex_string::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 *)
683
class Item_bin_string: public Item_hex_string
686
Item_bin_string(const char *str,uint32_t str_length);
689
class Item_result_field :public Item /* Item with result field */
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)
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)
708
save_in_field(result_field, no_conversions);
711
bool check_vcol_func_processor(unsigned char *)
716
class Item_ref :public Item_ident
719
void set_properties();
721
enum Ref_Type { REF, DIRECT_REF, OUTER_REF };
722
Field *result_field; /* Save result here */
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) {}
730
This constructor is used in two scenarios:
732
No initialization is performed, fix_fields() call will be necessary.
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.
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.
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);
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
753
Item *it= ((Item *) item)->real_item();
754
return ref && (*ref)->eq(it, binary_cmp);
758
my_decimal *val_decimal(my_decimal *);
760
String *val_str(String* tmp);
762
bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
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
781
return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
783
void update_used_tables()
786
(*ref)->update_used_tables();
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)
793
(*ref)->save_in_field(result_field, no_conversions);
797
return ref ? (*ref)->real_item() : this;
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()
804
return (*ref)->result_as_int64_t();
807
Item_field *filed_for_view_update()
808
{ return (*ref)->filed_for_view_update(); }
809
virtual Ref_Type ref_type() { return REF; }
811
// Row emulation: forwarding of ROW-related calls to ref
814
return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1;
816
Item* element_index(uint32_t i)
818
return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this;
820
Item** addr(uint32_t i)
822
return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0;
824
bool check_cols(uint32_t c)
826
return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c)
827
: Item::check_cols(c);
831
return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0;
835
if (ref && result_type() == ROW_RESULT)
836
(*ref)->bring_value();
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.
846
class Item_direct_ref :public Item_ref
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)
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) {}
861
String *val_str(String* tmp);
862
my_decimal *val_decimal(my_decimal *);
865
bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
866
virtual Ref_Type ref_type() { return DIRECT_REF; }
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
875
See also comments for the fix_inner_refs() and the
876
Item_field::fix_outer_field() functions.
879
class Item_outer_ref :public Item_direct_ref
883
/* The aggregate function under which this outer ref is used, if any. */
884
Item_sum *in_sum_func;
886
true <=> that the outer_ref is already present in the select list
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)
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)
908
void save_in_result_field(bool)
910
outer_ref->save_org_in_field(result_field);
912
bool fix_fields(Session *, Item **);
913
void fix_after_pullout(st_select_lex *new_parent, Item **ref);
914
table_map used_tables() const
916
return (*ref)->const_item() ? 0 : OUTER_REF_TABLE_BIT;
918
virtual Ref_Type ref_type() { return OUTER_REF; }
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
932
class Item_ref_null_helper: public Item_ref
935
Item_in_subselect* owner;
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),
944
String* val_str(String* s);
945
my_decimal *val_decimal(my_decimal *);
947
bool get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate);
948
virtual void print(String *str, enum_query_type query_type);
950
we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
952
table_map used_tables() const
954
return (depended_from ?
955
OUTER_REF_TABLE_BIT :
956
(*ref)->used_tables() | RAND_TABLE_BIT);
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.
965
An instance of Item_int_with_ref may have signed or unsigned integer value.
969
class Item_int_with_ref :public Item_int
973
Item_int_with_ref(int64_t i, Item *ref_arg, bool unsigned_arg) :
974
Item_int(i), ref(ref_arg)
976
unsigned_flag= unsigned_arg;
978
int save_in_field(Field *field, bool no_conversions)
980
return ref->save_in_field(field, no_conversions);
983
virtual Item *real_item() { return ref; }
987
class Item_copy_string :public Item
989
enum enum_field_types cached_field_type;
992
Item_copy_string(Item *i) :item(i)
994
null_value= maybe_null= item->maybe_null;
995
decimals=item->decimals;
996
max_length=item->max_length;
998
cached_field_type= item->field_type();
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; }
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));
1014
return null_value ? 0 : my_strntoll(str_value.charset(),str_value.ptr(),
1015
str_value.length(),10, (char**) 0,
1018
String *val_str(String*);
1019
my_decimal *val_decimal(my_decimal *);
1020
void make_field(Send_field *field) { item->make_field(field); }
1022
int save_in_field(Field *field, bool)
1024
return save_str_value_in_field(field, &str_value);
1026
table_map used_tables() const { return (table_map) 1L; }
1027
bool const_item() const { return 0; }
1028
bool is_null() { return null_value; }
1030
class Item_default_value : public Item_field
1034
Item_default_value(Name_resolution_context *context_arg)
1035
:Item_field(context_arg, (const char *)NULL, (const char *)NULL,
1036
(const char *)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),
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; }
1049
bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
1051
return arg->walk(processor, walk_subquery, args) ||
1052
(this->*processor)(args);
1055
Item *transform(Item_transformer transformer, unsigned char *args);
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.
1068
class Item_insert_value : public Item_field
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),
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)
1081
return Item_field::save_in_field(field_arg, no_conversions);
1084
We use RAND_TABLE_BIT to prevent Item_insert_value from
1085
being treated as a constant and precalculated before execution
1087
table_map used_tables() const { return RAND_TABLE_BIT; }
1089
bool walk(Item_processor processor, bool walk_subquery, unsigned char *args)
1091
return arg->walk(processor, walk_subquery, args) ||
1092
(this->*processor)(args);
1094
bool check_vcol_func_processor(unsigned char *)
1099
class Item_cache: public Item_basic_constant
1103
table_map used_table_map;
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.
1110
Field *cached_field;
1111
enum enum_field_types cached_field_type;
1114
example(0), used_table_map(0), cached_field(0), cached_field_type(DRIZZLE_TYPE_VARCHAR)
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)
1126
void set_used_tables(table_map map) { used_table_map= map; }
1128
virtual bool allocate(uint32_t)
1130
virtual bool setup(Item *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;
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
1151
return this == item;
1156
class Item_cache_int: public Item_cache
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) {}
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; }
1176
class Item_cache_real: public Item_cache
1180
Item_cache_real(): Item_cache(), value(0) {}
1182
void store(Item *item);
1183
double val_real() { assert(fixed == 1); return value; }
1185
String* val_str(String *str);
1186
my_decimal *val_decimal(my_decimal *);
1187
enum Item_result result_type() const { return REAL_RESULT; }
1191
class Item_cache_decimal: public Item_cache
1194
my_decimal decimal_value;
1196
Item_cache_decimal(): Item_cache() {}
1198
void store(Item *item);
1201
String* val_str(String *str);
1202
my_decimal *val_decimal(my_decimal *);
1203
enum Item_result result_type() const { return DECIMAL_RESULT; }
1207
class Item_cache_str: public Item_cache
1209
char buffer[STRING_BUFFER_USUAL_SIZE];
1210
String *value, value_buff;
1214
Item_cache_str(const Item *item);
1215
void store(Item *item);
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);
1227
626
void mark_select_range_as_dependent(Session *session,
1228
627
st_select_lex *last_select,
1229
628
st_select_lex *current_sel,