2 Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "mysql_priv.h"
21 Row items used for comparing rows and IN operations on rows:
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)
31 think placing 2-3 component items in item (as it done for function
34 Item_row::Item_row(List
<Item
> &arg
):
35 Item(), used_tables_cache(0), not_null_tables_cache(0),
36 const_item_cache(1), with_null(0)
39 //TODO: think placing 2-3 component items in item (as it done for function)
40 if ((arg_count
= arg
.elements
))
41 items
= (Item
**) sql_alloc(sizeof(Item
*)*arg_count
);
44 List_iterator
<Item
> li(arg
);
54 void Item_row::illegal_method_call(const char *method
)
56 DBUG_ENTER("Item_row::illegal_method_call");
57 DBUG_PRINT("error", ("!!! %s method was called for row item", method
));
59 my_error(ER_OPERAND_COLUMNS
, MYF(0), 1);
63 bool Item_row::fix_fields(THD
*thd
, Item
**ref
)
65 DBUG_ASSERT(fixed
== 0);
68 Item
**arg
, **arg_end
;
69 for (arg
= items
, arg_end
= items
+arg_count
; arg
!= arg_end
; arg
++)
71 if ((*arg
)->fix_fields(thd
, arg
))
73 // we can't assign 'item' before, because fix_fields() can change arg
75 used_tables_cache
|= item
->used_tables();
76 const_item_cache
&= item
->const_item() && !with_null
;
77 not_null_tables_cache
|= item
->not_null_tables();
82 with_null
|= item
->null_inside();
89 maybe_null
|= item
->maybe_null
;
90 with_sum_func
= with_sum_func
|| item
->with_sum_func
;
97 void Item_row::cleanup()
99 DBUG_ENTER("Item_row::cleanup");
102 /* Reset to the original values */
103 used_tables_cache
= 0;
111 void Item_row::split_sum_func(THD
*thd
, Item
**ref_pointer_array
,
114 Item
**arg
, **arg_end
;
115 for (arg
= items
, arg_end
= items
+arg_count
; arg
!= arg_end
; arg
++)
116 (*arg
)->split_sum_func2(thd
, ref_pointer_array
, fields
, arg
, TRUE
);
120 void Item_row::update_used_tables()
122 used_tables_cache
= 0;
124 for (uint i
= 0; i
< arg_count
; i
++)
126 items
[i
]->update_used_tables();
127 used_tables_cache
|= items
[i
]->used_tables();
128 const_item_cache
&= items
[i
]->const_item();
132 bool Item_row::check_cols(uint c
)
136 my_error(ER_OPERAND_COLUMNS
, MYF(0), c
);
142 void Item_row::print(String
*str
, enum_query_type query_type
)
145 for (uint i
= 0; i
< arg_count
; i
++)
149 items
[i
]->print(str
, query_type
);
155 bool Item_row::walk(Item_processor processor
, bool walk_subquery
, uchar
*arg
)
157 for (uint i
= 0; i
< arg_count
; i
++)
159 if (items
[i
]->walk(processor
, walk_subquery
, arg
))
162 return (this->*processor
)(arg
);
166 Item
*Item_row::transform(Item_transformer transformer
, uchar
*arg
)
168 DBUG_ASSERT(!current_thd
->is_stmt_prepare());
170 for (uint i
= 0; i
< arg_count
; i
++)
172 Item
*new_item
= items
[i
]->transform(transformer
, arg
);
177 THD::change_item_tree() should be called only if the tree was
178 really transformed, i.e. when a new item has been created.
179 Otherwise we'll be allocating a lot of unnecessary memory for
180 change records at each execution.
182 if (items
[i
] != new_item
)
183 current_thd
->change_item_tree(&items
[i
], new_item
);
185 return (this->*transformer
)(arg
);
188 void Item_row::bring_value()
190 for (uint i
= 0; i
< arg_count
; i
++)
191 items
[i
]->bring_value();