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