MySQL  8.0.18
Source Code Documentation
temp_table_param.h
Go to the documentation of this file.
1 /* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
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, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef TEMP_TABLE_PARAM_INCLUDED
24 #define TEMP_TABLE_PARAM_INCLUDED
25 
26 #include <vector>
27 
28 #include "my_base.h"
29 #include "sql/mem_root_array.h"
30 #include "sql/sql_list.h"
31 #include "sql/thr_malloc.h"
32 #include "sql/window.h"
33 
34 class KEY;
35 class Copy_field;
36 class Item;
37 class Window;
38 
39 template <typename T>
40 using Memroot_vector = std::vector<T, Memroot_allocator<T>>;
41 
42 /**
43  Helper class for copy_funcs(); represents an Item to copy from table to
44  next tmp table.
45 */
46 class Func_ptr {
47  public:
48  explicit Func_ptr(Item *f) : m_func(f) {}
49  Item *func() const { return m_func; }
52 
53  private:
55 
56  /// If not nullptr, copy_funcs() will save the result of m_func here instead
57  /// of in m_func's usual designated result field.
59 };
60 
61 /// Used by copy_funcs()
63 
64 /**
65  Object containing parameters used when creating and using temporary
66  tables. Temporary tables created with the help of this object are
67  used only internally by the query execution engine.
68 */
69 
71  public:
72  /**
73  Used to store the values of grouped non-column-reference expressions in
74  between groups, so they can be retreived when the group changes.
75 
76  @see setup_copy_fields
77  @see copy_fields
78  */
81 
83  Func_ptr_array *items_to_copy; /* Fields in tmp table */
84 
85  /**
86  After temporary table creation, points to an index on the table
87  created depending on the purpose of the table - grouping,
88  duplicate elimination, etc. There is at most one such index.
89  */
91 
92  /**
93  LIMIT (maximum number of rows) for this temp table, or HA_POS_ERROR
94  for no limit. Enforced by MaterializeIterator when writing to the table.
95  */
97 
98  /**
99  Number of normal fields in the query, including those referred to
100  from aggregate functions. Hence, "SELECT `field1`,
101  SUM(`field2`) from t1" sets this counter to 2.
102 
103  @see count_field_types
104  */
106  /**
107  Number of fields in the query that have functions. Includes both
108  aggregate functions (e.g., SUM) and non-aggregates (e.g., RAND)
109  and windowing functions.
110  Also counts functions referred to from windowing or aggregate functions,
111  i.e., "SELECT SUM(RAND())" sets this counter to 2.
112 
113  @see count_field_types
114  */
116  /**
117  Number of fields in the query that have aggregate functions. Note
118  that the optimizer may choose to optimize away these fields by
119  replacing them with constants, in which case sum_func_count will
120  need to be updated.
121 
122  @see optimize_aggregated_query, count_field_types
123  */
127  /**
128  Whether we allow running GROUP BY processing into a temporary table,
129  i.e., keeping many different aggregations going at once without
130  having ordered input. This is usually the case, but is currently not
131  supported for aggregation UDFs, aggregates with DISTINCT, or ROLLUP.
132 
133  Note that even if this is true, the optimizer may choose to not use
134  a temporary table, as it is often more efficient to just read along
135  an index.
136  */
138  /**
139  Number of outer_sum_funcs i.e the number of set functions that are
140  aggregated in a query block outer to this subquery.
141 
142  @see count_field_types
143  */
145  /**
146  Enabled when we have atleast one outer_sum_func. Needed when used
147  along with distinct.
148 
149  @see create_tmp_table
150  */
154  /*
155  True if GROUP BY and its aggregate functions are already computed
156  by a table access method (e.g. by loose index scan). In this case
157  query execution should not perform aggregation and should treat
158  aggregate functions as normal functions.
159  */
162  /**
163  true <=> don't actually create table handler when creating the result
164  table. This allows range optimizer to add indexes later.
165  Used for materialized derived tables/views.
166  @see TABLE_LIST::update_derived_keys.
167  */
169  /*
170  If true, create_tmp_field called from create_tmp_table will convert
171  all BIT fields to 64-bit longs. This is a workaround the limitation
172  that MEMORY tables cannot index BIT columns.
173  */
175 
176  /// Whether the UNIQUE index can be promoted to PK
178 
179  /// Whether UNIQUE keys should always be implemented by way of a hidden
180  /// hash field, never a unique index. Needed for materialization of mixed
181  /// UNION ALL / UNION DISTINCT queries (see comments in
182  /// create_result_table()).
184 
185  /// (Last) window's tmp file step can be skipped
187 
188  /// This tmp table is used for a window's frame buffer
190 
191  /// If this is the out table of a window: the said window
193 
197  group_buff(nullptr),
198  items_to_copy(nullptr),
199  keyinfo(NULL),
200  field_count(0),
201  func_count(0),
202  sum_func_count(0),
204  group_parts(0),
205  group_length(0),
206  group_null_parts(0),
217  m_window(nullptr) {}
218 
219  void cleanup() {
220  grouped_expressions.clear();
221  copy_fields.clear();
222  }
223 };
224 
225 #endif // TEMP_TABLE_PARAM_INCLUDED
Base class to implement typed value caching Item classes.
Definition: item.h:5185
Helper class for copy_funcs(); represents an Item to copy from table to next tmp table.
Definition: temp_table_param.h:46
unsigned char uchar
Definition: my_inttypes.h:51
std::vector< T, Memroot_allocator< T > > Memroot_vector
Definition: temp_table_param.h:40
uchar * group_buff
Definition: temp_table_param.h:82
uint group_length
Definition: temp_table_param.h:126
Constitutes a mapping from columns of tables in the from clause to aggregated columns.
Definition: field.h:4945
uint outer_sum_func_count
Number of outer_sum_funcs i.e the number of set functions that are aggregated in a query block outer ...
Definition: temp_table_param.h:144
Mem_root_array< Func_ptr > Func_ptr_array
Used by copy_funcs()
Definition: temp_table_param.h:62
Definition: field.h:700
KEY * keyinfo
After temporary table creation, points to an index on the table created depending on the purpose of t...
Definition: temp_table_param.h:90
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:79
bool force_copy_fields
Definition: temp_table_param.h:161
uint group_null_parts
Definition: temp_table_param.h:126
void cleanup()
Definition: temp_table_param.h:219
uint group_parts
Definition: temp_table_param.h:126
Field * override_result_field() const
Definition: temp_table_param.h:51
Memroot_vector< Copy_field > copy_fields
Definition: temp_table_param.h:80
bool can_use_pk_for_unique
Whether the UNIQUE index can be promoted to PK.
Definition: temp_table_param.h:177
This file includes constants used by all storage engines.
void set_override_result_field(Field *f)
Definition: temp_table_param.h:50
bool precomputed_group_by
Definition: temp_table_param.h:160
Item * m_func
Definition: temp_table_param.h:54
Temp_table_param(MEM_ROOT *mem_root= *THR_MALLOC)
Definition: temp_table_param.h:194
bool m_window_short_circuit
(Last) window&#39;s tmp file step can be skipped
Definition: temp_table_param.h:186
Item * func() const
Definition: temp_table_param.h:49
bool schema_table
Definition: temp_table_param.h:153
Definition: item.h:668
unsigned int uint
Definition: uca-dump.cc:29
#define true
Definition: config_static.h:44
uint hidden_field_count
Definition: temp_table_param.h:125
uint func_count
Number of fields in the query that have functions.
Definition: temp_table_param.h:115
Func_ptr(Item *f)
Definition: temp_table_param.h:48
Definition: m_ctype.h:359
uint sum_func_count
Number of fields in the query that have aggregate functions.
Definition: temp_table_param.h:124
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:398
Window * m_window
If this is the out table of a window: the said window.
Definition: temp_table_param.h:192
static MEM_ROOT mem_root
Definition: client_plugin.cc:107
uint field_count
Number of normal fields in the query, including those referred to from aggregate functions.
Definition: temp_table_param.h:105
bool using_outer_summary_function
Enabled when we have atleast one outer_sum_func.
Definition: temp_table_param.h:151
thread_local MEM_ROOT ** THR_MALLOC
Definition: mysqld.cc:1331
Definition: key.h:111
bool m_window_frame_buffer
This tmp table is used for a window&#39;s frame buffer.
Definition: temp_table_param.h:189
Field * m_override_result_field
If not nullptr, copy_funcs() will save the result of m_func here instead of in m_func&#39;s usual designa...
Definition: temp_table_param.h:58
#define HA_POS_ERROR
Definition: my_base.h:1132
bool allow_group_via_temp_table
Whether we allow running GROUP BY processing into a temporary table, i.e., keeping many different agg...
Definition: temp_table_param.h:137
#define NULL
Definition: types.h:55
ha_rows end_write_records
LIMIT (maximum number of rows) for this temp table, or HA_POS_ERROR for no limit. ...
Definition: temp_table_param.h:96
Func_ptr_array * items_to_copy
Definition: temp_table_param.h:83
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
bool bit_fields_as_long
Definition: temp_table_param.h:174
Memroot_vector< Item_copy * > grouped_expressions
Used to store the values of grouped non-column-reference expressions in between groups, so they can be retreived when the group changes.
Definition: temp_table_param.h:79
CHARSET_INFO * table_charset
Definition: temp_table_param.h:152
#define false
Definition: config_static.h:43
my_off_t ha_rows
Definition: my_base.h:1130
bool skip_create_table
true <=> don&#39;t actually create table handler when creating the result table.
Definition: temp_table_param.h:168
bool force_hash_field_for_unique
Whether UNIQUE keys should always be implemented by way of a hidden hash field, never a unique index...
Definition: temp_table_param.h:183
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:70
Memroot_allocator is a C++ STL memory allocator based on MEM_ROOT.
Definition: equi_height.h:92