1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
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 */
16
#include "mysql_priv.h"
19
Row items used for comparing rows and IN operations on rows:
22
(a, b, c) > (10, 10, 30)
23
(a, b, c) = (select c, d, e, from t1 where x=12)
24
(a, b, c) IN ((1,2,2), (3,4,5), (6,7,8)
25
(a, b, c) IN (select c, d, e, from t1)
29
think placing 2-3 component items in item (as it done for function
32
Item_row::Item_row(List<Item> &arg):
33
Item(), used_tables_cache(0), const_item_cache(1), with_null(0)
36
//TODO: think placing 2-3 component items in item (as it done for function)
37
if ((arg_count= arg.elements))
38
items= (Item**) sql_alloc(sizeof(Item*)*arg_count);
41
List_iterator<Item> li(arg);
51
void Item_row::illegal_method_call(const char *method)
53
DBUG_ENTER("Item_row::illegal_method_call");
54
DBUG_PRINT("error", ("!!! %s method was called for row item", method));
56
my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
60
bool Item_row::fix_fields(THD *thd, Item **ref)
62
DBUG_ASSERT(fixed == 0);
65
Item **arg, **arg_end;
66
for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
68
if ((*arg)->fix_fields(thd, arg))
70
// we can't assign 'item' before, because fix_fields() can change arg
72
used_tables_cache |= item->used_tables();
73
const_item_cache&= item->const_item() && !with_null;
77
with_null|= item->null_inside();
84
maybe_null|= item->maybe_null;
85
with_sum_func= with_sum_func || item->with_sum_func;
92
void Item_row::cleanup()
94
DBUG_ENTER("Item_row::cleanup");
97
/* Reset to the original values */
106
void Item_row::split_sum_func(THD *thd, Item **ref_pointer_array,
109
Item **arg, **arg_end;
110
for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
111
(*arg)->split_sum_func2(thd, ref_pointer_array, fields, arg, TRUE);
115
void Item_row::update_used_tables()
117
used_tables_cache= 0;
119
for (uint i= 0; i < arg_count; i++)
121
items[i]->update_used_tables();
122
used_tables_cache|= items[i]->used_tables();
123
const_item_cache&= items[i]->const_item();
127
void Item_row::fix_after_pullout(st_select_lex *new_parent, Item **ref)
129
used_tables_cache= 0;
131
for (uint i= 0; i < arg_count; i++)
133
items[i]->fix_after_pullout(new_parent, &items[i]);
134
used_tables_cache|= items[i]->used_tables();
135
const_item_cache&= items[i]->const_item();
139
bool Item_row::check_cols(uint c)
143
my_error(ER_OPERAND_COLUMNS, MYF(0), c);
149
void Item_row::print(String *str, enum_query_type query_type)
152
for (uint i= 0; i < arg_count; i++)
156
items[i]->print(str, query_type);
162
bool Item_row::walk(Item_processor processor, bool walk_subquery, uchar *arg)
164
for (uint i= 0; i < arg_count; i++)
166
if (items[i]->walk(processor, walk_subquery, arg))
169
return (this->*processor)(arg);
173
Item *Item_row::transform(Item_transformer transformer, uchar *arg)
175
for (uint i= 0; i < arg_count; i++)
177
Item *new_item= items[i]->transform(transformer, arg);
182
THD::change_item_tree() should be called only if the tree was
183
really transformed, i.e. when a new item has been created.
184
Otherwise we'll be allocating a lot of unnecessary memory for
185
change records at each execution.
187
if (items[i] != new_item)
188
current_thd->change_item_tree(&items[i], new_item);
190
return (this->*transformer)(arg);
193
void Item_row::bring_value()
195
for (uint i= 0; i < arg_count; i++)
196
items[i]->bring_value();