MySQL  8.0.17
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  */
92  /**
93  Number of normal fields in the query, including those referred to
94  from aggregate functions. Hence, "SELECT `field1`,
95  SUM(`field2`) from t1" sets this counter to 2.
96 
97  @see count_field_types
98  */
100  /**
101  Number of fields in the query that have functions. Includes both
102  aggregate functions (e.g., SUM) and non-aggregates (e.g., RAND)
103  and windowing functions.
104  Also counts functions referred to from windowing or aggregate functions,
105  i.e., "SELECT SUM(RAND())" sets this counter to 2.
106 
107  @see count_field_types
108  */
110  /**
111  Number of fields in the query that have aggregate functions. Note
112  that the optimizer may choose to optimize away these fields by
113  replacing them with constants, in which case sum_func_count will
114  need to be updated.
115 
116  @see optimize_aggregated_query, count_field_types
117  */
121  /**
122  Whether we allow running GROUP BY processing into a temporary table,
123  i.e., keeping many different aggregations going at once without
124  having ordered input. This is usually the case, but is currently not
125  supported for aggregation UDFs, aggregates with DISTINCT, or ROLLUP.
126 
127  Note that even if this is true, the optimizer may choose to not use
128  a temporary table, as it is often more efficient to just read along
129  an index.
130  */
132  /**
133  Number of outer_sum_funcs i.e the number of set functions that are
134  aggregated in a query block outer to this subquery.
135 
136  @see count_field_types
137  */
139  /**
140  Enabled when we have atleast one outer_sum_func. Needed when used
141  along with distinct.
142 
143  @see create_tmp_table
144  */
148  /*
149  True if GROUP BY and its aggregate functions are already computed
150  by a table access method (e.g. by loose index scan). In this case
151  query execution should not perform aggregation and should treat
152  aggregate functions as normal functions.
153  */
156  /**
157  true <=> don't actually create table handler when creating the result
158  table. This allows range optimizer to add indexes later.
159  Used for materialized derived tables/views.
160  @see TABLE_LIST::update_derived_keys.
161  */
163  /*
164  If true, create_tmp_field called from create_tmp_table will convert
165  all BIT fields to 64-bit longs. This is a workaround the limitation
166  that MEMORY tables cannot index BIT columns.
167  */
169 
170  /// Whether the UNIQUE index can be promoted to PK
172 
173  /// (Last) window's tmp file step can be skipped
175 
176  /// This tmp table is used for a window's frame buffer
178 
179  /// If this is the out table of a window: the said window
181 
185  group_buff(nullptr),
186  items_to_copy(nullptr),
187  keyinfo(NULL),
189  field_count(0),
190  func_count(0),
191  sum_func_count(0),
193  group_parts(0),
194  group_length(0),
195  group_null_parts(0),
206  m_window(nullptr) {}
207 
208  void cleanup() {
209  grouped_expressions.clear();
210  copy_fields.clear();
211  }
212 };
213 
214 #endif // TEMP_TABLE_PARAM_INCLUDED
Base class to implement typed value caching Item classes.
Definition: item.h:5192
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:120
Constitutes a mapping from columns of tables in the from clause to aggregated columns.
Definition: field.h:4931
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:138
Mem_root_array< Func_ptr > Func_ptr_array
Used by copy_funcs()
Definition: temp_table_param.h:62
Definition: field.h:709
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:155
uint group_null_parts
Definition: temp_table_param.h:120
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
void cleanup()
Definition: temp_table_param.h:208
uint group_parts
Definition: temp_table_param.h:120
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:171
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:154
Item * m_func
Definition: temp_table_param.h:54
Temp_table_param(MEM_ROOT *mem_root= *THR_MALLOC)
Definition: temp_table_param.h:182
bool m_window_short_circuit
(Last) window&#39;s tmp file step can be skipped
Definition: temp_table_param.h:174
Item * func() const
Definition: temp_table_param.h:49
bool schema_table
Definition: temp_table_param.h:147
Definition: item.h:666
unsigned int uint
Definition: uca-dump.cc:29
#define true
Definition: config_static.h:44
uint hidden_field_count
Definition: temp_table_param.h:119
uint func_count
Number of fields in the query that have functions.
Definition: temp_table_param.h:109
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:118
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:397
Window * m_window
If this is the out table of a window: the said window.
Definition: temp_table_param.h:180
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:99
bool using_outer_summary_function
Enabled when we have atleast one outer_sum_func.
Definition: temp_table_param.h:145
thread_local MEM_ROOT ** THR_MALLOC
Definition: mysqld.cc:1333
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:177
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
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:131
ha_rows end_write_records
Definition: temp_table_param.h:91
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:168
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:146
#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:162
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