MySQL  8.0.24
Source Code Documentation
Go to the documentation of this file.
4 /* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.
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.
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  GNU General Public License, version 2.0, for more details.
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 */
26 /**
27  @file sql/sql_executor.h
28  Classes for query execution.
29 */
31 #include <sys/types.h>
33 #include <cstring>
34 #include <memory>
35 #include <string>
36 #include <vector>
38 #include "my_alloc.h"
39 #include "my_compiler.h"
40 #include "my_inttypes.h"
41 #include "my_table_map.h"
42 #include "sql/row_iterator.h"
43 #include "sql/sql_lex.h"
44 #include "sql/sql_opt_exec_shared.h" // QEP_shared_owner
45 #include "sql/table.h"
46 #include "sql/temp_table_param.h" // Temp_table_param
49 class Cached_item;
50 class Field;
51 class Field_longlong;
52 class Filesort;
53 class FollowTailIterator;
54 class Item;
55 class Item_sum;
56 class JOIN;
57 class JOIN_TAB;
58 class KEY;
60 class Opt_trace_object;
61 class QEP_TAB;
62 class QUICK_SELECT_I;
63 class THD;
64 class Window;
66 struct AccessPath;
67 struct CACHE_FIELD;
68 struct POSITION;
69 template <class T>
70 class List;
71 template <typename Element_type>
72 class Mem_root_array;
74 /*
75  Array of pointers to tables whose rowids compose the temporary table
76  record.
77 */
81  ushort null_byte;
83 };
85 /*
86  Temporary table used by semi-join DuplicateElimination strategy
88  This consists of the temptable itself and data needed to put records
89  into it. The table's DDL is as follows:
91  CREATE TABLE tmptable (col VARCHAR(n) BINARY, PRIMARY KEY(col));
93  where the primary key can be replaced with unique constraint if n exceeds
94  the limit (as it is always done for query execution-time temptables).
96  The record value is a concatenation of rowids of tables from the join we're
97  executing. If a join table is on the inner side of the outer join, we
98  assume that its rowid can be NULL and provide means to store this rowid in
99  the tuple.
100 */
103  public:
108  /*
109  is_confluent==true means this is a special case where the temptable record
110  has zero length (and presence of a unique key means that the temptable can
111  have either 0 or 1 records).
112  In this case we don't create the physical temptable but instead record
113  its state in SJ_TMP_TABLE::have_confluent_record.
114  */
117  /*
118  When is_confluent==true: the contents of the table (whether it has the
119  record or not).
120  */
123  /* table record parameters */
128  /* The temporary table itself (NULL means not created yet) */
131  /* Pointer to next table (next->start_idx > this->end_idx) */
133  /* Calc hash instead of too long key */
135 };
137 /**
138  Executor structure for the materialized semi-join info, which contains
139  - Description of expressions selected from subquery
140  - The sj-materialization temporary table
141 */
143  public:
146  : sj_nest(sj_nest),
147  is_scan(is_scan),
151  table_param(),
152  table(nullptr) {}
154  TABLE_LIST *const sj_nest; ///< Semi-join nest for this materialization
155  const bool is_scan; ///< true if executing a scan, false if lookup
156  const uint table_count; ///< Number of tables in the sj-nest
157  const uint mat_table_index; ///< Index in join_tab for materialized table
158  const uint inner_table_index; ///< Index in join_tab for first inner table
159  Temp_table_param table_param; ///< The temptable and its related info
160  TABLE *table; ///< Reference to temporary table
161 };
165 MY_ATTRIBUTE((warn_unused_result))
166 bool copy_fields(Temp_table_param *param, const THD *thd,
167  bool reverse_copy = false);
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 };
213 bool copy_funcs(Temp_table_param *, const THD *thd,
216 // Combines copy_fields() and copy_funcs().
217 bool copy_fields_and_funcs(Temp_table_param *param, const THD *thd,
220 /**
221  Copy the lookup key into the table ref's key buffer.
223  @param thd pointer to the THD object
224  @param table the table to read
225  @param ref information about the index lookup key
227  @retval false ref key copied successfully
228  @retval true error dectected during copying of key
229 */
230 bool construct_lookup_ref(THD *thd, TABLE *table, TABLE_REF *ref);
232 /** Help function when we get some an error from the table handler. */
233 int report_handler_error(TABLE *table, int error);
235 int safe_index_read(QEP_TAB *tab);
239 int do_sj_dups_weedout(THD *thd, SJ_TMP_TABLE *sjtbl);
242 // Create list for using with tempory table
244  Ref_item_array ref_item_array,
245  mem_root_deque<Item *> *res_fields,
246  size_t added_non_hidden_fields);
247 // Create list for using with tempory table
249  THD *thd, Query_block *select,
250  Ref_item_array ref_item_array,
251  mem_root_deque<Item *> *res_fields,
252  size_t added_non_hidden_fields);
253 bool prepare_sum_aggregators(Item_sum **func_ptr, bool need_distinct);
254 bool setup_sum_funcs(THD *thd, Item_sum **func_ptr);
255 bool make_group_fields(JOIN *main_join, JOIN *curr_join);
256 bool check_unique_constraint(TABLE *table);
257 ulonglong unique_hash(const Field *field, ulonglong *hash);
259 class QEP_TAB : public QEP_shared_owner {
260  public:
262  : QEP_shared_owner(),
269  rematerialize(false),
270  not_used_in_distinct(false),
272  having(nullptr),
274  filesort(nullptr),
278  m_keyread_optim(false),
279  m_reversed_access(false),
282  /// Initializes the object from a JOIN_TAB
283  void init(JOIN_TAB *jt);
284  // Cleans up.
285  void cleanup();
287  // Getters and setters
293  bool keyread_optim() const { return m_keyread_optim; }
295  if (table()) m_keyread_optim = table()->key_read;
296  }
297  bool reversed_access() const { return m_reversed_access; }
298  void set_reversed_access(bool arg) { m_reversed_access = arg; }
300  void set_table(TABLE *t) {
301  m_qs->set_table(t);
302  if (t) t->reginfo.qep_tab = this;
303  }
305  /// @returns semijoin strategy for this table.
306  uint get_sj_strategy() const;
308  /// Return true if join_tab should perform a FirstMatch action
309  bool do_firstmatch() const { return firstmatch_return != NO_PLAN_IDX; }
311  /// Return true if join_tab should perform a LooseScan action
312  bool do_loosescan() const { return loosescan_key_len; }
314  /// Return true if join_tab starts a Duplicate Weedout action
315  bool starts_weedout() const { return flush_weedout_table; }
317  /// Return true if join_tab finishes a Duplicate Weedout action
318  bool finishes_weedout() const { return check_weed_out_table; }
320  /**
321  A helper function that allocates appropriate join cache object and
322  sets next_query_block function of previous tab.
323  */
324  void init_join_cache(JOIN_TAB *join_tab);
326  /**
327  @returns query block id for an inner table of materialized semi-join, and
328  0 for all other tables.
329  @note implementation is not efficient (loops over all tables) - use this
330  function only in EXPLAIN.
331  */
332  uint sjm_query_block_id() const;
334  /// @returns whether this is doing QS_DYNAMIC_RANGE
335  bool dynamic_range() const {
336  if (!position()) return false; // tmp table
337  return using_dynamic_range;
338  }
340  bool use_order() const; ///< Use ordering provided by chosen index?
342  /**
343  Used to begin a new execution of a subquery. Necessary if this subquery
344  has done a filesort which which has cleared condition/quick.
345  */
349  }
351  /**
352  Construct an access path for reading from this table in the query,
353  using the access method that has been determined previously
354  (e.g., table scan, ref access, optional sort afterwards, etc.).
355  */
357  void push_index_cond(const JOIN_TAB *join_tab, uint keyno,
358  Opt_trace_object *trace_obj);
360  /// @return the index used for a table in a QEP
361  uint effective_index() const;
363  bool pfs_batch_update(const JOIN *join) const;
365  public:
366  /// Pointer to table reference
369  /* Variables for semi-join duplicate elimination */
373  /*
374  If set, means we should stop join enumeration after we've got the first
375  match and return to the specified join tab. May be PRE_FIRST_PLAN_IDX
376  which means stopping join execution after the first match.
377  */
380  /*
381  Length of key tuple (depends on #keyparts used) to use for loose scan.
382  If zero, means that loosescan is not used.
383  */
386  /*
387  If doing a LooseScan, this QEP is the first (i.e. "driving")
388  QEP_TAB, and match_tab points to the last QEP_TAB handled by the strategy.
389  match_tab->found_match should be checked to see if the current value group
390  had a match.
391  */
394  /// Dependent table functions have to be materialized on each new scan
397  enum Setup_func {
402  };
404  bool using_dynamic_range = false;
406  /** true <=> remove duplicates on this table. */
409  // If we have a query of the type SELECT DISTINCT t1.* FROM t1 JOIN t2
410  // ON ..., (ie., we join in one or more tables that we don't actually
411  // read any columns from), we can stop scanning t2 as soon as we see the
412  // first row. This pattern seems to be a workaround for lack of semijoins
413  // in older versions of MySQL.
416  /// Index condition for BKA access join
419  /** HAVING condition for checking prior saving a record into tmp table*/
422  // Operation between the previous QEP_TAB and this one.
424  // Regular nested loop.
427  // Aggregate (GROUP BY).
430  // Various temporary table operations, used at the end of the join.
436  // Block-nested loop (rewritten to hash join).
439  // Batch key access.
440  OT_BKA
443  /* Tmp table info */
446  /* Sorting related info */
449  /**
450  If we pushed a global ORDER BY down onto this first table, that ORDER BY
451  list will be preseved here.
452  */
455  /**
456  Slice number of the ref items array to switch to before reading rows from
457  this table.
458  */
461  /// @see m_quick_optim
464  /**
465  m_quick is the quick "to be used at this stage of execution".
466  It can happen that filesort uses the quick (produced by the optimizer) to
467  produce a sorted result, then the read of this result has to be done
468  without "quick", so we must reset m_quick to NULL, but we want to delay
469  freeing of m_quick or it would close the filesort's result and the table
470  prematurely.
471  In that case, we move m_quick to m_quick_optim (=> delay deletion), reset
472  m_quick to NULL (read of filesort's result will be without quick); if
473  this is a subquery which is later executed a second time,
474  QEP_TAB::reset() will restore the quick from m_quick_optim into m_quick.
475  quick_optim stands for "the quick decided by the optimizer".
476  EXPLAIN reads this member and m_condition_optim; so if you change them
477  after exposing the plan (setting plan_state), do it with the
478  LOCK_query_plan mutex.
479  */
482  /**
483  True if only index is going to be read for this table. This is the
484  optimizer's decision.
485  */
488  /**
489  True if reversed scan is used. This is the optimizer's decision.
490  */
493  /**
494  Maps of all lateral derived tables which should be refreshed when
495  execution reads a new row from this table.
496  @note that if a LDT depends on t1 and t2, and t2 is after t1 in the plan,
497  then only t2::lateral_derived_tables_depend_on_me gets the map of the
498  LDT, for efficiency (less useless calls to QEP_TAB::refresh_lateral())
499  and clarity in EXPLAIN.
500  */
505  QEP_TAB(const QEP_TAB &); // not defined
506  QEP_TAB &operator=(const QEP_TAB &); // not defined
507 };
509 /**
510  @returns a pointer to the QEP_TAB whose index is qtab->member. For
511  example, QEP_AT(x,first_inner) is the first_inner table of x.
512 */
513 #define QEP_AT(qtab, member) (qtab->join()->qep_tab[qtab->member])
515 /**
516  Use this class when you need a QEP_TAB not connected to any JOIN_TAB.
517 */
519  public:
522  /// @returns access to the QEP_TAB
523  QEP_TAB &as_QEP_TAB() { return m_qt; }
525  private:
528 };
530 bool set_record_buffer(TABLE *table, double expected_rows_to_fetch);
531 void init_tmptable_sum_functions(Item_sum **func_ptr);
532 void update_tmptable_sum_func(Item_sum **func_ptr, TABLE *tmp_table);
533 bool has_rollup_result(Item *item);
534 bool is_rollup_group_wrapper(Item *item);
535 bool is_rollup_sum_wrapper(Item *item);
538 /*
539  If a condition cannot be applied right away, for instance because it is a
540  WHERE condition and we're on the right side of an outer join, we have to
541  return it up so that it can be applied on a higher recursion level.
542  This structure represents such a condition.
543  */
546  int table_index_to_attach_to; // -1 means “on the last possible outer join”.
547 };
551  const std::vector<Item *> &conditions, THD *thd);
553 void SplitConditions(Item *condition, QEP_TAB *current_table,
554  std::vector<Item *> *predicates_below_join,
555  std::vector<PendingCondition> *predicates_above_join,
556  std::vector<PendingCondition> *join_conditions);
559  const bool new_partition_or_eof,
560  bool *output_row_ready);
562  bool *new_partition);
563 bool bring_back_frame_row(THD *thd, Window *w, Temp_table_param *out_param,
565  int fno = 0);
568  AccessPath *table_path);
570  THD *thd, TABLE_LIST *table_ref, TABLE *table, bool rematerialize,
571  Mem_root_array<const AccessPath *> *invalidators, bool need_rowid,
572  AccessPath *table_path);
574 void ConvertItemsToCopy(const mem_root_deque<Item *> &items, Field **fields,
575  Temp_table_param *param);
576 std::string RefToString(const TABLE_REF &ref, const KEY *key,
577  bool include_nulls);
581 /**
582  Split AND conditions into their constituent parts, recursively.
583  Conditions that are not AND conditions are appended unchanged onto
584  condition_parts. E.g. if you have ((a AND b) AND c), condition_parts
585  will contain [a, b, c], plus whatever it contained before the call.
586  */
587 void ExtractConditions(Item *condition,
588  Mem_root_array<Item *> *condition_parts);
590 #endif /* SQL_EXECUTOR_INCLUDED */
An iterator that helps invalidating caches.
Definition: composite_iterators.h:382
This is used for segregating rows in groups (e.g.
Definition: item.h:6014
Definition: field.h:2345
Definition: field.h:568
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:453
Class Item_sum is the base class used for special expressions that SQL calls 'set functions'.
Definition: item_sum.h:398
Definition: item.h:776
Query optimization plan node.
Definition: sql_select.h:581
Definition: sql_optimizer.h:125
Definition: key.h:112
Definition: sql_list.h:431
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:418
The iterator actually doing the reads from the inner table during BKA.
Definition: bka_iterator.h:265
A JSON object (unordered set of key/value pairs).
Definition: opt_trace.h:801
Use this class when you need a QEP_TAB not connected to any JOIN_TAB.
Definition: sql_executor.h:518
Definition: sql_executor.h:521
QEP_TAB m_qt
Definition: sql_executor.h:527
Definition: sql_executor.h:520
Definition: sql_executor.h:523
QEP_shared m_qs
Definition: sql_executor.h:526
Definition: sql_executor.h:259
uint loosescan_key_len
Definition: sql_executor.h:384
bool dynamic_range() const
Definition: sql_executor.h:335
Item * condition_optim() const
Definition: sql_executor.h:289
Setup_func materialize_table
Definition: sql_executor.h:403
void set_reversed_access(bool arg)
Definition: sql_executor.h:298
Item * m_condition_optim
Definition: sql_executor.h:462
bool rematerialize
Dependent table functions have to be materialized on each new scan.
Definition: sql_executor.h:395
bool keyread_optim() const
Definition: sql_executor.h:293
TABLE_LIST * table_ref
Pointer to table reference.
Definition: sql_executor.h:367
void set_quick_optim()
Definition: sql_executor.h:291
Filesort * filesort
Definition: sql_executor.h:447
bool reversed_access() const
Definition: sql_executor.h:297
void set_table(TABLE *t)
Definition: sql_executor.h:300
uint ref_item_slice
Slice number of the ref items array to switch to before reading rows from this table.
Definition: sql_executor.h:459
bool m_reversed_access
True if reversed scan is used.
Definition: sql_executor.h:491
bool needs_duplicate_removal
true <=> remove duplicates on this table.
Definition: sql_executor.h:407
plan_idx firstmatch_return
Definition: sql_executor.h:378
enum QEP_TAB::enum_op_type op_type
QUICK_SELECT_I * quick_optim() const
Definition: sql_executor.h:290
bool do_firstmatch() const
Return true if join_tab should perform a FirstMatch action.
Definition: sql_executor.h:309
ORDER * filesort_pushed_order
If we pushed a global ORDER BY down onto this first table, that ORDER BY list will be preseved here.
Definition: sql_executor.h:453
Definition: sql_executor.h:397
Definition: sql_executor.h:398
Definition: sql_executor.h:399
Definition: sql_executor.h:401
Definition: sql_executor.h:400
QUICK_SELECT_I * m_quick_optim
m_quick is the quick "to be used at this stage of execution".
Definition: sql_executor.h:480
Definition: sql_executor.h:261
bool not_used_in_distinct
Definition: sql_executor.h:414
bool starts_weedout() const
Return true if join_tab starts a Duplicate Weedout action.
Definition: sql_executor.h:315
bool m_keyread_optim
True if only index is going to be read for this table.
Definition: sql_executor.h:486
bool using_dynamic_range
Definition: sql_executor.h:404
bool finishes_weedout() const
Return true if join_tab finishes a Duplicate Weedout action.
Definition: sql_executor.h:318
table_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:501
bool do_loosescan() const
Return true if join_tab should perform a LooseScan action.
Definition: sql_executor.h:312
Item * having
HAVING condition for checking prior saving a record into tmp table.
Definition: sql_executor.h:420
SJ_TMP_TABLE * flush_weedout_table
Definition: sql_executor.h:370
void restore_quick_optim_and_condition()
Used to begin a new execution of a subquery.
Definition: sql_executor.h:346
Temp_table_param * tmp_table_param
Definition: sql_executor.h:444
void set_condition_optim()
Definition: sql_executor.h:292
plan_idx match_tab
Definition: sql_executor.h:392
SJ_TMP_TABLE * check_weed_out_table
Definition: sql_executor.h:371
Definition: sql_executor.h:423
Definition: sql_executor.h:431
Definition: sql_executor.h:440
Definition: sql_executor.h:433
Definition: sql_executor.h:428
Definition: sql_executor.h:437
Definition: sql_executor.h:432
Definition: sql_executor.h:434
Definition: sql_executor.h:425
Item * cache_idx_cond
Index condition for BKA access join.
Definition: sql_executor.h:417
Mem_root_array< const AccessPath * > * invalidators
Definition: sql_executor.h:503
QEP_TAB & operator=(const QEP_TAB &)
QEP_TAB(const QEP_TAB &)
void set_keyread_optim()
Definition: sql_executor.h:294
Owner of a QEP_shared; parent of JOIN_TAB and QEP_TAB.
Definition: sql_opt_exec_shared.h:471
Item * condition() const
Definition: sql_opt_exec_shared.h:516
QEP_shared * m_qs
Definition: sql_opt_exec_shared.h:564
void set_condition(Item *to)
Definition: sql_opt_exec_shared.h:517
void set_quick(QUICK_SELECT_I *q)
Definition: sql_opt_exec_shared.h:528
JOIN * join() const
Definition: sql_opt_exec_shared.h:484
QUICK_SELECT_I * quick() const
Definition: sql_opt_exec_shared.h:527
void set_qs(QEP_shared *q)
Definition: sql_opt_exec_shared.h:477
POSITION * position() const
Definition: sql_opt_exec_shared.h:495
TABLE * table() const
Definition: sql_opt_exec_shared.h:494
Holds members common to JOIN_TAB and QEP_TAB.
Definition: sql_opt_exec_shared.h:229
void set_table(TABLE *t)
Definition: sql_opt_exec_shared.h:271
Definition: opt_range.h:230
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1101
Definition: sql_executor.h:102
uint rowid_len
Definition: sql_executor.h:126
TABLE * tmp_table
Definition: sql_executor.h:129
Definition: sql_executor.h:105
Definition: sql_executor.h:132
uint null_bits
Definition: sql_executor.h:124
SJ_TMP_TABLE_TAB * tabs_end
Definition: sql_executor.h:106
bool have_confluent_row
Definition: sql_executor.h:121
Definition: sql_executor.h:104
uint null_bytes
Definition: sql_executor.h:125
bool is_confluent
Definition: sql_executor.h:115
Field_longlong * hash_field
Definition: sql_executor.h:134
Executor structure for the materialized semi-join info, which contains.
Definition: sql_executor.h:142
const bool is_scan
true if executing a scan, false if lookup
Definition: sql_executor.h:155
TABLE * table
Reference to temporary table.
Definition: sql_executor.h:160
Definition: sql_executor.h:153
const uint inner_table_index
Index in join_tab for first inner table.
Definition: sql_executor.h:158
const uint mat_table_index
Index in join_tab for materialized table.
Definition: sql_executor.h:157
Temp_table_param table_param
The temptable and its related info.
Definition: sql_executor.h:159
TABLE_LIST *const sj_nest
Semi-join nest for this materialization.
Definition: sql_executor.h:154
Semijoin_mat_exec(TABLE_LIST *sj_nest, bool is_scan, uint table_count, uint mat_table_index, uint inner_table_index)
Definition: sql_executor.h:144
const uint table_count
Number of tables in the sj-nest.
Definition: sql_executor.h:156
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:813
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:73
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:94
Dialog Client Authentication nullptr
char * pos
void init_tmptable_sum_functions(Item_sum **func_ptr)
bool pfs_batch_update(const JOIN *join) const
bool is_rollup_group_wrapper(Item *item)
bool setup_sum_funcs(THD *thd, Item_sum **func_ptr)
Call setup() for all sum functions.
AccessPath * GetAccessPathForDerivedTable(THD *thd, QEP_TAB *qep_tab, AccessPath *table_path)
bool copy_funcs(Temp_table_param *, const THD *thd, Copy_func_type type=CFT_ALL)
Copy result of functions to record in tmp_table.
void ExtractConditions(Item *condition, Mem_root_array< Item * > *condition_parts)
Split AND conditions into their constituent parts, recursively.
bool has_rollup_result(Item *item)
Checks if an item has a ROLLUP NULL which needs to be written to temp table.
std::string RefToString(const TABLE_REF &ref, const KEY *key, bool include_nulls)
int join_read_const_table(JOIN_TAB *tab, POSITION *pos)
Reads content of constant table.
ulonglong unique_hash(const Field *field, ulonglong *hash)
Generate hash for a field.
int do_sj_dups_weedout(THD *thd, SJ_TMP_TABLE *sjtbl)
SemiJoinDuplicateElimination: Weed out duplicate row combinations.
int report_handler_error(TABLE *table, int error)
Help function when we get some an error from the table handler.
void setup_tmptable_write_func(QEP_TAB *tab, Opt_trace_object *trace)
Setup write_func of QEP_tmp_table object.
int update_item_cache_if_changed(List< Cached_item > &list)
Item * unwrap_rollup_group(Item *item)
int safe_index_read(QEP_TAB *tab)
AccessPath * access_path()
Construct an access path for reading from this table in the query, using the access method that has b...
bool use_order() const
Use ordering provided by chosen index?
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.
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.
bool check_unique_constraint(TABLE *table)
Check unique_constraint.
bool copy_fields_and_funcs(Temp_table_param *param, const THD *thd, Copy_func_type type=CFT_ALL)
bool make_group_fields(JOIN *main_join, JOIN *curr_join)
allocate group fields or take prepared (cached).
void update_tmptable_sum_func(Item_sum **func_ptr, TABLE *tmp_table)
Update record 0 in tmp_table from record 1.
bool process_buffered_windowing_record(THD *thd, Temp_table_param *param, const bool new_partition_or_eof, bool *output_row_ready)
While there are more unprocessed rows ready to process given the current partition/frame state,...
bool is_rollup_sum_wrapper(Item *item)
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.
bool construct_lookup_ref(THD *thd, TABLE *table, TABLE_REF *ref)
Copy the lookup key into the table ref's key buffer.
bool copy_fields(Temp_table_param *param, const THD *thd, bool reverse_copy=false)
Make a copy of all simple SELECT'ed fields.
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...
bool bring_back_frame_row(THD *thd, Window *w, Temp_table_param *out_param, int64 rowno, Window_retrieve_cached_row_reason reason, int fno=0)
Bring back buffered data to the record of qep_tab-1 [1], and optionally execute copy_fields() to the ...
bool prepare_sum_aggregators(Item_sum **func_ptr, bool need_distinct)
bool buffer_windowing_record(THD *thd, Temp_table_param *param, bool *new_partition)
If we cannot evaluate all window functions for a window on the fly, buffer the current row for later ...
void init(JOIN_TAB *jt)
Initializes the object from a JOIN_TAB.
void init_join_cache(JOIN_TAB *join_tab)
A helper function that allocates appropriate join cache object and sets next_query_block function of ...
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.
void cleanup()
uint sjm_query_block_id() const
uint effective_index() const
Return the index used for a table in a QEP.
uint get_sj_strategy() const
static uchar key[100]
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:469
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
unsigned char uchar
Definition: my_inttypes.h:51
int64_t int64
Definition: my_inttypes.h:67
uint64_t table_map
Definition: my_table_map.h:29
Log error(cerr, "ERROR")
PT & ref(PT *tp)
unique_ptr_destroy_only< RowIterator > PossiblyAttachFilterIterator(unique_ptr_destroy_only< RowIterator > iterator, const std::vector< Item * > &conditions, THD *thd)
bool MaterializeIsDoingDeduplication(TABLE *table)
Definition: sql_executor.h:169
In first windowing step, copies non-window functions which do not rely on window functions,...
Definition: sql_executor.h:200
In windowing step, copies non framing window function, e.g.
Definition: sql_executor.h:184
In windowing step, copies window functions that need frame cardinality, that is we need to read all r...
Definition: sql_executor.h:190
In windowing step, copies framing window function, including all grouping aggregates,...
Definition: sql_executor.h:178
In non-windowing step, copies functions.
Definition: sql_executor.h:173
In final windowing step, copies all non-wf functions.
Definition: sql_executor.h:206
In windowing step, copies framing window functions that read only one row per frame.
Definition: sql_executor.h:195
Copies all window functions.
Definition: sql_executor.h:210
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)
Common types of the Optimizer, used by optimization and execution.
The slice with pointers to columns of table(s), ie., the actual Items.
Definition: sql_opt_exec_shared.h:628
#define NO_PLAN_IDX
undefined index
Definition: sql_opt_exec_shared.h:55
int8 plan_idx
This represents the index of a JOIN_TAB/QEP_TAB in an array.
Definition: sql_opt_exec_shared.h:40
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:156
Definition: table.h:277
A position of table within a join order.
Definition: sql_select.h:345
Definition: sql_executor.h:544
Item * cond
Definition: sql_executor.h:545
int table_index_to_attach_to
Definition: sql_executor.h:546
Definition: sql_executor.h:78
QEP_TAB * qep_tab
Definition: sql_executor.h:79
ushort null_byte
Definition: sql_executor.h:81
uchar null_bit
Definition: sql_executor.h:82
uint rowid_offset
Definition: sql_executor.h:80
Definition: table.h:2612
Definition: sql_opt_exec_shared.h:59
Definition: table.h:1389
class QEP_TAB * qep_tab
Definition: table.h:1733
bool key_read
If set, the optimizer has found that row retrieval should access index tree only.
Definition: table.h:1656
struct TABLE::@155 reginfo
unsigned int uint
Position hints for the frame buffer are saved for these kind of row accesses, cf.
Definition: window.h:64