MySQL 8.0.33
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 <cstring>
33#include <memory>
34#include <string>
35#include <vector>
36
37#include "my_alloc.h"
38#include "my_inttypes.h"
39#include "my_table_map.h"
41#include "sql/sql_lex.h"
42#include "sql/sql_opt_exec_shared.h" // QEP_shared_owner
43#include "sql/table.h"
44#include "sql/temp_table_param.h" // Temp_table_param
45
47class Cached_item;
48class Field;
49class Field_longlong;
50class Filesort;
52class Item;
53class Item_sum;
54class JOIN;
55class JOIN_TAB;
56class KEY;
59class QEP_TAB;
60class RowIterator;
61class THD;
62class Window;
63template <class T>
64class mem_root_deque;
65
67struct AccessPath;
68struct CACHE_FIELD;
69struct POSITION;
70template <class T>
71class List;
72template <typename Element_type>
73class Mem_root_array;
74
75/*
76 Array of pointers to tables whose rowids compose the temporary table
77 record.
78*/
82 ushort null_byte;
84};
85
86/*
87 Temporary table used by semi-join DuplicateElimination strategy
88
89 This consists of the temptable itself and data needed to put records
90 into it. The table's DDL is as follows:
91
92 CREATE TABLE tmptable (col VARCHAR(n) BINARY, PRIMARY KEY(col));
93
94 where the primary key can be replaced with unique constraint if n exceeds
95 the limit (as it is always done for query execution-time temptables).
96
97 The record value is a concatenation of rowids of tables from the join we're
98 executing. If a join table is on the inner side of the outer join, we
99 assume that its rowid can be NULL and provide means to store this rowid in
100 the tuple.
101*/
102
104 public:
108
109 /*
110 is_confluent==true means this is a special case where the temptable record
111 has zero length (and presence of a unique key means that the temptable can
112 have either 0 or 1 records).
113 In this case we don't create the physical temptable but instead record
114 its state in SJ_TMP_TABLE::have_confluent_record.
115 */
117
118 /*
119 When is_confluent==true: the contents of the table (whether it has the
120 record or not).
121 */
123
124 /* table record parameters */
128
129 /* The temporary table itself (NULL means not created yet) */
131
132 /* Pointer to next table (next->start_idx > this->end_idx) */
134 /* Calc hash instead of too long key */
136};
137
138/**
139 Executor structure for the materialized semi-join info, which contains
140 - Description of expressions selected from subquery
141 - The sj-materialization temporary table
142*/
144 public:
147 : sj_nest(sj_nest),
152 table_param(),
153 table(nullptr) {}
155 Table_ref *const sj_nest; ///< Semi-join nest for this materialization
156 const bool is_scan; ///< true if executing a scan, false if lookup
157 const uint table_count; ///< Number of tables in the sj-nest
158 const uint mat_table_index; ///< Index in join_tab for materialized table
159 const uint inner_table_index; ///< Index in join_tab for first inner table
160 Temp_table_param table_param; ///< The temptable and its related info
161 TABLE *table; ///< Reference to temporary table
162};
163
165
166[[nodiscard]] bool copy_fields(Temp_table_param *param, const THD *thd,
167 bool reverse_copy = false);
168
169enum Copy_func_type : int {
170 /**
171 In non-windowing step, copies functions
172 */
174 /**
175 In windowing step, copies framing window function, including
176 all grouping aggregates, e.g. SUM, AVG and FIRST_VALUE, LAST_VALUE.
177 */
179 /**
180 In windowing step, copies non framing window function, e.g.
181 ROW_NUMBER, RANK, DENSE_RANK, except those that are two_pass cf.
182 copy_two_pass_window_functions which are treated separately.
183 */
185 /**
186 In windowing step, copies window functions that need frame cardinality,
187 that is we need to read all rows of a partition before we can compute the
188 wf's value for the the first row in the partition.
189 */
191 /**
192 In windowing step, copies framing window functions that read only one row
193 per frame.
194 */
196 /**
197 In first windowing step, copies non-window functions which do not rely on
198 window functions, i.e. those that have Item::has_wf() == false.
199 */
201 /**
202 In final windowing step, copies all non-wf functions. Must be called after
203 all wfs have been evaluated, as non-wf functions may reference wf,
204 e.g. 1+RANK.
205 */
207 /**
208 Copies all window functions.
209 */
211 /**
212 Copies Item_field only (typically because other functions might depend
213 on those fields).
214 */
216};
217
218bool copy_funcs(Temp_table_param *, const THD *thd,
220
221/**
222 Copy the lookup key into the table ref's key buffer.
223
224 @param thd pointer to the THD object
225 @param table the table to read
226 @param ref information about the index lookup key
227
228 @retval false ref key copied successfully
229 @retval true error detected during copying of key
230*/
231bool construct_lookup(THD *thd, TABLE *table, Index_lookup *ref);
232
233/** Help function when we get some an error from the table handler. */
234int report_handler_error(TABLE *table, int error);
235
237
238int do_sj_dups_weedout(THD *thd, SJ_TMP_TABLE *sjtbl);
240
241// Create list for using with temporary table
243 Ref_item_array ref_item_array,
244 mem_root_deque<Item *> *res_fields,
245 size_t added_non_hidden_fields);
246// Create list for using with temporary table
248 THD *thd, Query_block *select,
249 Ref_item_array ref_item_array,
250 mem_root_deque<Item *> *res_fields,
251 size_t added_non_hidden_fields);
252bool prepare_sum_aggregators(Item_sum **func_ptr, bool need_distinct);
253bool setup_sum_funcs(THD *thd, Item_sum **func_ptr);
254bool make_group_fields(JOIN *main_join, JOIN *curr_join);
255bool check_unique_constraint(TABLE *table);
256ulonglong unique_hash(const Field *field, ulonglong *hash);
257int read_const(TABLE *table, Index_lookup *ref);
258
259class QEP_TAB : public QEP_shared_owner {
260 public:
269 rematerialize(false),
275 m_keyread_optim(false),
276 m_reversed_access(false),
278
279 /// Initializes the object from a JOIN_TAB
280 void init(JOIN_TAB *jt);
281 // Cleans up.
282 void cleanup();
283
284 // Getters and setters
285
288 bool keyread_optim() const { return m_keyread_optim; }
291 }
292 bool reversed_access() const { return m_reversed_access; }
293 void set_reversed_access(bool arg) { m_reversed_access = arg; }
294
295 void set_table(TABLE *t) {
296 m_qs->set_table(t);
297 if (t) t->reginfo.qep_tab = this;
298 }
299
300 /// @returns semijoin strategy for this table.
301 uint get_sj_strategy() const;
302
303 /// Return true if join_tab should perform a FirstMatch action
304 bool do_firstmatch() const { return firstmatch_return != NO_PLAN_IDX; }
305
306 /// Return true if join_tab should perform a LooseScan action
307 bool do_loosescan() const { return loosescan_key_len; }
308
309 /// Return true if join_tab starts a Duplicate Weedout action
310 bool starts_weedout() const { return flush_weedout_table; }
311
312 /// Return true if join_tab finishes a Duplicate Weedout action
313 bool finishes_weedout() const { return check_weed_out_table; }
314
315 /**
316 A helper function that allocates appropriate join cache object and
317 sets next_query_block function of previous tab.
318 */
319 void init_join_cache(JOIN_TAB *join_tab);
320
321 /**
322 @returns query block id for an inner table of materialized semi-join, and
323 0 for all other tables.
324 @note implementation is not efficient (loops over all tables) - use this
325 function only in EXPLAIN.
326 */
327 uint sjm_query_block_id() const;
328
329 /// @returns whether this is doing QS_DYNAMIC_RANGE
330 bool dynamic_range() const {
331 if (!position()) return false; // tmp table
332 return using_dynamic_range;
333 }
334
335 bool use_order() const; ///< Use ordering provided by chosen index?
336
337 /**
338 Construct an access path for reading from this table in the query,
339 using the access method that has been determined previously
340 (e.g., table scan, ref access, optional sort afterwards, etc.).
341 */
343 void push_index_cond(const JOIN_TAB *join_tab, uint keyno,
344 Opt_trace_object *trace_obj);
345
346 /// @return the index used for a table in a QEP
347 uint effective_index() const;
348
349 bool pfs_batch_update(const JOIN *join) const;
350
351 public:
352 /// Pointer to table reference
354
355 /* Variables for semi-join duplicate elimination */
358
359 /*
360 If set, means we should stop join enumeration after we've got the first
361 match and return to the specified join tab. May be PRE_FIRST_PLAN_IDX
362 which means stopping join execution after the first match.
363 */
365
366 /*
367 Length of key tuple (depends on #keyparts used) to use for loose scan.
368 If zero, means that loosescan is not used.
369 */
371
372 /*
373 If doing a LooseScan, this QEP is the first (i.e. "driving")
374 QEP_TAB, and match_tab points to the last QEP_TAB handled by the strategy.
375 match_tab->found_match should be checked to see if the current value group
376 had a match.
377 */
379
380 /// Dependent table functions have to be materialized on each new scan
382
388 };
391
392 /** true <=> remove duplicates on this table. */
394
395 // If we have a query of the type SELECT DISTINCT t1.* FROM t1 JOIN t2
396 // ON ..., (ie., we join in one or more tables that we don't actually
397 // read any columns from), we can stop scanning t2 as soon as we see the
398 // first row. This pattern seems to be a workaround for lack of semijoins
399 // in older versions of MySQL.
401
402 /** HAVING condition for checking prior saving a record into tmp table*/
404
405 // Operation between the previous QEP_TAB and this one.
407 // Regular nested loop.
409
410 // Aggregate (GROUP BY).
412
413 // Various temporary table operations, used at the end of the join.
418
419 // Block-nested loop (rewritten to hash join).
421
422 // Batch key access.
423 OT_BKA
425
426 /* Tmp table info */
428
429 /* Sorting related info */
431
432 /**
433 If we pushed a global ORDER BY down onto this first table, that ORDER BY
434 list will be preserved here.
435 */
437
438 /**
439 Slice number of the ref items array to switch to before reading rows from
440 this table.
441 */
443
444 /// Condition as it was set by the optimizer, used for EXPLAIN.
445 /// m_condition may be overwritten at a later stage.
447
448 /**
449 True if only index is going to be read for this table. This is the
450 optimizer's decision.
451 */
453
454 /**
455 True if reversed scan is used. This is the optimizer's decision.
456 */
458
459 /**
460 Maps of all lateral derived tables which should be refreshed when
461 execution reads a new row from this table.
462 @note that if a LDT depends on t1 and t2, and t2 is after t1 in the plan,
463 then only t2::lateral_derived_tables_depend_on_me gets the map of the
464 LDT, for efficiency (less useless calls to QEP_TAB::refresh_lateral())
465 and clarity in EXPLAIN.
466 */
468
470
471 QEP_TAB(const QEP_TAB &); // not defined
472 QEP_TAB &operator=(const QEP_TAB &); // not defined
473};
474
475bool set_record_buffer(TABLE *table, double expected_rows_to_fetch);
477void update_tmptable_sum_func(Item_sum **func_ptr, TABLE *tmp_table);
478bool has_rollup_result(Item *item);
479bool is_rollup_group_wrapper(Item *item);
481
482/*
483 If a condition cannot be applied right away, for instance because it is a
484 WHERE condition and we're on the right side of an outer join, we have to
485 return it up so that it can be applied on a higher recursion level.
486 This structure represents such a condition.
487 */
490 int table_index_to_attach_to; // -1 means “on the last possible outer join”.
491};
492
493/**
494 Cache invalidator iterators we need to apply, but cannot yet due to outer
495 joins. As soon as “table_index_to_invalidate” is visible in our current join
496 nest (which means there could no longer be NULL-complemented rows we could
497 forget), we can and must output this invalidator and remove it from the array.
498 */
500 /**
501 The table whose every (post-join) row invalidates one or more derived
502 lateral tables.
503 */
506};
507
514
515/**
516 Create an AND conjunction of all given items. If there are no items, returns
517 nullptr. If there's only one item, returns that item.
518 */
520
523 const std::vector<Item *> &conditions, THD *thd);
524
525void SplitConditions(Item *condition, QEP_TAB *current_table,
526 std::vector<Item *> *predicates_below_join,
527 std::vector<PendingCondition> *predicates_above_join,
528 std::vector<PendingCondition> *join_conditions,
529 plan_idx semi_join_table_idx, qep_tab_map left_tables);
530
531/**
532 For a MATERIALIZE access path, move any non-basic iterators (e.g. sorts and
533 filters) from table_path to above the path, for easier EXPLAIN and generally
534 simpler structure. Note the assert in CreateIteratorFromAccessPath() that we
535 succeeded. (ALTERNATIVE counts as a basic iterator in this regard.)
536
537 We do this by finding the second-bottommost access path, and inserting our
538 materialize node as its child. The bottommost one becomes the actual table
539 access path.
540
541 If a ZERO_ROWS access path is materialized, we simply replace the MATERIALIZE
542 path with the ZERO_ROWS path, since there is nothing to materialize.
543 @param path the MATERIALIZE path.
544 @param query_block The query block in which 'path' belongs.
545 @returns The new root of the set of AccessPaths formed by 'path' and its
546 descendants.
547 */
549 const Query_block &query_block);
550
552 AccessPath *table_path);
554 THD *thd, Table_ref *table_ref, TABLE *table, bool rematerialize,
555 Mem_root_array<const AccessPath *> *invalidators, bool need_rowid,
556 AccessPath *table_path);
557
558void ConvertItemsToCopy(const mem_root_deque<Item *> &items, Field **fields,
559 Temp_table_param *param);
560std::string RefToString(const Index_lookup &ref, const KEY *key,
561 bool include_nulls);
562
564
565/**
566 Split AND conditions into their constituent parts, recursively.
567 Conditions that are not AND conditions are appended unchanged onto
568 condition_parts. E.g. if you have ((a AND b) AND c), condition_parts
569 will contain [a, b, c], plus whatever it contained before the call.
570 */
571bool ExtractConditions(Item *condition,
572 Mem_root_array<Item *> *condition_parts);
573
575 AccessPath *range_scan,
576 Table_ref *table_ref, POSITION *position,
577 bool count_examined_rows);
578
579/**
580 Creates an iterator for the given table, then calls Init() on the resulting
581 iterator. Unlike create_table_iterator(), this can create iterators for sort
582 buffer results (which are set in the TABLE object during query execution).
583 Returns nullptr on failure.
584 */
586 THD *thd, TABLE *table, AccessPath *range_scan, Table_ref *table_ref,
587 POSITION *position, bool ignore_not_found_rows, bool count_examined_rows);
588
589/**
590 A short form for when there's no range scan, recursive CTEs or cost
591 information; just a unique_result or a simple table scan. Normally, you should
592 prefer just instantiating an iterator yourself -- this is for legacy use only.
593 */
595 THD *thd, TABLE *table, bool ignore_not_found_rows,
596 bool count_examined_rows) {
597 return init_table_iterator(thd, table, nullptr, nullptr, nullptr,
598 ignore_not_found_rows, count_examined_rows);
599}
600
601AccessPath *ConnectJoins(plan_idx upper_first_idx, plan_idx first_idx,
602 plan_idx last_idx, QEP_TAB *qep_tabs, THD *thd,
603 CallingContext calling_context,
604 std::vector<PendingCondition> *pending_conditions,
605 std::vector<PendingInvalidator> *pending_invalidators,
606 std::vector<PendingCondition> *pending_join_conditions,
607 qep_tab_map *unhandled_duplicates,
608 table_map *conditions_depend_on_outer_tables);
609
610#endif /* SQL_EXECUTOR_INCLUDED */
An iterator that helps invalidating caches.
Definition: composite_iterators.h:391
This is used for segregating rows in groups (e.g.
Definition: item.h:6300
Definition: field.h:2353
Definition: field.h:574
Sorting related info.
Definition: filesort.h:51
FollowTailIterator is a special version of TableScanIterator that is used as part of WITH RECURSIVE q...
Definition: basic_row_iterators.h:438
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:850
Query optimization plan node.
Definition: sql_select.h:598
Definition: sql_optimizer.h:132
Definition: key.h:112
Definition: sql_list.h:433
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:425
The iterator actually doing the reads from the inner table during BKA.
Definition: bka_iterator.h:263
A JSON object (unordered set of key/value pairs).
Definition: opt_trace.h:798
Definition: sql_executor.h:259
uint loosescan_key_len
Definition: sql_executor.h:370
bool dynamic_range() const
Definition: sql_executor.h:330
Setup_func materialize_table
Definition: sql_executor.h:389
void set_reversed_access(bool arg)
Definition: sql_executor.h:293
Item * m_condition_optim
Condition as it was set by the optimizer, used for EXPLAIN.
Definition: sql_executor.h:446
bool rematerialize
Dependent table functions have to be materialized on each new scan.
Definition: sql_executor.h:381
bool keyread_optim() const
Definition: sql_executor.h:288
Filesort * filesort
Definition: sql_executor.h:430
bool reversed_access() const
Definition: sql_executor.h:292
void set_table(TABLE *t)
Definition: sql_executor.h:295
uint ref_item_slice
Slice number of the ref items array to switch to before reading rows from this table.
Definition: sql_executor.h:442
bool m_reversed_access
True if reversed scan is used.
Definition: sql_executor.h:457
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:467
bool needs_duplicate_removal
true <=> remove duplicates on this table.
Definition: sql_executor.h:393
plan_idx firstmatch_return
Definition: sql_executor.h:364
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:304
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:436
Setup_func
Definition: sql_executor.h:383
@ NO_SETUP
Definition: sql_executor.h:384
@ MATERIALIZE_TABLE_FUNCTION
Definition: sql_executor.h:385
@ MATERIALIZE_SEMIJOIN
Definition: sql_executor.h:387
@ MATERIALIZE_DERIVED
Definition: sql_executor.h:386
QEP_TAB()
Definition: sql_executor.h:261
Item * condition_optim() const
Definition: sql_executor.h:286
QEP_TAB & operator=(const QEP_TAB &)
bool not_used_in_distinct
Definition: sql_executor.h:400
bool starts_weedout() const
Return true if join_tab starts a Duplicate Weedout action.
Definition: sql_executor.h:310
bool m_keyread_optim
True if only index is going to be read for this table.
Definition: sql_executor.h:452
bool using_dynamic_range
Definition: sql_executor.h:390
bool finishes_weedout() const
Return true if join_tab finishes a Duplicate Weedout action.
Definition: sql_executor.h:313
bool do_loosescan() const
Return true if join_tab should perform a LooseScan action.
Definition: sql_executor.h:307
Item * having
HAVING condition for checking prior saving a record into tmp table.
Definition: sql_executor.h:403
SJ_TMP_TABLE * flush_weedout_table
Definition: sql_executor.h:356
Temp_table_param * tmp_table_param
Definition: sql_executor.h:427
void set_condition_optim()
Definition: sql_executor.h:287
plan_idx match_tab
Definition: sql_executor.h:378
Table_ref * table_ref
Pointer to table reference.
Definition: sql_executor.h:353
SJ_TMP_TABLE * check_weed_out_table
Definition: sql_executor.h:357
enum_op_type
Definition: sql_executor.h:406
@ OT_MATERIALIZE
Definition: sql_executor.h:414
@ OT_BKA
Definition: sql_executor.h:423
@ OT_AGGREGATE_INTO_TMP_TABLE
Definition: sql_executor.h:416
@ OT_AGGREGATE
Definition: sql_executor.h:411
@ OT_BNL
Definition: sql_executor.h:420
@ OT_AGGREGATE_THEN_MATERIALIZE
Definition: sql_executor.h:415
@ OT_WINDOWING_FUNCTION
Definition: sql_executor.h:417
@ OT_NONE
Definition: sql_executor.h:408
Mem_root_array< const AccessPath * > * invalidators
Definition: sql_executor.h:469
QEP_TAB(const QEP_TAB &)
void set_keyread_optim()
Definition: sql_executor.h:289
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:1155
A context for reading through a single table using a chosen access method: index read,...
Definition: row_iterator.h:81
Definition: sql_executor.h:103
uint rowid_len
Definition: sql_executor.h:127
TABLE * tmp_table
Definition: sql_executor.h:130
SJ_TMP_TABLE_TAB * tabs
Definition: sql_executor.h:106
SJ_TMP_TABLE * next
Definition: sql_executor.h:133
uint null_bits
Definition: sql_executor.h:125
SJ_TMP_TABLE_TAB * tabs_end
Definition: sql_executor.h:107
bool have_confluent_row
Definition: sql_executor.h:122
SJ_TMP_TABLE()
Definition: sql_executor.h:105
uint null_bytes
Definition: sql_executor.h:126
bool is_confluent
Definition: sql_executor.h:116
Field_longlong * hash_field
Definition: sql_executor.h:135
Executor structure for the materialized semi-join info, which contains.
Definition: sql_executor.h:143
const bool is_scan
true if executing a scan, false if lookup
Definition: sql_executor.h:156
TABLE * table
Reference to temporary table.
Definition: sql_executor.h:161
Table_ref *const sj_nest
Semi-join nest for this materialization.
Definition: sql_executor.h:155
const uint inner_table_index
Index in join_tab for first inner table.
Definition: sql_executor.h:159
const uint mat_table_index
Index in join_tab for materialized table.
Definition: sql_executor.h:158
Temp_table_param table_param
The temptable and its related info.
Definition: sql_executor.h:160
~Semijoin_mat_exec()=default
const uint table_count
Number of tables in the sj-nest.
Definition: sql_executor.h:157
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:145
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
Definition: table.h:2761
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:94
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:104
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:109
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
Item * unwrap_rollup_group(Item *item)
Definition: sql_executor.cc:336
void init_tmptable_sum_functions(Item_sum **func_ptr)
Definition: sql_executor.cc:396
bool pfs_batch_update(const JOIN *join) const
Definition: sql_executor.cc:4620
bool is_rollup_group_wrapper(Item *item)
Definition: sql_executor.cc:330
bool setup_sum_funcs(THD *thd, Item_sum **func_ptr)
Call setup() for all sum functions.
Definition: sql_executor.cc:387
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:428
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:306
int join_read_const_table(JOIN_TAB *tab, POSITION *pos)
Reads content of constant table.
Definition: sql_executor.cc:3472
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:4053
ulonglong unique_hash(const Field *field, ulonglong *hash)
Generate hash for a field.
Definition: sql_executor.cc:3932
int do_sj_dups_weedout(THD *thd, SJ_TMP_TABLE *sjtbl)
SemiJoinDuplicateElimination: Weed out duplicate row combinations.
Definition: sql_executor.cc:3375
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:1529
int report_handler_error(TABLE *table, int error)
Help function when we get some an error from the table handler.
Definition: sql_executor.cc:3445
void setup_tmptable_write_func(QEP_TAB *tab, Opt_trace_object *trace)
Setup write_func of QEP_tmp_table object.
Definition: sql_executor.cc:517
int update_item_cache_if_changed(List< Cached_item > &list)
Definition: sql_executor.cc:4135
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:3689
int read_const(TABLE *table, Index_lookup *ref)
Definition: sql_executor.cc:3603
bool use_order() const
Use ordering provided by chosen index?
Definition: sql_executor.cc:3663
AccessPath * GetAccessPathForDerivedTable(THD *thd, QEP_TAB *qep_tab, AccessPath *table_path)
Definition: sql_executor.cc:1471
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:4392
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)
Change all funcs and sum_funcs to fields in tmp table, and create new list of all items.
Definition: sql_executor.cc:4245
bool check_unique_constraint(TABLE *table)
Check unique_constraint.
Definition: sql_executor.cc:4025
std::string RefToString(const Index_lookup &ref, const KEY *key, bool include_nulls)
Definition: sql_executor.cc:129
bool make_group_fields(JOIN *main_join, JOIN *curr_join)
allocate group fields or take prepared (cached).
Definition: sql_executor.cc:4093
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:404
Item * CreateConjunction(List< Item > *items)
Create an AND conjunction of all given items.
Definition: sql_executor.cc:734
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:653
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:4182
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:925
bool ExtractConditions(Item *condition, Mem_root_array< Item * > *condition_parts)
Split AND conditions into their constituent parts, recursively.
Definition: sql_executor.cc:706
bool prepare_sum_aggregators(Item_sum **func_ptr, bool need_distinct)
Definition: sql_executor.cc:361
void init(JOIN_TAB *jt)
Initializes the object from a JOIN_TAB.
Definition: sql_optimizer.cc:1318
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:3067
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:2738
void cleanup()
Definition: sql_select.cc:3333
uint sjm_query_block_id() const
Definition: sql_select.cc:3389
uint effective_index() const
Return the index used for a table in a QEP.
Definition: sql_optimizer.cc:1345
uint get_sj_strategy() const
Definition: sql_optimizer.cc:1325
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:488
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
Log error(cerr, "ERROR")
static char * path
Definition: mysqldump.cc:133
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:2876
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:4638
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:4673
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:508
@ DIRECTLY_UNDER_OUTER_JOIN
Definition: sql_executor.h:511
@ TOP_LEVEL
Definition: sql_executor.h:509
@ DIRECTLY_UNDER_WEEDOUT
Definition: sql_executor.h:512
@ DIRECTLY_UNDER_SEMIJOIN
Definition: sql_executor.h:510
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:4693
Copy_func_type
Definition: sql_executor.h:169
@ CFT_HAS_NO_WF
In first windowing step, copies non-window functions which do not rely on window functions,...
Definition: sql_executor.h:200
@ CFT_WF_NON_FRAMING
In windowing step, copies non framing window function, e.g.
Definition: sql_executor.h:184
@ 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:190
@ CFT_WF_FRAMING
In windowing step, copies framing window function, including all grouping aggregates,...
Definition: sql_executor.h:178
@ CFT_ALL
In non-windowing step, copies functions.
Definition: sql_executor.h:173
@ CFT_FIELDS
Copies Item_field only (typically because other functions might depend on those fields).
Definition: sql_executor.h:215
@ CFT_HAS_WF
In final windowing step, copies all non-wf functions.
Definition: sql_executor.h:206
@ CFT_WF_USES_ONLY_ONE_ROW
In windowing step, copies framing window functions that read only one row per frame.
Definition: sql_executor.h:195
@ CFT_WF
Copies all window functions.
Definition: sql_executor.h:210
Common types of the Optimizer, used by optimization and execution.
@ REF_SLICE_SAVED_BASE
The slice with pointers to columns of table(s), ie., the actual Items.
Definition: sql_opt_exec_shared.h:637
int plan_idx
This represents the index of a JOIN_TAB/QEP_TAB in an array.
Definition: sql_opt_exec_shared.h:53
#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:192
Structure used for index-based lookups.
Definition: sql_opt_exec_shared.h:66
Definition: table.h:280
A position of table within a join order.
Definition: sql_select.h:351
Definition: sql_executor.h:488
Item * cond
Definition: sql_executor.h:489
int table_index_to_attach_to
Definition: sql_executor.h:490
Cache invalidator iterators we need to apply, but cannot yet due to outer joins.
Definition: sql_executor.h:499
QEP_TAB * qep_tab
The table whose every (post-join) row invalidates one or more derived lateral tables.
Definition: sql_executor.h:504
plan_idx table_index_to_invalidate
Definition: sql_executor.h:505
Definition: sql_executor.h:79
QEP_TAB * qep_tab
Definition: sql_executor.h:80
ushort null_byte
Definition: sql_executor.h:82
uchar null_bit
Definition: sql_executor.h:83
uint rowid_offset
Definition: sql_executor.h:81
Definition: table.h:1395
class QEP_TAB * qep_tab
Definition: table.h:1808
bool key_read
If set, the optimizer has found that row retrieval should access index tree only.
Definition: table.h:1733
struct TABLE::@178 reginfo
unsigned int uint
Definition: uca9-dump.cc:74
Window_retrieve_cached_row_reason
Position hints for the frame buffer are saved for these kind of row accesses, cf.
Definition: window.h:64