mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / sql / item_row.cc
blob1db71da1a2192bc17e3160dc6eca13255ad27c8e
1 /*
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"
20 /**
21 Row items used for comparing rows and IN operations on rows:
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
30 @todo
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);
42 else
43 items= 0;
44 List_iterator<Item> li(arg);
45 uint i= 0;
46 Item *item;
47 while ((item= li++))
49 items[i]= item;
50 i++;
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));
58 DBUG_ASSERT(0);
59 my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
60 DBUG_VOID_RETURN;
63 bool Item_row::fix_fields(THD *thd, Item **ref)
65 DBUG_ASSERT(fixed == 0);
66 null_value= 0;
67 maybe_null= 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))
72 return TRUE;
73 // we can't assign 'item' before, because fix_fields() can change arg
74 Item *item= *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();
79 if (const_item_cache)
81 if (item->cols() > 1)
82 with_null|= item->null_inside();
83 else
85 if (item->is_null())
86 with_null|= 1;
89 maybe_null|= item->maybe_null;
90 with_sum_func= with_sum_func || item->with_sum_func;
92 fixed= 1;
93 return FALSE;
97 void Item_row::cleanup()
99 DBUG_ENTER("Item_row::cleanup");
101 Item::cleanup();
102 /* Reset to the original values */
103 used_tables_cache= 0;
104 const_item_cache= 1;
105 with_null= 0;
107 DBUG_VOID_RETURN;
111 void Item_row::split_sum_func(THD *thd, Item **ref_pointer_array,
112 List<Item> &fields)
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;
123 const_item_cache= 1;
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)
134 if (c != arg_count)
136 my_error(ER_OPERAND_COLUMNS, MYF(0), c);
137 return 1;
139 return 0;
142 void Item_row::print(String *str, enum_query_type query_type)
144 str->append('(');
145 for (uint i= 0; i < arg_count; i++)
147 if (i)
148 str->append(',');
149 items[i]->print(str, query_type);
151 str->append(')');
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))
160 return 1;
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);
173 if (!new_item)
174 return 0;
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();