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