MySQL  8.0.23
Source Code Documentation
temp_table_param.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, 2020, 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),
211  m_window(nullptr) {}
212 
213  void cleanup() { copy_fields.clear(); }
214 };
215 
216 #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:110
Temp_table_param::hidden_field_count
uint hidden_field_count
Definition: temp_table_param.h:120
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:85
Item
Definition: item.h:775
Mem_root_array
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:417
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:49
Temp_table_param
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:73
Temp_table_param::group_buff
uchar * group_buff
Definition: temp_table_param.h:77
Temp_table_param::force_copy_fields
bool force_copy_fields
Definition: temp_table_param.h:156
CHARSET_INFO
Definition: m_ctype.h:354
nullptr
Dialog Client Authentication nullptr
Definition: dialog.cc:353
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:213
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:181
mem_root
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
Mem_root_vector
std::vector< T, Mem_root_allocator< T > > Mem_root_vector
Definition: temp_table_param.h:43
Func_ptr::set_override_result_field
void set_override_result_field(Field *f)
Definition: temp_table_param.h:53
Temp_table_param::table_charset
CHARSET_INFO * table_charset
Definition: temp_table_param.h:147
Temp_table_param::items_to_copy
Func_ptr_array * items_to_copy
Definition: temp_table_param.h:78
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:132
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:139
Func_ptr::func
Item * func() const
Definition: temp_table_param.h:52
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:91
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:100
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:184
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:155
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:163
Temp_table_param::bit_fields_as_long
bool bit_fields_as_long
Definition: temp_table_param.h:169
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:146
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:178
Temp_table_param::group_null_parts
uint group_null_parts
Definition: temp_table_param.h:121
Temp_table_param::schema_table
bool schema_table
Definition: temp_table_param.h:148
Temp_table_param::Temp_table_param
Temp_table_param(MEM_ROOT *mem_root= *THR_MALLOC)
Definition: temp_table_param.h:189
Func_ptr_array
Mem_root_array< Func_ptr > Func_ptr_array
Used by copy_funcs()
Definition: temp_table_param.h:65
Func_ptr::override_result_field
Field * override_result_field() const
Definition: temp_table_param.h:54
HA_POS_ERROR
#define HA_POS_ERROR
Definition: my_base.h:1138
Func_ptr::m_func
Item * m_func
Definition: temp_table_param.h:57
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:187
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:119
Temp_table_param::copy_fields
Mem_root_vector< Copy_field > copy_fields
Definition: temp_table_param.h:75
Mem_root_allocator
Mem_root_allocator is a C++ STL memory allocator based on MEM_ROOT.
Definition: equi_height.h:92
Temp_table_param::group_parts
uint group_parts
Definition: temp_table_param.h:121
Temp_table_param::group_length
uint group_length
Definition: temp_table_param.h:121
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:172
ha_rows
my_off_t ha_rows
Definition: my_base.h:1136
Field
Definition: field.h:568
mem_root_allocator.h
THR_MALLOC
thread_local MEM_ROOT ** THR_MALLOC
Definition: mysqld.cc:1465
Func_ptr::Func_ptr
Func_ptr(Item *f)
Definition: temp_table_param.h:51
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:61
mem_root_array.h
Copy_field
Constitutes a mapping from columns of tables in the from clause to aggregated columns.
Definition: field.h:4580
false
#define false
Definition: config_static.h:43