1#ifndef ITEM_ROW_INCLUDED
2#define ITEM_ROW_INCLUDED
3
4/*
5 Copyright (c) 2002, 2013, Oracle and/or its affiliates.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; version 2 of the License.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
19
20/**
21 Row items used for comparing rows and IN operations on rows:
22
23 @verbatim
24 (a, b, c) > (10, 10, 30)
25 (a, b, c) = (select c, d, e, from t1 where x=12)
26 (a, b, c) IN ((1,2,2), (3,4,5), (6,7,8)
27 (a, b, c) IN (select c, d, e, from t1)
28 @endverbatim
29*/
30
31
32/**
33 Item which stores (x,y,...) and ROW(x,y,...).
34 Note that this can be recursive: ((x,y),(z,t)) is a ROW of ROWs.
35*/
36class Item_row: public Item,
37 private Item_args,
38 private Used_tables_and_const_cache,
39 private With_subquery_cache
40{
41 table_map not_null_tables_cache;
42 /**
43 If elements are made only of constants, of which one or more are
44 NULL. For example, this item is (1,2,NULL), or ( (1,NULL), (2,3) ).
45 */
46 bool with_null;
47public:
48 Item_row(THD *thd, List<Item> &list):
49 Item(thd), Item_args(thd, list), not_null_tables_cache(0), with_null(0)
50 { }
51 Item_row(THD *thd, Item_row *row):
52 Item(thd), Item_args(thd, static_cast<Item_args*>(row)), Used_tables_and_const_cache(),
53 not_null_tables_cache(0), with_null(0)
54 { }
55
56 bool with_subquery() const { DBUG_ASSERT(fixed); return m_with_subquery; }
57 enum Type type() const { return ROW_ITEM; };
58 const Type_handler *type_handler() const { return &type_handler_row; }
59 void illegal_method_call(const char *);
60 bool is_null() { return null_value; }
61 void make_send_field(THD *thd, Send_field *)
62 {
63 illegal_method_call((const char*)"make_send_field");
64 };
65 double val_real()
66 {
67 illegal_method_call((const char*)"val");
68 return 0;
69 };
70 longlong val_int()
71 {
72 illegal_method_call((const char*)"val_int");
73 return 0;
74 };
75 String *val_str(String *)
76 {
77 illegal_method_call((const char*)"val_str");
78 return 0;
79 };
80 my_decimal *val_decimal(my_decimal *)
81 {
82 illegal_method_call((const char*)"val_decimal");
83 return 0;
84 };
85 bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
86 {
87 illegal_method_call((const char*)"get_date");
88 return true;
89 }
90 bool fix_fields(THD *thd, Item **ref);
91 void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge);
92 void cleanup();
93 void split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array,
94 List<Item> &fields, uint flags);
95 table_map used_tables() const { return used_tables_cache; };
96 bool const_item() const { return const_item_cache; };
97 void update_used_tables()
98 {
99 used_tables_and_const_cache_init();
100 used_tables_and_const_cache_update_and_join(arg_count, args);
101 }
102 table_map not_null_tables() const { return not_null_tables_cache; }
103 virtual void print(String *str, enum_query_type query_type);
104
105 bool walk(Item_processor processor, bool walk_subquery, void *arg)
106 {
107 if (walk_args(processor, walk_subquery, arg))
108 return true;
109 return (this->*processor)(arg);
110 }
111 Item *transform(THD *thd, Item_transformer transformer, uchar *arg);
112 bool eval_not_null_tables(void *opt_arg);
113
114 uint cols() const { return arg_count; }
115 Item* element_index(uint i) { return args[i]; }
116 Item** addr(uint i) { return args + i; }
117 bool check_cols(uint c);
118 bool null_inside() { return with_null; };
119 void bring_value();
120
121 Item* propagate_equal_fields(THD *thd, const Context &ctx, COND_EQUAL *cond)
122 {
123 Item_args::propagate_equal_fields(thd, Context_identity(), cond);
124 return this;
125 }
126
127 bool excl_dep_on_table(table_map tab_map)
128 {
129 return Item_args::excl_dep_on_table(tab_map);
130 }
131
132 bool excl_dep_on_grouping_fields(st_select_lex *sel)
133 {
134 return Item_args::excl_dep_on_grouping_fields(sel);
135 }
136
137 bool check_vcol_func_processor(void *arg) {return FALSE; }
138 Item *get_copy(THD *thd)
139 { return get_item_copy<Item_row>(thd, this); }
140 Item *build_clone(THD *thd);
141};
142
143#endif /* ITEM_ROW_INCLUDED */
144