~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_row.cc

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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 */
 
15
 
 
16
#include "mysql_priv.h"
 
17
 
 
18
/**
 
19
  Row items used for comparing rows and IN operations on rows:
 
20
 
 
21
  @verbatim
 
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)
 
26
  @endverbatim
 
27
 
 
28
  @todo
 
29
    think placing 2-3 component items in item (as it done for function
 
30
*/
 
31
 
 
32
Item_row::Item_row(List<Item> &arg):
 
33
  Item(), used_tables_cache(0), const_item_cache(1), with_null(0)
 
34
{
 
35
 
 
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);
 
39
  else
 
40
    items= 0;
 
41
  List_iterator<Item> li(arg);
 
42
  uint i= 0;
 
43
  Item *item;
 
44
  while ((item= li++))
 
45
  {
 
46
    items[i]= item;
 
47
    i++;    
 
48
  }
 
49
}
 
50
 
 
51
void Item_row::illegal_method_call(const char *method)
 
52
{
 
53
  DBUG_ENTER("Item_row::illegal_method_call");
 
54
  DBUG_PRINT("error", ("!!! %s method was called for row item", method));
 
55
  DBUG_ASSERT(0);
 
56
  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
 
57
  DBUG_VOID_RETURN;
 
58
}
 
59
 
 
60
bool Item_row::fix_fields(THD *thd, Item **ref)
 
61
{
 
62
  DBUG_ASSERT(fixed == 0);
 
63
  null_value= 0;
 
64
  maybe_null= 0;
 
65
  Item **arg, **arg_end;
 
66
  for (arg= items, arg_end= items+arg_count; arg != arg_end ; arg++)
 
67
  {
 
68
    if ((*arg)->fix_fields(thd, arg))
 
69
      return TRUE;
 
70
    // we can't assign 'item' before, because fix_fields() can change arg
 
71
    Item *item= *arg;
 
72
    used_tables_cache |= item->used_tables();
 
73
    const_item_cache&= item->const_item() && !with_null;
 
74
    if (const_item_cache)
 
75
    {
 
76
      if (item->cols() > 1)
 
77
        with_null|= item->null_inside();
 
78
      else
 
79
      {
 
80
        if (item->is_null())
 
81
          with_null|= 1;
 
82
      }
 
83
    }
 
84
    maybe_null|= item->maybe_null;
 
85
    with_sum_func= with_sum_func || item->with_sum_func;
 
86
  }
 
87
  fixed= 1;
 
88
  return FALSE;
 
89
}
 
90
 
 
91
 
 
92
void Item_row::cleanup()
 
93
{
 
94
  DBUG_ENTER("Item_row::cleanup");
 
95
 
 
96
  Item::cleanup();
 
97
  /* Reset to the original values */
 
98
  used_tables_cache= 0;
 
99
  const_item_cache= 1;
 
100
  with_null= 0;
 
101
 
 
102
  DBUG_VOID_RETURN;
 
103
}
 
104
 
 
105
 
 
106
void Item_row::split_sum_func(THD *thd, Item **ref_pointer_array,
 
107
                              List<Item> &fields)
 
108
{
 
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);
 
112
}
 
113
 
 
114
 
 
115
void Item_row::update_used_tables()
 
116
{
 
117
  used_tables_cache= 0;
 
118
  const_item_cache= 1;
 
119
  for (uint i= 0; i < arg_count; i++)
 
120
  {
 
121
    items[i]->update_used_tables();
 
122
    used_tables_cache|= items[i]->used_tables();
 
123
    const_item_cache&= items[i]->const_item();
 
124
  }
 
125
}
 
126
 
 
127
void Item_row::fix_after_pullout(st_select_lex *new_parent, Item **ref)
 
128
{
 
129
  used_tables_cache= 0;
 
130
  const_item_cache= 1;
 
131
  for (uint i= 0; i < arg_count; i++)
 
132
  {
 
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();
 
136
  }
 
137
}
 
138
 
 
139
bool Item_row::check_cols(uint c)
 
140
{
 
141
  if (c != arg_count)
 
142
  {
 
143
    my_error(ER_OPERAND_COLUMNS, MYF(0), c);
 
144
    return 1;
 
145
  }
 
146
  return 0;
 
147
}
 
148
 
 
149
void Item_row::print(String *str, enum_query_type query_type)
 
150
{
 
151
  str->append('(');
 
152
  for (uint i= 0; i < arg_count; i++)
 
153
  {
 
154
    if (i)
 
155
      str->append(',');
 
156
    items[i]->print(str, query_type);
 
157
  }
 
158
  str->append(')');
 
159
}
 
160
 
 
161
 
 
162
bool Item_row::walk(Item_processor processor, bool walk_subquery, uchar *arg)
 
163
{
 
164
  for (uint i= 0; i < arg_count; i++)
 
165
  {
 
166
    if (items[i]->walk(processor, walk_subquery, arg))
 
167
      return 1;
 
168
  }
 
169
  return (this->*processor)(arg);
 
170
}
 
171
 
 
172
 
 
173
Item *Item_row::transform(Item_transformer transformer, uchar *arg)
 
174
{
 
175
  for (uint i= 0; i < arg_count; i++)
 
176
  {
 
177
    Item *new_item= items[i]->transform(transformer, arg);
 
178
    if (!new_item)
 
179
      return 0;
 
180
 
 
181
    /*
 
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.
 
186
    */
 
187
    if (items[i] != new_item)
 
188
      current_thd->change_item_tree(&items[i], new_item);
 
189
  }
 
190
  return (this->*transformer)(arg);
 
191
}
 
192
 
 
193
void Item_row::bring_value()
 
194
{
 
195
  for (uint i= 0; i < arg_count; i++)
 
196
    items[i]->bring_value();
 
197
}