MySQL 8.0.39
Source Code Documentation
temp_table_param.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef TEMP_TABLE_PARAM_INCLUDED
25#define TEMP_TABLE_PARAM_INCLUDED
26
27#include <sys/types.h>
28#include <vector>
29
30#include "my_base.h"
31#include "my_inttypes.h"
32#include "sql/field.h"
33#include "sql/mem_root_array.h"
34#include "sql/thr_malloc.h"
35
36class KEY;
37class Item;
38class Window;
39struct CHARSET_INFO;
40struct MEM_ROOT;
41
42enum Copy_func_type : int;
43
44/**
45 Helper class for copy_funcs(); represents an Item to copy from table to
46 next tmp table.
47*/
48class Func_ptr {
49 public:
51
52 Item *func() const { return m_func; }
53 void set_func(Item *func);
54 Field *result_field() const { return m_result_field; }
55 Item_field *result_item() const;
57 return m_func_bits & (1 << type);
58 }
59
60 private:
63
64 // A premade Item_field for m_result_field (may be nullptr if allocation
65 // failed). This has two purposes:
66 //
67 // - It avoids repeated constructions if the field is used multiple times
68 // (e.g., first in a SELECT list, then in a sort order).
69 // - It gives a canonical, unique item, so that we can compare it with ==
70 // (in FindReplacementItem(), where ->eq would have a metadata issues).
71 // This is important if we are to replace it with something else again
72 // later.
73 //
74 // It is created on-demand to avoid getting into the thd->stmt_arena field
75 // list for a temporary table that is freed later anyway.
76 mutable Item_field *m_result_item = nullptr;
77
78 // A bitmap where all CFT_* enums are bit indexes, and we have a 1 if m_func
79 // is of the type given by that enum. E.g., if m_func is an Item_field,
80 // (1 << CFT_FIELDS) will be set here. This is used for quickly finding out
81 // which items to copy in copy_funcs(), without having to look at the actual
82 // items (which involves virtual function calls).
84};
85
86/// Used by copy_funcs()
88
89/**
90 Object containing parameters used when creating and using temporary
91 tables. Temporary tables created with the help of this object are
92 used only internally by the query execution engine.
93*/
94
96 public:
98
100 Func_ptr_array *items_to_copy; /* Fields in tmp table */
101
102 /**
103 After temporary table creation, points to an index on the table
104 created depending on the purpose of the table - grouping,
105 duplicate elimination, etc. There is at most one such index.
106 */
108
109 /**
110 LIMIT (maximum number of rows) for this temp table, or HA_POS_ERROR
111 for no limit. Enforced by MaterializeIterator when writing to the table.
112 */
114
115 /**
116 Number of items in the query. Includes both aggregate functions (e.g., SUM),
117 and non-aggregates (e.g., RAND), window functions and fields.
118 Also counts functions referred to from windowing or aggregate functions,
119 i.e., "SELECT SUM(RAND())" sets this counter to 2.
120
121 @see count_field_types
122 */
124 /**
125 Number of fields in the query that have aggregate functions. Note
126 that the optimizer may choose to optimize away these fields by
127 replacing them with constants, in which case sum_func_count will
128 need to be updated.
129
130 @see optimize_aggregated_query, count_field_types
131 */
135 /**
136 Whether we allow running GROUP BY processing into a temporary table,
137 i.e., keeping many different aggregations going at once without
138 having ordered input. This is usually the case, but is currently not
139 supported for aggregation UDFs, aggregates with DISTINCT, or ROLLUP.
140
141 Note that even if this is true, the optimizer may choose to not use
142 a temporary table, as it is often more efficient to just read along
143 an index.
144 */
146 /**
147 Number of outer_sum_funcs i.e the number of set functions that are
148 aggregated in a query block outer to this subquery.
149
150 @see count_field_types
151 */
153 /**
154 Enabled when we have at least one outer_sum_func. Needed when used
155 along with distinct.
156
157 @see create_tmp_table
158 */
162 /*
163 True if GROUP BY and its aggregate functions are already computed
164 by a table access method (e.g. by loose index scan). In this case
165 query execution should not perform aggregation and should treat
166 aggregate functions as normal functions.
167 */
170 /**
171 true <=> don't actually create table handler when creating the result
172 table. This allows range optimizer to add indexes later.
173 Used for materialized derived tables/views.
174 @see Table_ref::update_derived_keys.
175 */
177 /*
178 If true, create_tmp_field called from create_tmp_table will convert
179 all BIT fields to 64-bit longs. This is a workaround the limitation
180 that MEMORY tables cannot index BIT columns.
181 */
183
184 /// Whether the UNIQUE index can be promoted to PK
186
187 /// Whether UNIQUE keys should always be implemented by way of a hidden
188 /// hash field, never a unique index. Needed for materialization of mixed
189 /// UNION ALL / UNION DISTINCT queries (see comments in
190 /// create_result_table()).
192
193 /// This tmp table is used for a window's frame buffer
195
196 /// For INTERSECT and EXCEPT computation
197 enum {
201 } m_operation{TTP_UNION_OR_TABLE};
202 /// The tempoary table rows need a counter to keep track of its
203 /// duplicates: needed for EXCEPT and INTERSECT computation.
204 bool needs_set_counter() { return m_operation != TTP_UNION_OR_TABLE; }
205 /// For INTERSECT and EXCEPT computation.
206 /// Cf. TABLE::m_last_operation_is_distinct.
208
209 /// If this is the out table of a window: the said window
211
217 func_count(0),
220 group_parts(0),
221 group_length(0),
226 schema_table(false),
228 force_copy_fields(false),
229 skip_create_table(false),
230 bit_fields_as_long(false),
232 m_window(nullptr) {}
233
236 group_buff(other.group_buff),
238 keyinfo(other.keyinfo),
240 func_count(other.func_count),
258 m_window(other.m_window) {}
259
260 void cleanup() { copy_fields.clear(); }
261};
262
263#endif // TEMP_TABLE_PARAM_INCLUDED
Definition: field.h:575
Helper class for copy_funcs(); represents an Item to copy from table to next tmp table.
Definition: temp_table_param.h:48
Item * m_func
Definition: temp_table_param.h:61
Field * m_result_field
Definition: temp_table_param.h:62
Func_ptr(Item *item, Field *result_field)
Definition: sql_tmp_table.cc:2957
int m_func_bits
Definition: temp_table_param.h:83
bool should_copy(Copy_func_type type) const
Definition: temp_table_param.h:56
Item_field * m_result_item
Definition: temp_table_param.h:76
Item_field * result_item() const
Definition: sql_tmp_table.cc:2967
Item * func() const
Definition: temp_table_param.h:52
Field * result_field() const
Definition: temp_table_param.h:54
void set_func(Item *func)
Definition: sql_tmp_table.cc:2962
Definition: item.h:4163
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:853
Definition: key.h:113
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:95
bool force_copy_fields
Definition: temp_table_param.h:169
uint sum_func_count
Number of fields in the query that have aggregate functions.
Definition: temp_table_param.h:132
bool using_outer_summary_function
Enabled when we have at least one outer_sum_func.
Definition: temp_table_param.h:159
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:152
Window * m_window
If this is the out table of a window: the said window.
Definition: temp_table_param.h:210
Func_ptr_array * items_to_copy
Definition: temp_table_param.h:100
bool m_last_operation_is_distinct
For INTERSECT and EXCEPT computation.
Definition: temp_table_param.h:207
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:145
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:191
bool m_window_frame_buffer
This tmp table is used for a window's frame buffer.
Definition: temp_table_param.h:194
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:107
Temp_table_param(MEM_ROOT *mem_root, const Temp_table_param &other)
Definition: temp_table_param.h:234
enum Temp_table_param::@181 TTP_UNION_OR_TABLE
For INTERSECT and EXCEPT computation.
CHARSET_INFO * table_charset
Definition: temp_table_param.h:160
uint group_null_parts
Definition: temp_table_param.h:134
uint func_count
Number of items in the query.
Definition: temp_table_param.h:123
uint group_length
Definition: temp_table_param.h:134
Mem_root_array< Copy_field > copy_fields
Definition: temp_table_param.h:97
bool schema_table
Definition: temp_table_param.h:161
bool needs_set_counter()
The tempoary table rows need a counter to keep track of its duplicates: needed for EXCEPT and INTERSE...
Definition: temp_table_param.h:204
Temp_table_param(MEM_ROOT *mem_root= *THR_MALLOC)
Definition: temp_table_param.h:212
uint hidden_field_count
Definition: temp_table_param.h:133
bool skip_create_table
true <=> don't actually create table handler when creating the result table.
Definition: temp_table_param.h:176
bool can_use_pk_for_unique
Whether the UNIQUE index can be promoted to PK.
Definition: temp_table_param.h:185
uint group_parts
Definition: temp_table_param.h:134
void cleanup()
Definition: temp_table_param.h:260
@ TTP_UNION_OR_TABLE
Definition: temp_table_param.h:198
@ TTP_INTERSECT
Definition: temp_table_param.h:200
@ TTP_EXCEPT
Definition: temp_table_param.h:199
bool precomputed_group_by
Definition: temp_table_param.h:168
uchar * group_buff
Definition: temp_table_param.h:99
bool bit_fields_as_long
Definition: temp_table_param.h:182
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:113
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:105
static MEM_ROOT mem_root
Definition: client_plugin.cc:110
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:222
This file includes constants used by all storage engines.
my_off_t ha_rows
Definition: my_base.h:1140
#define HA_POS_ERROR
Definition: my_base.h:1142
Some integer typedefs for easier portability.
unsigned char uchar
Definition: my_inttypes.h:52
thread_local MEM_ROOT ** THR_MALLOC
Definition: mysqld.cc:1560
required string type
Definition: replication_group_member_actions.proto:34
Copy_func_type
Definition: sql_executor.h:170
Definition: m_ctype.h:385
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Mem_root_array< Func_ptr > Func_ptr_array
Used by copy_funcs()
Definition: temp_table_param.h:87
unsigned int uint
Definition: uca9-dump.cc:75