MySQL  8.0.24
Source Code Documentation
temp_table_param.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, 2021, Oracle and/or its affiliates.
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 <sys/types.h>
27 #include <vector>
28 
29 #include "my_base.h"
30 #include "my_inttypes.h"
31 #include "sql/field.h"
32 #include "sql/mem_root_allocator.h"
33 #include "sql/mem_root_array.h"
34 #include "sql/thr_malloc.h"
35 
36 class KEY;
37 class Item;
38 class Window;
39 struct CHARSET_INFO;
40 struct MEM_ROOT;
41 
42 template <typename T>
43 using Mem_root_vector = std::vector<T, Mem_root_allocator<T>>;
44 
45 /**
46  Helper class for copy_funcs(); represents an Item to copy from table to
47  next tmp table.
48 */
49 class Func_ptr {
50  public:
51  explicit Func_ptr(Item *f) : m_func(f) {}
52  Item *func() const { return m_func; }
55 
56  private:
58 
59  /// If not nullptr, copy_funcs() will save the result of m_func here instead
60  /// of in m_func's usual designated result field.
62 };
63 
64 /// Used by copy_funcs()
66 
67 /**
68  Object containing parameters used when creating and using temporary
69  tables. Temporary tables created with the help of this object are
70  used only internally by the query execution engine.
71 */
72 
74  public:
76 
78  Func_ptr_array *items_to_copy; /* Fields in tmp table */
79 
80  /**
81  After temporary table creation, points to an index on the table
82  created depending on the purpose of the table - grouping,
83  duplicate elimination, etc. There is at most one such index.
84  */
86 
87  /**
88  LIMIT (maximum number of rows) for this temp table, or HA_POS_ERROR
89  for no limit. Enforced by MaterializeIterator when writing to the table.
90  */
92 
93  /**
94  Number of normal fields in the query, including those referred to
95  from aggregate functions. Hence, "SELECT `field1`,
96  SUM(`field2`) from t1" sets this counter to 2.
97 
98  @see count_field_types
99  */
101  /**
102  Number of fields in the query that have functions. Includes both
103  aggregate functions (e.g., SUM) and non-aggregates (e.g., RAND)
104  and windowing functions.
105  Also counts functions referred to from windowing or aggregate functions,
106  i.e., "SELECT SUM(RAND())" sets this counter to 2.
107 
108  @see count_field_types
109  */
111  /**
112  Number of fields in the query that have aggregate functions. Note
113  that the optimizer may choose to optimize away these fields by
114  replacing them with constants, in which case sum_func_count will
115  need to be updated.
116 
117  @see optimize_aggregated_query, count_field_types
118  */
122  /**
123  Whether we allow running GROUP BY processing into a temporary table,
124  i.e., keeping many different aggregations going at once without
125  having ordered input. This is usually the case, but is currently not
126  supported for aggregation UDFs, aggregates with DISTINCT, or ROLLUP.
127 
128  Note that even if this is true, the optimizer may choose to not use
129  a temporary table, as it is often more efficient to just read along
130  an index.
131  */
133  /**
134  Number of outer_sum_funcs i.e the number of set functions that are
135  aggregated in a query block outer to this subquery.
136 
137  @see count_field_types
138  */
140  /**
141  Enabled when we have atleast one outer_sum_func. Needed when used
142  along with distinct.
143 
144  @see create_tmp_table
145  */
149  /*
150  True if GROUP BY and its aggregate functions are already computed
151  by a table access method (e.g. by loose index scan). In this case
152  query execution should not perform aggregation and should treat
153  aggregate functions as normal functions.
154  */
157  /**
158  true <=> don't actually create table handler when creating the result
159  table. This allows range optimizer to add indexes later.
160  Used for materialized derived tables/views.
161  @see TABLE_LIST::update_derived_keys.
162  */
164  /*
165  If true, create_tmp_field called from create_tmp_table will convert
166  all BIT fields to 64-bit longs. This is a workaround the limitation
167  that MEMORY tables cannot index BIT columns.
168  */
170 
171  /// Whether the UNIQUE index can be promoted to PK
173 
174  /// Whether UNIQUE keys should always be implemented by way of a hidden
175  /// hash field, never a unique index. Needed for materialization of mixed
176  /// UNION ALL / UNION DISTINCT queries (see comments in
177  /// create_result_table()).
179 
180  /// (Last) window's tmp file step can be skipped
182 
183  /// This tmp table is used for a window's frame buffer
185 
186  /// If this is the out table of a window: the said window
188 
193  keyinfo(nullptr),
194  field_count(0),
195  func_count(0),
196  sum_func_count(0),
198  group_parts(0),
199  group_length(0),
200  group_null_parts(0),
204  schema_table(false),
205  precomputed_group_by(false),
206  force_copy_fields(false),
207  skip_create_table(false),
208  bit_fields_as_long(false),
209  can_use_pk_for_unique(true),
210  m_window_short_circuit(false),
211  m_window(nullptr) {}
212 
213  void cleanup() { copy_fields.clear(); }
214 };
215 
216 #endif // TEMP_TABLE_PARAM_INCLUDED
Constitutes a mapping from columns of tables in the from clause to aggregated columns.
Definition: field.h:4591
Definition: field.h:568
Helper class for copy_funcs(); represents an Item to copy from table to next tmp table.
Definition: temp_table_param.h:49
Item * func() const
Definition: temp_table_param.h:52
void set_override_result_field(Field *f)
Definition: temp_table_param.h:53
Item * m_func
Definition: temp_table_param.h:57
Func_ptr(Item *f)
Definition: temp_table_param.h:51
Field * override_result_field() const
Definition: temp_table_param.h:54
Field * m_override_result_field
If not nullptr, copy_funcs() will save the result of m_func here instead of in m_func's usual designa...
Definition: temp_table_param.h:61
Definition: item.h:776
Definition: key.h:112
Mem_root_allocator is a C++ STL memory allocator based on MEM_ROOT.
Definition: mem_root_allocator.h:67
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:418
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:73
bool force_copy_fields
Definition: temp_table_param.h:156
uint sum_func_count
Number of fields in the query that have aggregate functions.
Definition: temp_table_param.h:119
bool using_outer_summary_function
Enabled when we have atleast one outer_sum_func.
Definition: temp_table_param.h:146
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:139
Window * m_window
If this is the out table of a window: the said window.
Definition: temp_table_param.h:187
Func_ptr_array * items_to_copy
Definition: temp_table_param.h:78
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:132
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:178
bool m_window_short_circuit
(Last) window's tmp file step can be skipped
Definition: temp_table_param.h:181
bool m_window_frame_buffer
This tmp table is used for a window's frame buffer.
Definition: temp_table_param.h:184
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:85
CHARSET_INFO * table_charset
Definition: temp_table_param.h:147
uint group_null_parts
Definition: temp_table_param.h:121
uint func_count
Number of fields in the query that have functions.
Definition: temp_table_param.h:110
uint group_length
Definition: temp_table_param.h:121
bool schema_table
Definition: temp_table_param.h:148
Temp_table_param(MEM_ROOT *mem_root= *THR_MALLOC)
Definition: temp_table_param.h:189
uint hidden_field_count
Definition: temp_table_param.h:120
bool skip_create_table
true <=> don't actually create table handler when creating the result table.
Definition: temp_table_param.h:163
bool can_use_pk_for_unique
Whether the UNIQUE index can be promoted to PK.
Definition: temp_table_param.h:172
uint field_count
Number of normal fields in the query, including those referred to from aggregate functions.
Definition: temp_table_param.h:100
uint group_parts
Definition: temp_table_param.h:121
Mem_root_vector< Copy_field > copy_fields
Definition: temp_table_param.h:75
void cleanup()
Definition: temp_table_param.h:213
bool precomputed_group_by
Definition: temp_table_param.h:155
uchar * group_buff
Definition: temp_table_param.h:77
bool bit_fields_as_long
Definition: temp_table_param.h:169
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:91
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:94
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
Dialog Client Authentication nullptr
Definition: dialog.cc:353
This file includes constants used by all storage engines.
my_off_t ha_rows
Definition: my_base.h:1136
#define HA_POS_ERROR
Definition: my_base.h:1138
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:51
thread_local MEM_ROOT ** THR_MALLOC
Definition: mysqld.cc:1500
Definition: m_ctype.h:354
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:78
std::vector< T, Mem_root_allocator< T > > Mem_root_vector
Definition: temp_table_param.h:43
Mem_root_array< Func_ptr > Func_ptr_array
Used by copy_funcs()
Definition: temp_table_param.h:65
unsigned int uint
Definition: uca-dump.cc:29