MySQL 8.3.0
Source Code Documentation
sql_executor.h
Go to the documentation of this file.
1#ifndef SQL_EXECUTOR_INCLUDED
2#define SQL_EXECUTOR_INCLUDED
3
4/* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is also distributed with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have included with MySQL.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26/**
27 @file sql/sql_executor.h
28 Classes for query execution.
29*/
30
31#include <sys/types.h>
32#include <string>
33#include <vector>
34
35#include "my_alloc.h"
36#include "my_inttypes.h"
37#include "my_table_map.h"
38#include "sql/sql_lex.h"
39#include "sql/sql_opt_exec_shared.h" // QEP_shared_owner
40#include "sql/table.h"
41#include "sql/temp_table_param.h" // Temp_table_param
42
43class Cached_item;
44class Field;
45class Field_longlong;
46class Filesort;
47class Item;
48class Item_sum;
49class JOIN;
50class JOIN_TAB;
51class KEY;
53class QEP_TAB;
54class RowIterator;
55class THD;
56template <class T>
57class mem_root_deque;
58
59struct AccessPath;
60struct POSITION;
61template <class T>
62class List;
63template <typename Element_type>
64class Mem_root_array;
65
66/*
67 Array of pointers to tables whose rowids compose the temporary table
68 record.
69*/
73 ushort null_byte;
75};
76
77/*
78 Temporary table used by semi-join DuplicateElimination strategy
79
80 This consists of the temptable itself and data needed to put records
81 into it. The table's DDL is as follows:
82
83 CREATE TABLE tmptable (col VARCHAR(n) BINARY, PRIMARY KEY(col));
84
85 where the primary key can be replaced with unique constraint if n exceeds
86 the limit (as it is always done for query execution-time temptables).
87
88 The record value is a concatenation of rowids of tables from the join we're
89 executing. If a join table is on the inner side of the outer join, we
90 assume that its rowid can be NULL and provide means to store this rowid in
91 the tuple.
92*/
93
95 public:
99
100 /*
101 is_confluent==true means this is a special case where the temptable record
102 has zero length (and presence of a unique key means that the temptable can
103 have either 0 or 1 records).
104 In this case we don't create the physical temptable but instead record
105 its state in SJ_TMP_TABLE::have_confluent_record.
106 */
108
109 /*
110 When is_confluent==true: the contents of the table (whether it has the
111 record or not).
112 */
114
115 /* table record parameters */
119
120 /* The temporary table itself (NULL means not created yet) */
122
123 /* Pointer to next table (next->start_idx > this->end_idx) */
125 /* Calc hash instead of too long key */
127};
128
129/**
130 Executor structure for the materialized semi-join info, which contains
131 - Description of expressions selected from subquery
132 - The sj-materialization temporary table
133*/
135 public:
138 : sj_nest(sj_nest),
143 table_param(),
144 table(nullptr) {}
146 Table_ref *const sj_nest; ///< Semi-join nest for this materialization
147 const bool is_scan; ///< true if executing a scan, false if lookup
148 const uint table_count; ///< Number of tables in the sj-nest
149 const uint mat_table_index; ///< Index in join_tab for materialized table
150 const uint inner_table_index; ///< Index in join_tab for first inner table
151 Temp_table_param table_param; ///< The temptable and its related info
152 TABLE *table; ///< Reference to temporary table
153};
154
156
157[[nodiscard]] bool copy_fields(Temp_table_param *param, const THD *thd,
158 bool reverse_copy = false);
159
160enum Copy_func_type : int {
161 /**
162 In non-windowing step, copies functions
163 */
165 /**
166 In windowing step, copies framing window function, including
167 all grouping aggregates, e.g. SUM, AVG and FIRST_VALUE, LAST_VALUE.
168 */
170 /**
171 In windowing step, copies non framing window function, e.g.
172 ROW_NUMBER, RANK, DENSE_RANK, except those that are two_pass cf.
173 copy_two_pass_window_functions which are treated separately.
174 */
176 /**
177 In windowing step, copies window functions that need frame cardinality,
178 that is we need to read all rows of a partition before we can compute the
179 wf's value for the the first row in the partition.
180 */
182 /**
183 In windowing step, copies framing window functions that read only one row
184 per frame.
185 */
187 /**
188 In first windowing step, copies non-window functions which do not rely on
189 window functions, i.e. those that have Item::has_wf() == false.
190 */
192 /**
193 In final windowing step, copies all non-wf functions. Must be called after
194 all wfs have been evaluated, as non-wf functions may reference wf,
195 e.g. 1+RANK.
196 */
198 /**
199 Copies all window functions.
200 */
202 /**
203 Copies Item_field only (typically because other functions might depend
204 on those fields).
205 */
207};
208
209bool copy_funcs(Temp_table_param *, const THD *thd,
211
212/**
213 Copy the lookup key into the table ref's key buffer.
214
215 @param thd pointer to the THD object
216 @param table the table to read
217 @param ref information about the index lookup key
218
219 @retval false ref key copied successfully
220 @retval true error detected during copying of key
221*/
223
224/** Help function when we get some an error from the table handler. */
226
228
229int do_sj_dups_weedout(THD *thd, SJ_TMP_TABLE *sjtbl);
231
232// Create list for using with temporary table
234 Ref_item_array ref_item_array,
235 mem_root_deque<Item *> *res_fields,
236 size_t added_non_hidden_fields,
237 bool windowing = false);
238// Create list for using with temporary table
240 THD *thd, Query_block *select,
241 Ref_item_array ref_item_array,
242 mem_root_deque<Item *> *res_fields,
243 size_t added_non_hidden_fields);
244bool prepare_sum_aggregators(Item_sum **func_ptr, bool need_distinct);
245bool setup_sum_funcs(THD *thd, Item_sum **func_ptr);
246bool make_group_fields(JOIN *main_join, JOIN *curr_join);
249ulonglong calc_field_hash(const Field *field, ulonglong *hash);
252
253class QEP_TAB : public QEP_shared_owner {
254 public:
263 rematerialize(false),
269 m_keyread_optim(false),
270 m_reversed_access(false),
272
273 /// Initializes the object from a JOIN_TAB
274 void init(JOIN_TAB *jt);
275 // Cleans up.
276 void cleanup();
277
278 // Getters and setters
279
282 bool keyread_optim() const { return m_keyread_optim; }
285 }
286 bool reversed_access() const { return m_reversed_access; }
287 void set_reversed_access(bool arg) { m_reversed_access = arg; }
288
289 void set_table(TABLE *t) {
290 m_qs->set_table(t);
291 if (t) t->reginfo.qep_tab = this;
292 }
293
294 /// @returns semijoin strategy for this table.
295 uint get_sj_strategy() const;
296
297 /// Return true if join_tab should perform a FirstMatch action
298 bool do_firstmatch() const { return firstmatch_return != NO_PLAN_IDX; }
299
300 /// Return true if join_tab should perform a LooseScan action
301 bool do_loosescan() const { return loosescan_key_len; }
302
303 /// Return true if join_tab starts a Duplicate Weedout action
304 bool starts_weedout() const { return flush_weedout_table; }
305
306 /// Return true if join_tab finishes a Duplicate Weedout action
307 bool finishes_weedout() const { return check_weed_out_table; }
308
309 /**
310 A helper function that allocates appropriate join cache object and
311 sets next_query_block function of previous tab.
312 */
313 void init_join_cache(JOIN_TAB *join_tab);
314
315 /**
316 @returns query block id for an inner table of materialized semi-join, and
317 0 for all other tables.
318 @note implementation is not efficient (loops over all tables) - use this
319 function only in EXPLAIN.
320 */
321 uint sjm_query_block_id() const;
322
323 /// @returns whether this is doing QS_DYNAMIC_RANGE
324 bool dynamic_range() const {
325 if (!position()) return false; // tmp table
326 return using_dynamic_range;
327 }
328
329 bool use_order() const; ///< Use ordering provided by chosen index?
330
331 /**
332 Construct an access path for reading from this table in the query,
333 using the access method that has been determined previously
334 (e.g., table scan, ref access, optional sort afterwards, etc.).
335 */
337 void push_index_cond(const JOIN_TAB *join_tab, uint keyno,
338 Opt_trace_object *trace_obj);
339
340 /// @return the index used for a table in a QEP
341 uint effective_index() const;
342
343 bool pfs_batch_update(const JOIN *join) const;
344
345 public:
346 /// Pointer to table reference
348
349 /* Variables for semi-join duplicate elimination */
352
353 /*
354 If set, means we should stop join enumeration after we've got the first
355 match and return to the specified join tab. May be PRE_FIRST_PLAN_IDX
356 which means stopping join execution after the first match.
357 */
359
360 /*
361 Length of key tuple (depends on #keyparts used) to use for loose scan.
362 If zero, means that loosescan is not used.
363 */
365
366 /*
367 If doing a LooseScan, this QEP is the first (i.e. "driving")
368 QEP_TAB, and match_tab points to the last QEP_TAB handled by the strategy.
369 match_tab->found_match should be checked to see if the current value group
370 had a match.
371 */
373
374 /// Dependent table functions have to be materialized on each new scan
376
382 };
385
386 /** true <=> remove duplicates on this table. */
388
389 // If we have a query of the type SELECT DISTINCT t1.* FROM t1 JOIN t2
390 // ON ..., (ie., we join in one or more tables that we don't actually
391 // read any columns from), we can stop scanning t2 as soon as we see the
392 // first row. This pattern seems to be a workaround for lack of semijoins
393 // in older versions of MySQL.
395
396 /** HAVING condition for checking prior saving a record into tmp table*/
398
399 // Operation between the previous QEP_TAB and this one.
401 // Regular nested loop.
403
404 // Aggregate (GROUP BY).
406
407 // Various temporary table operations, used at the end of the join.
412
413 // Block-nested loop (rewritten to hash join).
415
416 // Batch key access.
417 OT_BKA
419
420 /* Tmp table info */
422
423 /* Sorting related info */
425
426 /**
427 If we pushed a global ORDER BY down onto this first table, that ORDER BY
428 list will be preserved here.
429 */
431
432 /**
433 Slice number of the ref items array to switch to before reading rows from
434 this table.
435 */
437
438 /// Condition as it was set by the optimizer, used for EXPLAIN.
439 /// m_condition may be overwritten at a later stage.
441
442 /**
443 True if only index is going to be read for this table. This is the
444 optimizer's decision.
445 */
447
448 /**
449 True if reversed scan is used. This is the optimizer's decision.
450 */
452
453 /**
454 Maps of all lateral derived tables which should be refreshed when
455 execution reads a new row from this table.
456 @note that if a LDT depends on t1 and t2, and t2 is after t1 in the plan,
457 then only t2::lateral_derived_tables_depend_on_me gets the map of the
458 LDT, for efficiency (less useless calls to QEP_TAB::refresh_lateral())
459 and clarity in EXPLAIN.
460 */
462
464
465 QEP_TAB(const QEP_TAB &); // not defined
466 QEP_TAB &operator=(const QEP_TAB &); // not defined
467};
468
469bool set_record_buffer(TABLE *table, double expected_rows_to_fetch);
471void update_tmptable_sum_func(Item_sum **func_ptr, TABLE *tmp_table);
472bool has_rollup_result(Item *item);
473bool is_rollup_group_wrapper(const Item *item);
475
476/*
477 If a condition cannot be applied right away, for instance because it is a
478 WHERE condition and we're on the right side of an outer join, we have to
479 return it up so that it can be applied on a higher recursion level.
480 This structure represents such a condition.
481 */
484 int table_index_to_attach_to; // -1 means “on the last possible outer join”.
485};
486
487/**
488 Cache invalidator iterators we need to apply, but cannot yet due to outer
489 joins. As soon as “table_index_to_invalidate” is visible in our current join
490 nest (which means there could no longer be NULL-complemented rows we could
491 forget), we can and must output this invalidator and remove it from the array.
492 */
494 /**
495 The table whose every (post-join) row invalidates one or more derived
496 lateral tables.
497 */
500};
501
508
509/**
510 Create an AND conjunction of all given items. If there are no items, returns
511 nullptr. If there's only one item, returns that item.
512 */
514
517 const std::vector<Item *> &conditions, THD *thd);
518
519void SplitConditions(Item *condition, QEP_TAB *current_table,
520 std::vector<Item *> *predicates_below_join,
521 std::vector<PendingCondition> *predicates_above_join,
522 std::vector<PendingCondition> *join_conditions,
523 plan_idx semi_join_table_idx, qep_tab_map left_tables);
524
525/**
526 For a MATERIALIZE access path, move any non-basic iterators (e.g. sorts and
527 filters) from table_path to above the path, for easier EXPLAIN and generally
528 simpler structure. Note the assert in CreateIteratorFromAccessPath() that we
529 succeeded. (ALTERNATIVE counts as a basic iterator in this regard.)
530
531 We do this by finding the second-bottommost access path, and inserting our
532 materialize node as its child. The bottommost one becomes the actual table
533 access path.
534
535 If a ZERO_ROWS access path is materialized, we simply replace the MATERIALIZE
536 path with the ZERO_ROWS path, since there is nothing to materialize.
537 @param path the MATERIALIZE path.
538 @param query_block The query block in which 'path' belongs.
539 @returns The new root of the set of AccessPaths formed by 'path' and its
540 descendants.
541 */
543 const Query_block &query_block);
544
546 THD *thd, Table_ref *table_ref, TABLE *table, bool rematerialize,
547 Mem_root_array<const AccessPath *> *invalidators, bool need_rowid,
548 AccessPath *table_path);
549
550void ConvertItemsToCopy(const mem_root_deque<Item *> &items, Field **fields,
551 Temp_table_param *param);
552std::string RefToString(const Index_lookup &ref, const KEY &key,
553 bool include_nulls);
554
556
557/**
558 Split AND conditions into their constituent parts, recursively.
559 Conditions that are not AND conditions are appended unchanged onto
560 condition_parts. E.g. if you have ((a AND b) AND c), condition_parts
561 will contain [a, b, c], plus whatever it contained before the call.
562 */
563bool ExtractConditions(Item *condition,
564 Mem_root_array<Item *> *condition_parts);
565
567 AccessPath *range_scan,
568 Table_ref *table_ref, POSITION *position,
569 bool count_examined_rows);
570
571/**
572 Creates an iterator for the given table, then calls Init() on the resulting
573 iterator. Unlike create_table_iterator(), this can create iterators for sort
574 buffer results (which are set in the TABLE object during query execution).
575 Returns nullptr on failure.
576 */
578 THD *thd, TABLE *table, AccessPath *range_scan, Table_ref *table_ref,
579 POSITION *position, bool ignore_not_found_rows, bool count_examined_rows);
580
581/**
582 A short form for when there's no range scan, recursive CTEs or cost
583 information; just a unique_result or a simple table scan. Normally, you should
584 prefer just instantiating an iterator yourself -- this is for legacy use only.
585 */
587 THD *thd, TABLE *table, bool ignore_not_found_rows,
588 bool count_examined_rows) {
589 return init_table_iterator(thd, table, nullptr, nullptr, nullptr,
590 ignore_not_found_rows, count_examined_rows);
591}
592
593AccessPath *ConnectJoins(plan_idx upper_first_idx, plan_idx first_idx,
594 plan_idx last_idx, QEP_TAB *qep_tabs, THD *thd,
595 CallingContext calling_context,
596 std::vector<PendingCondition> *pending_conditions,
597 std::vector<PendingInvalidator> *pending_invalidators,
598 std::vector<PendingCondition> *pending_join_conditions,
599 qep_tab_map *unhandled_duplicates,
600 table_map *conditions_depend_on_outer_tables);
601
602#endif /* SQL_EXECUTOR_INCLUDED */
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:250
This is used for segregating rows in groups (e.g.
Definition: item.h:6516
Definition: field.h:2391
Definition: field.h:574
Sorting related info.
Definition: filesort.h:51
Class Item_sum is the base class used for special expressions that SQL calls 'set functions'.
Definition: item_sum.h:398
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:933
Query optimization plan node.
Definition: sql_select.h:601
Definition: sql_optimizer.h:132
Definition: key.h:112
Definition: sql_list.h:434
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:425
A JSON object (unordered set of key/value pairs).
Definition: opt_trace.h:801
Definition: sql_executor.h:253
uint loosescan_key_len
Definition: sql_executor.h:364
bool dynamic_range() const
Definition: sql_executor.h:324
Setup_func materialize_table
Definition: sql_executor.h:383
void set_reversed_access(bool arg)
Definition: sql_executor.h:287
Item * m_condition_optim
Condition as it was set by the optimizer, used for EXPLAIN.
Definition: sql_executor.h:440
bool rematerialize
Dependent table functions have to be materialized on each new scan.
Definition: sql_executor.h:375
bool keyread_optim() const
Definition: sql_executor.h:282
Filesort * filesort
Definition: sql_executor.h:424
bool reversed_access() const
Definition: sql_executor.h:286
void set_table(TABLE *t)
Definition: sql_executor.h:289
uint ref_item_slice
Slice number of the ref items array to switch to before reading rows from this table.
Definition: sql_executor.h:436
bool m_reversed_access
True if reversed scan is used.
Definition: sql_executor.h:451
qep_tab_map lateral_derived_tables_depend_on_me
Maps of all lateral derived tables which should be refreshed when execution reads a new row from this...
Definition: sql_executor.h:461
bool needs_duplicate_removal
true <=> remove duplicates on this table.
Definition: sql_executor.h:387
plan_idx firstmatch_return
Definition: sql_executor.h:358
enum QEP_TAB::enum_op_type op_type
bool do_firstmatch() const
Return true if join_tab should perform a FirstMatch action.
Definition: sql_executor.h:298
ORDER * filesort_pushed_order
If we pushed a global ORDER BY down onto this first table, that ORDER BY list will be preserved here.
Definition: sql_executor.h:430
Setup_func
Definition: sql_executor.h:377
@ NO_SETUP
Definition: sql_executor.h:378
@ MATERIALIZE_TABLE_FUNCTION
Definition: sql_executor.h:379
@ MATERIALIZE_SEMIJOIN
Definition: sql_executor.h:381
@ MATERIALIZE_DERIVED
Definition: sql_executor.h:380
QEP_TAB()
Definition: sql_executor.h:255
Item * condition_optim() const
Definition: sql_executor.h:280
QEP_TAB & operator=(const QEP_TAB &)
bool not_used_in_distinct
Definition: sql_executor.h:394
bool starts_weedout() const
Return true if join_tab starts a Duplicate Weedout action.
Definition: sql_executor.h:304
bool m_keyread_optim
True if only index is going to be read for this table.
Definition: sql_executor.h:446
bool using_dynamic_range
Definition: sql_executor.h:384
bool finishes_weedout() const
Return true if join_tab finishes a Duplicate Weedout action.
Definition: sql_executor.h:307
bool do_loosescan() const
Return true if join_tab should perform a LooseScan action.
Definition: sql_executor.h:301
Item * having
HAVING condition for checking prior saving a record into tmp table.
Definition: sql_executor.h:397
SJ_TMP_TABLE * flush_weedout_table
Definition: sql_executor.h:350
Temp_table_param * tmp_table_param
Definition: sql_executor.h:421
void set_condition_optim()
Definition: sql_executor.h:281
plan_idx match_tab
Definition: sql_executor.h:372
Table_ref * table_ref
Pointer to table reference.
Definition: sql_executor.h:347
SJ_TMP_TABLE * check_weed_out_table
Definition: sql_executor.h:351
enum_op_type
Definition: sql_executor.h:400
@ OT_MATERIALIZE
Definition: sql_executor.h:408
@ OT_BKA
Definition: sql_executor.h:417
@ OT_AGGREGATE_INTO_TMP_TABLE
Definition: sql_executor.h:410
@ OT_AGGREGATE
Definition: sql_executor.h:405
@ OT_BNL
Definition: sql_executor.h:414
@ OT_AGGREGATE_THEN_MATERIALIZE
Definition: sql_executor.h:409
@ OT_WINDOWING_FUNCTION
Definition: sql_executor.h:411
@ OT_NONE
Definition: sql_executor.h:402
Mem_root_array< const AccessPath * > * invalidators
Definition: sql_executor.h:463
QEP_TAB(const QEP_TAB &)
void set_keyread_optim()
Definition: sql_executor.h:283
Owner of a QEP_shared; parent of JOIN_TAB and QEP_TAB.
Definition: sql_opt_exec_shared.h:477
JOIN * join() const
Definition: sql_opt_exec_shared.h:490
TABLE * table() const
Definition: sql_opt_exec_shared.h:503
QEP_shared * m_qs
Definition: sql_opt_exec_shared.h:573
Item * condition() const
Definition: sql_opt_exec_shared.h:525
POSITION * position() const
Definition: sql_opt_exec_shared.h:504
void set_table(TABLE *t)
Definition: sql_opt_exec_shared.h:276
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1161
A context for reading through a single table using a chosen access method: index read,...
Definition: row_iterator.h:81
Definition: sql_executor.h:94
uint rowid_len
Definition: sql_executor.h:118
TABLE * tmp_table
Definition: sql_executor.h:121
SJ_TMP_TABLE_TAB * tabs
Definition: sql_executor.h:97
SJ_TMP_TABLE * next
Definition: sql_executor.h:124
uint null_bits
Definition: sql_executor.h:116
SJ_TMP_TABLE_TAB * tabs_end
Definition: sql_executor.h:98
bool have_confluent_row
Definition: sql_executor.h:113
SJ_TMP_TABLE()
Definition: sql_executor.h:96
uint null_bytes
Definition: sql_executor.h:117
bool is_confluent
Definition: sql_executor.h:107
Field_longlong * hash_field
Definition: sql_executor.h:126
Executor structure for the materialized semi-join info, which contains.
Definition: sql_executor.h:134
const bool is_scan
true if executing a scan, false if lookup
Definition: sql_executor.h:147
TABLE * table
Reference to temporary table.
Definition: sql_executor.h:152
Table_ref *const sj_nest
Semi-join nest for this materialization.
Definition: sql_executor.h:146
const uint inner_table_index
Index in join_tab for first inner table.
Definition: sql_executor.h:150
const uint mat_table_index
Index in join_tab for materialized table.
Definition: sql_executor.h:149
Temp_table_param table_param
The temptable and its related info.
Definition: sql_executor.h:151
~Semijoin_mat_exec()=default
const uint table_count
Number of tables in the sj-nest.
Definition: sql_executor.h:148
Semijoin_mat_exec(Table_ref *sj_nest, bool is_scan, uint table_count, uint mat_table_index, uint inner_table_index)
Definition: sql_executor.h:136
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
Definition: table.h:2853
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:94
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:110
Item * unwrap_rollup_group(Item *item)
Definition: sql_executor.cc:337
void init_tmptable_sum_functions(Item_sum **func_ptr)
Definition: sql_executor.cc:397
bool pfs_batch_update(const JOIN *join) const
Definition: sql_executor.cc:4673
ulonglong calc_row_hash(TABLE *table)
Generate hash for unique_constraint for all visible fields of a table.
Definition: sql_executor.cc:4040
bool setup_sum_funcs(THD *thd, Item_sum **func_ptr)
Call setup() for all sum functions.
Definition: sql_executor.cc:388
bool copy_funcs(Temp_table_param *, const THD *thd, Copy_func_type type=CFT_ALL)
Copy result of functions to record in tmp_table.
Definition: sql_executor.cc:429
bool has_rollup_result(Item *item)
Checks if an item has a ROLLUP NULL which needs to be written to temp table.
Definition: sql_executor.cc:307
int join_read_const_table(JOIN_TAB *tab, POSITION *pos)
Reads content of constant table.
Definition: sql_executor.cc:3513
bool construct_lookup(THD *thd, TABLE *table, Index_lookup *ref)
Copy the lookup key into the table ref's key buffer.
Definition: sql_executor.cc:4095
int do_sj_dups_weedout(THD *thd, SJ_TMP_TABLE *sjtbl)
SemiJoinDuplicateElimination: Weed out duplicate row combinations.
Definition: sql_executor.cc:3416
AccessPath * MoveCompositeIteratorsFromTablePath(AccessPath *path, const Query_block &query_block)
For a MATERIALIZE access path, move any non-basic iterators (e.g.
Definition: sql_executor.cc:1536
int report_handler_error(TABLE *table, int error)
Help function when we get some an error from the table handler.
Definition: sql_executor.cc:3486
void setup_tmptable_write_func(QEP_TAB *tab, Opt_trace_object *trace)
Setup write_func of QEP_tmp_table object.
Definition: sql_executor.cc:518
int update_item_cache_if_changed(List< Cached_item > &list)
Definition: sql_executor.cc:4177
AccessPath * access_path()
Construct an access path for reading from this table in the query, using the access method that has b...
Definition: sql_executor.cc:3730
int read_const(TABLE *table, Index_lookup *ref)
Definition: sql_executor.cc:3644
bool use_order() const
Use ordering provided by chosen index?
Definition: sql_executor.cc:3704
AccessPath * GetAccessPathForDerivedTable(THD *thd, Table_ref *table_ref, TABLE *table, bool rematerialize, Mem_root_array< const AccessPath * > *invalidators, bool need_rowid, AccessPath *table_path)
Definition: sql_executor.cc:1640
bool is_rollup_group_wrapper(const Item *item)
Definition: sql_executor.cc:331
bool change_to_use_tmp_fields_except_sums(mem_root_deque< Item * > *fields, THD *thd, Query_block *select, Ref_item_array ref_item_array, mem_root_deque< Item * > *res_fields, size_t added_non_hidden_fields)
Change all sum_func refs to fields to point at fields in tmp table.
Definition: sql_executor.cc:4445
bool make_group_fields(JOIN *main_join, JOIN *curr_join)
allocate group fields or take prepared (cached).
Definition: sql_executor.cc:4135
bool change_to_use_tmp_fields(mem_root_deque< Item * > *fields, THD *thd, Ref_item_array ref_item_array, mem_root_deque< Item * > *res_fields, size_t added_non_hidden_fields, bool windowing=false)
Change all funcs and sum_funcs to fields in tmp table, and create new list of all items.
Definition: sql_executor.cc:4288
bool check_unique_fields(TABLE *table)
Check whether a row is already present in the tmp table.
Definition: sql_executor.cc:4067
void update_tmptable_sum_func(Item_sum **func_ptr, TABLE *tmp_table)
Update record 0 in tmp_table from record 1.
Definition: sql_executor.cc:405
bool table_rec_cmp(TABLE *table)
Compare GROUP BY in from tmp table's record[0] and record[1].
Definition: sql_executor.cc:3956
std::string RefToString(const Index_lookup &ref, const KEY &key, bool include_nulls)
Definition: sql_executor.cc:130
Item * CreateConjunction(List< Item > *items)
Create an AND conjunction of all given items.
Definition: sql_executor.cc:735
bool set_record_buffer(TABLE *table, double expected_rows_to_fetch)
Allocate a data buffer that the storage engine can use for fetching batches of records.
Definition: sql_executor.cc:654
bool copy_fields(Temp_table_param *param, const THD *thd, bool reverse_copy=false)
Make a copy of all simple SELECT'ed fields.
Definition: sql_executor.cc:4224
void ConvertItemsToCopy(const mem_root_deque< Item * > &items, Field **fields, Temp_table_param *param)
For historical reasons, derived table materialization and temporary table materialization didn't spec...
Definition: sql_executor.cc:927
bool ExtractConditions(Item *condition, Mem_root_array< Item * > *condition_parts)
Split AND conditions into their constituent parts, recursively.
Definition: sql_executor.cc:707
ulonglong calc_field_hash(const Field *field, ulonglong *hash)
Generate hash for a field.
Definition: sql_executor.cc:3974
bool prepare_sum_aggregators(Item_sum **func_ptr, bool need_distinct)
Definition: sql_executor.cc:362
void init(JOIN_TAB *jt)
Initializes the object from a JOIN_TAB.
Definition: sql_optimizer.cc:1325
void init_join_cache(JOIN_TAB *join_tab)
A helper function that allocates appropriate join cache object and sets next_query_block function of ...
Definition: sql_select.cc:3254
void push_index_cond(const JOIN_TAB *join_tab, uint keyno, Opt_trace_object *trace_obj)
Try to extract and push the index condition down to table handler.
Definition: sql_select.cc:2924
void cleanup()
Definition: sql_select.cc:3511
uint sjm_query_block_id() const
Definition: sql_select.cc:3567
uint effective_index() const
Return the index used for a table in a QEP.
Definition: sql_optimizer.cc:1352
uint get_sj_strategy() const
Definition: sql_optimizer.cc:1332
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:476
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
unsigned char uchar
Definition: my_inttypes.h:51
uint64_t table_map
Definition: my_table_map.h:29
uint64_t qep_tab_map
Definition: my_table_map.h:31
static char * path
Definition: mysqldump.cc:148
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
PT & ref(PT *tp)
Definition: tablespace_impl.cc:358
std::list< T, ut::allocator< T > > list
Specialization of list which uses ut_allocator.
Definition: ut0new.h:2877
required string key
Definition: replication_asynchronous_connection_failover.proto:59
required string type
Definition: replication_group_member_actions.proto:33
AccessPath * ConnectJoins(plan_idx upper_first_idx, plan_idx first_idx, plan_idx last_idx, QEP_TAB *qep_tabs, THD *thd, CallingContext calling_context, std::vector< PendingCondition > *pending_conditions, std::vector< PendingInvalidator > *pending_invalidators, std::vector< PendingCondition > *pending_join_conditions, qep_tab_map *unhandled_duplicates, table_map *conditions_depend_on_outer_tables)
bool MaterializeIsDoingDeduplication(TABLE *table)
(end of group Query_Executor)
Definition: sql_executor.cc:4691
AccessPath * create_table_access_path(THD *thd, TABLE *table, AccessPath *range_scan, Table_ref *table_ref, POSITION *position, bool count_examined_rows)
create_table_access_path is used to scan by using a number of different methods.
Definition: sql_executor.cc:4761
unique_ptr_destroy_only< RowIterator > PossiblyAttachFilterIterator(unique_ptr_destroy_only< RowIterator > iterator, const std::vector< Item * > &conditions, THD *thd)
void SplitConditions(Item *condition, QEP_TAB *current_table, std::vector< Item * > *predicates_below_join, std::vector< PendingCondition > *predicates_above_join, std::vector< PendingCondition > *join_conditions, plan_idx semi_join_table_idx, qep_tab_map left_tables)
CallingContext
Definition: sql_executor.h:502
@ DIRECTLY_UNDER_OUTER_JOIN
Definition: sql_executor.h:505
@ TOP_LEVEL
Definition: sql_executor.h:503
@ DIRECTLY_UNDER_WEEDOUT
Definition: sql_executor.h:506
@ DIRECTLY_UNDER_SEMIJOIN
Definition: sql_executor.h:504
unique_ptr_destroy_only< RowIterator > init_table_iterator(THD *thd, TABLE *table, AccessPath *range_scan, Table_ref *table_ref, POSITION *position, bool ignore_not_found_rows, bool count_examined_rows)
Creates an iterator for the given table, then calls Init() on the resulting iterator.
Definition: sql_executor.cc:4781
Copy_func_type
Definition: sql_executor.h:160
@ CFT_HAS_NO_WF
In first windowing step, copies non-window functions which do not rely on window functions,...
Definition: sql_executor.h:191
@ CFT_WF_NON_FRAMING
In windowing step, copies non framing window function, e.g.
Definition: sql_executor.h:175
@ CFT_WF_NEEDS_PARTITION_CARDINALITY
In windowing step, copies window functions that need frame cardinality, that is we need to read all r...
Definition: sql_executor.h:181
@ CFT_WF_FRAMING
In windowing step, copies framing window function, including all grouping aggregates,...
Definition: sql_executor.h:169
@ CFT_ALL
In non-windowing step, copies functions.
Definition: sql_executor.h:164
@ CFT_FIELDS
Copies Item_field only (typically because other functions might depend on those fields).
Definition: sql_executor.h:206
@ CFT_HAS_WF
In final windowing step, copies all non-wf functions.
Definition: sql_executor.h:197
@ CFT_WF_USES_ONLY_ONE_ROW
In windowing step, copies framing window functions that read only one row per frame.
Definition: sql_executor.h:186
@ CFT_WF
Copies all window functions.
Definition: sql_executor.h:201
Common types of the Optimizer, used by optimization and execution.
int plan_idx
This represents the index of a JOIN_TAB/QEP_TAB in an array.
Definition: sql_opt_exec_shared.h:53
@ REF_SLICE_SAVED_BASE
The slice with pointers to columns of table(s), ie., the actual Items.
Definition: sql_opt_exec_shared.h:637
#define NO_PLAN_IDX
undefined index
Definition: sql_opt_exec_shared.h:54
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:212
Structure used for index-based lookups.
Definition: sql_opt_exec_shared.h:66
Definition: table.h:283
A position of table within a join order.
Definition: sql_select.h:354
Definition: sql_executor.h:482
Item * cond
Definition: sql_executor.h:483
int table_index_to_attach_to
Definition: sql_executor.h:484
Cache invalidator iterators we need to apply, but cannot yet due to outer joins.
Definition: sql_executor.h:493
QEP_TAB * qep_tab
The table whose every (post-join) row invalidates one or more derived lateral tables.
Definition: sql_executor.h:498
plan_idx table_index_to_invalidate
Definition: sql_executor.h:499
Definition: sql_executor.h:70
QEP_TAB * qep_tab
Definition: sql_executor.h:71
ushort null_byte
Definition: sql_executor.h:73
uchar null_bit
Definition: sql_executor.h:74
uint rowid_offset
Definition: sql_executor.h:72
Definition: table.h:1403
class QEP_TAB * qep_tab
Definition: table.h:1883
bool key_read
If set, the optimizer has found that row retrieval should access index tree only.
Definition: table.h:1808
struct TABLE::@184 reginfo