File: item_row.cc

package info (click to toggle)
mysql-8.0 8.0.44-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,272,892 kB
  • sloc: cpp: 4,685,345; ansic: 412,712; pascal: 108,395; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; python: 21,816; sh: 17,285; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,083; makefile: 1,793; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (212 lines) | stat: -rw-r--r-- 6,676 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* Copyright (c) 2002, 2025, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is designed to work with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have either included with
   the program or referenced in the documentation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#include "sql/item_row.h"

#include "my_alloc.h"  // MEM_ROOT
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_sys.h"
#include "mysqld_error.h"
#include "sql/current_thd.h"
#include "sql/sql_class.h"  // THD
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/thr_malloc.h"
#include "sql_string.h"

struct Parse_context;

Item_row::Item_row(const POS &pos, Item *head,
                   const mem_root_deque<Item *> &tail)
    : super(pos),
      used_tables_cache(0),
      not_null_tables_cache(0),
      with_null(false) {
  set_data_type(MYSQL_TYPE_INVALID);
  arg_count = 1 + tail.size();
  items = (*THR_MALLOC)->ArrayAlloc<Item *>(arg_count);
  if (items == nullptr) {
    arg_count = 0;
    return;  // OOM
  }
  items[0] = head;
  uint i = 1;
  for (Item *item : tail) {
    items[i++] = item;
  }
}

Item_row::Item_row(Item *head, const mem_root_deque<Item *> &tail)
    : used_tables_cache(0), not_null_tables_cache(0), with_null(false) {
  set_data_type(MYSQL_TYPE_INVALID);
  // TODO: think placing 2-3 component items in item (as it done for function)
  arg_count = 1 + tail.size();
  items = (*THR_MALLOC)->ArrayAlloc<Item *>(arg_count);
  if (items == nullptr) {
    arg_count = 0;
    return;  // OOM
  }
  items[0] = head;
  uint i = 1;
  for (Item *item : tail) {
    items[i] = item;
    i++;
  }
}

bool Item_row::itemize(Parse_context *pc, Item **res) {
  if (skip_itemize(res)) return false;
  if (super::itemize(pc, res)) return true;
  for (uint i = 0; i < arg_count; i++) {
    if (items[i]->itemize(pc, &items[i])) return true;
    add_accum_properties(items[i]);
  }
  return false;
}

void Item_row::illegal_method_call(const char *method [[maybe_unused]]) const {
  DBUG_TRACE;
  DBUG_PRINT("error", ("!!! %s method was called for row item", method));
  assert(0);
  my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
}

bool Item_row::fix_fields(THD *thd, Item **) {
  assert(fixed == 0);
  null_value = false;
  set_nullable(false);
  bool types_assigned = true;
  Item **arg, **arg_end;
  for (arg = items, arg_end = items + arg_count; arg != arg_end; arg++) {
    if ((!(*arg)->fixed && (*arg)->fix_fields(thd, arg))) return true;
    // we can't assign 'item' before, because fix_fields() can change arg
    Item *item = *arg;
    used_tables_cache |= item->used_tables();
    not_null_tables_cache |= item->not_null_tables();

    types_assigned &= item->data_type() != MYSQL_TYPE_INVALID;

    if (const_item() && !thd->lex->is_view_context_analysis()) {
      if (item->cols() > 1)
        with_null |= item->null_inside();
      else
        with_null |= item->is_null();
    }

    // item->is_null() may have raised an error.
    if (thd->is_error()) return true;

    set_nullable(is_nullable() || item->is_nullable());
    add_accum_properties(item);
  }
  if (types_assigned) set_data_type(MYSQL_TYPE_NULL);
  fixed = true;
  return false;
}

void Item_row::cleanup() {
  DBUG_TRACE;

  Item::cleanup();
}

void Item_row::split_sum_func(THD *thd, Ref_item_array ref_item_array,
                              mem_root_deque<Item *> *fields) {
  Item **arg, **arg_end;
  for (arg = items, arg_end = items + arg_count; arg != arg_end; arg++)
    (*arg)->split_sum_func2(thd, ref_item_array, fields, arg, true);
}

void Item_row::update_used_tables() {
  used_tables_cache = 0;
  m_accum_properties = 0;
  not_null_tables_cache = 0;
  for (uint i = 0; i < arg_count; i++) {
    items[i]->update_used_tables();
    used_tables_cache |= items[i]->used_tables();
    not_null_tables_cache |= items[i]->not_null_tables();
    add_accum_properties(items[i]);
  }
}

void Item_row::fix_after_pullout(Query_block *parent_query_block,
                                 Query_block *removed_query_block) {
  used_tables_cache = 0;
  not_null_tables_cache = 0;
  for (uint i = 0; i < arg_count; i++) {
    items[i]->fix_after_pullout(parent_query_block, removed_query_block);
    used_tables_cache |= items[i]->used_tables();
    not_null_tables_cache |= items[i]->not_null_tables();
  }
}

bool Item_row::propagate_type(THD *thd, const Type_properties &type) {
  assert(data_type() == MYSQL_TYPE_INVALID);
  for (uint i = 0; i < arg_count; i++) {
    if (items[i]->data_type() == MYSQL_TYPE_INVALID &&
        items[i]->propagate_type(thd, type))
      return true;
  }
  set_data_type(MYSQL_TYPE_NULL);
  return false;
}

bool Item_row::check_cols(uint c) {
  if (c != arg_count) {
    my_error(ER_OPERAND_COLUMNS, MYF(0), c);
    return true;
  }
  return false;
}

void Item_row::print(const THD *thd, String *str,
                     enum_query_type query_type) const {
  str->append('(');
  for (uint i = 0; i < arg_count; i++) {
    if (i) str->append(',');
    items[i]->print(thd, str, query_type);
  }
  str->append(')');
}

bool Item_row::walk(Item_processor processor, enum_walk walk, uchar *arg) {
  if ((walk & enum_walk::PREFIX) && (this->*processor)(arg)) return true;

  for (uint i = 0; i < arg_count; i++) {
    if (items[i]->walk(processor, walk, arg)) return true;
  }
  return (walk & enum_walk::POSTFIX) && (this->*processor)(arg);
}

Item *Item_row::transform(Item_transformer transformer, uchar *arg) {
  for (uint i = 0; i < arg_count; i++) {
    items[i] = items[i]->transform(transformer, arg);
    if (items[i] == nullptr) return nullptr; /* purecov: inspected */
  }
  return (this->*transformer)(arg);
}

void Item_row::bring_value() {
  for (uint i = 0; i < arg_count; i++) items[i]->bring_value();
}