MySQL  8.0.20
Source Code Documentation
Go to the documentation of this file.
4 /* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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 <string.h>
32 #include <sys/types.h>
33 #include <memory>
34 #include <vector>
36 #include "my_alloc.h"
37 #include "my_base.h"
38 #include "my_compiler.h"
39 #include "my_inttypes.h"
40 #include "my_table_map.h"
41 #include "sql/row_iterator.h"
42 #include "sql/sql_lex.h"
43 #include "sql/sql_opt_exec_shared.h" // QEP_shared_owner
44 #include "sql/table.h"
45 #include "sql/temp_table_param.h" // Temp_table_param
48 class Cached_item;
49 class Field;
50 class Field_longlong;
51 class Filesort;
52 class FollowTailIterator;
53 class Item;
54 class Item_sum;
55 class JOIN;
56 class JOIN_TAB;
58 class Opt_trace_object;
59 class QEP_TAB;
60 class QUICK_SELECT_I;
61 class THD;
62 class Window;
64 struct CACHE_FIELD;
65 struct POSITION;
66 template <class T>
67 class List;
68 template <typename Element_type>
69 class Mem_root_array;
71 /*
72  Array of pointers to tables whose rowids compose the temporary table
73  record.
74 */
78  ushort null_byte;
80 };
82 /*
83  Temporary table used by semi-join DuplicateElimination strategy
85  This consists of the temptable itself and data needed to put records
86  into it. The table's DDL is as follows:
88  CREATE TABLE tmptable (col VARCHAR(n) BINARY, PRIMARY KEY(col));
90  where the primary key can be replaced with unique constraint if n exceeds
91  the limit (as it is always done for query execution-time temptables).
93  The record value is a concatenation of rowids of tables from the join we're
94  executing. If a join table is on the inner side of the outer join, we
95  assume that its rowid can be NULL and provide means to store this rowid in
96  the tuple.
97 */
99 class SJ_TMP_TABLE {
100  public:
101  SJ_TMP_TABLE() : hash_field(nullptr) {}
105  /*
106  is_confluent==true means this is a special case where the temptable record
107  has zero length (and presence of a unique key means that the temptable can
108  have either 0 or 1 records).
109  In this case we don't create the physical temptable but instead record
110  its state in SJ_TMP_TABLE::have_confluent_record.
111  */
114  /*
115  When is_confluent==true: the contents of the table (whether it has the
116  record or not).
117  */
120  /* table record parameters */
125  /* The temporary table itself (NULL means not created yet) */
128  /* Pointer to next table (next->start_idx > this->end_idx) */
130  /* Calc hash instead of too long key */
132 };
134 /**
135  Executor structure for the materialized semi-join info, which contains
136  - Description of expressions selected from subquery
137  - The sj-materialization temporary table
138 */
140  public:
141  Semijoin_mat_exec(TABLE_LIST *sj_nest, bool is_scan, uint table_count,
142  uint mat_table_index, uint inner_table_index)
143  : sj_nest(sj_nest),
144  is_scan(is_scan),
145  table_count(table_count),
146  mat_table_index(mat_table_index),
147  inner_table_index(inner_table_index),
148  table_param(),
149  table(nullptr) {}
151  TABLE_LIST *const sj_nest; ///< Semi-join nest for this materialization
152  const bool is_scan; ///< true if executing a scan, false if lookup
153  const uint table_count; ///< Number of tables in the sj-nest
154  const uint mat_table_index; ///< Index in join_tab for materialized table
155  const uint inner_table_index; ///< Index in join_tab for first inner table
156  Temp_table_param table_param; ///< The temptable and its related info
157  TABLE *table; ///< Reference to temporary table
158 };
162 MY_ATTRIBUTE((warn_unused_result))
163 bool copy_fields(Temp_table_param *param, const THD *thd,
164  bool reverse_copy = false);
167  /**
168  In non-windowing step, copies functions
169  */
171  /**
172  In windowing step, copies framing window function, including
173  all grouping aggregates, e.g. SUM, AVG and FIRST_VALUE, LAST_VALUE.
174  */
176  /**
177  In windowing step, copies non framing window function, e.g.
178  ROW_NUMBER, RANK, DENSE_RANK, except those that are two_pass cf.
179  copy_two_pass_window_functions which are treated separately.
180  */
182  /**
183  In windowing step, copies window functions that need frame cardinality,
184  that is we need to read all rows of a partition before we can compute the
185  wf's value for the the first row in the partition.
186  */
188  /**
189  In windowing step, copies framing window functions that read only one row
190  per frame.
191  */
193  /**
194  In first windowing step, copies non-window functions which do not rely on
195  window functions, i.e. those that have Item::has_wf() == false.
196  */
198  /**
199  In final windowing step, copies all non-wf functions. Must be called after
200  all wfs have been evaluated, as non-wf functions may reference wf,
201  e.g. 1+RANK.
202  */
204  /**
205  Copies all window functions.
206  */
208  /**
209  Copies all items that are expressions containing aggregates, but are not
210  themselves aggregates. Such expressions are typically split into their
211  constituent parts during setup_fields(), such that the parts that are
212  _not_ aggregates are replaced by Item_refs that point into a slice.
213  See AggregateIterator::Read() for more details.
214  */
216 };
218 bool copy_funcs(Temp_table_param *, const THD *thd,
221 // Combines copy_fields() and copy_funcs().
222 bool copy_fields_and_funcs(Temp_table_param *param, const THD *thd,
225 /**
226  Copy the lookup key into the table ref's key buffer.
228  @param thd pointer to the THD object
229  @param table the table to read
230  @param ref information about the index lookup key
232  @retval false ref key copied successfully
233  @retval true error dectected during copying of key
234 */
235 bool construct_lookup_ref(THD *thd, TABLE *table, TABLE_REF *ref);
237 /** Help function when we get some an error from the table handler. */
238 int report_handler_error(TABLE *table, int error);
240 int safe_index_read(QEP_TAB *tab);
244 int do_sj_dups_weedout(THD *thd, SJ_TMP_TABLE *sjtbl);
247 // Create list for using with tempory table
248 bool change_to_use_tmp_fields(List<Item> &all_fields,
249  size_t num_select_elements, THD *thd,
250  Ref_item_array ref_item_array,
251  List<Item> *res_selected_fields,
252  List<Item> *res_all_fields);
253 // Create list for using with tempory table
254 bool change_refs_to_tmp_fields(List<Item> &all_fields,
255  size_t num_select_elements, THD *thd,
256  Ref_item_array ref_item_array,
257  List<Item> *res_selected_fields,
258  List<Item> *res_all_fields);
259 bool prepare_sum_aggregators(Item_sum **func_ptr, bool need_distinct);
260 bool setup_sum_funcs(THD *thd, Item_sum **func_ptr);
261 bool make_group_fields(JOIN *main_join, JOIN *curr_join);
262 bool setup_copy_fields(List<Item> &all_fields, size_t num_select_elements,
263  THD *thd, Temp_table_param *param,
264  Ref_item_array ref_item_array,
265  List<Item> *res_selected_fields,
266  List<Item> *res_all_fields);
267 bool check_unique_constraint(TABLE *table);
268 ulonglong unique_hash(const Field *field, ulonglong *hash);
270 class QEP_TAB : public QEP_shared_owner {
271  public:
273  : QEP_shared_owner(),
274  table_ref(nullptr),
275  flush_weedout_table(nullptr),
276  check_weed_out_table(nullptr),
277  firstmatch_return(NO_PLAN_IDX),
278  loosescan_key_len(0),
279  match_tab(NO_PLAN_IDX),
280  first_unmatched(NO_PLAN_IDX),
281  rematerialize(false),
282  used_null_fields(false),
283  used_uneven_bit_fields(false),
284  copy_current_rowid(nullptr),
285  not_used_in_distinct(false),
286  cache_idx_cond(nullptr),
287  having(nullptr),
288  tmp_table_param(nullptr),
289  filesort(nullptr),
290  ref_item_slice(REF_SLICE_SAVED_BASE),
291  m_condition_optim(nullptr),
292  m_quick_optim(nullptr),
293  m_keyread_optim(false),
294  m_reversed_access(false),
295  lateral_derived_tables_depend_on_me(0) {}
297  /// Initializes the object from a JOIN_TAB
298  void init(JOIN_TAB *jt);
299  // Cleans up.
300  void cleanup();
302  // Getters and setters
304  Item *condition_optim() const { return m_condition_optim; }
305  QUICK_SELECT_I *quick_optim() const { return m_quick_optim; }
306  void set_quick_optim() { m_quick_optim = quick(); }
307  void set_condition_optim() { m_condition_optim = condition(); }
308  bool keyread_optim() const { return m_keyread_optim; }
310  if (table()) m_keyread_optim = table()->key_read;
311  }
312  bool reversed_access() const { return m_reversed_access; }
313  void set_reversed_access(bool arg) { m_reversed_access = arg; }
315  void set_table(TABLE *t) {
316  m_qs->set_table(t);
317  if (t) t->reginfo.qep_tab = this;
318  }
321  return m_temporary_table_deduplicates;
322  }
324  m_temporary_table_deduplicates = arg;
325  }
327  bool using_table_scan() const { return m_using_table_scan; }
328  void set_using_table_scan(bool arg) { m_using_table_scan = arg; }
330  /// @returns semijoin strategy for this table.
331  uint get_sj_strategy() const;
333  /// Return true if join_tab should perform a FirstMatch action
334  bool do_firstmatch() const { return firstmatch_return != NO_PLAN_IDX; }
336  /// Return true if join_tab should perform a LooseScan action
337  bool do_loosescan() const { return loosescan_key_len; }
339  /// Return true if join_tab starts a Duplicate Weedout action
340  bool starts_weedout() const { return flush_weedout_table; }
342  /// Return true if join_tab finishes a Duplicate Weedout action
343  bool finishes_weedout() const { return check_weed_out_table; }
345  /**
346  A helper function that allocates appropriate join cache object and
347  sets next_select function of previous tab.
348  */
349  void init_join_cache(JOIN_TAB *join_tab);
351  /**
352  @returns query block id for an inner table of materialized semi-join, and
353  0 for all other tables.
354  @note implementation is not efficient (loops over all tables) - use this
355  function only in EXPLAIN.
356  */
357  uint sjm_query_block_id() const;
359  /// @returns whether this is doing QS_DYNAMIC_RANGE
360  bool dynamic_range() const {
361  if (!position()) return false; // tmp table
362  return using_dynamic_range;
363  }
365  bool use_order() const; ///< Use ordering provided by chosen index?
367  /**
368  Used to begin a new execution of a subquery. Necessary if this subquery
369  has done a filesort which which has cleared condition/quick.
370  */
372  if (m_condition_optim) set_condition(m_condition_optim);
373  if (m_quick_optim) set_quick(m_quick_optim);
374  }
376  void pick_table_access_method();
377  void push_index_cond(const JOIN_TAB *join_tab, uint keyno,
378  Opt_trace_object *trace_obj);
380  /// @return the index used for a table in a QEP
381  uint effective_index() const;
383  bool pfs_batch_update(const JOIN *join) const;
385  public:
386  /// Pointer to table reference
389  /* Variables for semi-join duplicate elimination */
393  /*
394  If set, means we should stop join enumeration after we've got the first
395  match and return to the specified join tab. May be PRE_FIRST_PLAN_IDX
396  which means stopping join execution after the first match.
397  */
400  /*
401  Length of key tuple (depends on #keyparts used) to use for loose scan.
402  If zero, means that loosescan is not used.
403  */
406  /*
407  If doing a LooseScan, this QEP is the first (i.e. "driving")
408  QEP_TAB, and match_tab points to the last QEP_TAB handled by the strategy.
409  match_tab->found_match should be checked to see if the current value group
410  had a match.
411  */
414  plan_idx first_unmatched; /**< used for optimization purposes only */
416  /// Dependent table functions have to be materialized on each new scan
419  enum Setup_func {
424  };
425  Setup_func materialize_table = NO_SETUP;
426  bool using_dynamic_range = false;
429  // join-cache-related members
433  // Whether the row ID is needed for this table, and where the row ID can be
434  // found.
435  //
436  // If rowid_status != NO_ROWID_NEEDED, it indicates that this table is part of
437  // weedout. In order for weedout to eliminate duplicate rows, it needs a
438  // unique ID for each row it reads. In general, any operator that needs the
439  // row ID should ask the storage engine directly for the ID of the last row
440  // read by calling handler::position(). However, it is not that simple...
441  //
442  // As mentioned, position() will ask the storage engine to provide the row ID
443  // of the last row read. But some iterators (i.e. HashJoinIterator) buffer
444  // rows, so that the last row returned by i.e. HashJoinIterator is not
445  // necessarily the same as the last row returned by the storage engine.
446  // This means that any iterator that buffers rows without using a temporary
447  // table must store and restore the row ID itself. If a temporary table is
448  // used, the temporary table engine will provide the row ID.
449  //
450  // When creating the iterator tree, any iterator that needs to interact with
451  // row IDs must adhere to the following rules:
452  //
453  // 1. Any iterator that buffers rows without using a temporary table must
454  // store and restore the row ID if rowid_status != NO_ROWID_NEEDED.
455  // In addition, they must mark that they do so by changing the value of
456  // rowid_status to ROWID_PROVIDED_BY_ITERATOR_READ_CALL in their
457  // constructor.
458  // 2. Any iterator that needs the row ID (currently only WeedoutIterator)
459  // must check rowid_status to see if they should call position() or trust
460  // that a row ID is provided by another iterator. Note that when filesort
461  // sorts by row ID, it handles everything regarding row ID itself.
462  // It manages this because sorting by row ID always goes through a
463  // temporary table, which in turn will provide the row ID to filesort.
464  // 3. As the value of rowid_status may change while building the iterator
465  // tree, all iterators interacting with row IDs must cache the
466  // value they see in their constructor.
467  //
468  // Consider the following example:
469  //
470  // Weedout (t1,t3)
471  // |
472  // Nested loop
473  // / |
474  // Hash join t3
475  // / |
476  // t1 t2
477  //
478  // During query planning, rowid_status will be set to
479  // NEED_TO_CALL_POSITION_FOR_ROWID on t1 and t3 due to the planned weedout.
480  // When the iterator tree is constructed, the hash join constructor will be
481  // called first. It caches the value of rowid_status for t1 per rule 3 above,
482  // and changes the value to ROWID_PROVIDED_BY_ITERATOR_READ_CALL per rule 1.
483  // This notifies any iterator above itself that they should not call
484  // position(). When the nested loop constructor is called, nothing happens, as
485  // the iterator does not interact with row IDs in any way. When the weedout
486  // constructor is called, it caches the value of rowid_status for t1 and t3
487  // per rule 3. During execution, the weedout will call position() on t3,
488  // since rowid_status was NEED_TO_CALL_POSITION_FOR_ROWID when the iterator
489  // was constructed. It will not call position() on t1, as rowid_status was set
490  // to ROWID_PROVIDED_BY_ITERATOR_READ_CALL by the hash join iterator.
491  //
492  // Note that if you have a NULL-complemented row, there is no guarantee that
493  // position() will provide a valid row ID, or not even a valid row ID pointer.
494  // So all operations must check for NULL-complemented rows before trying to
495  // use/copy a row ID.
498  // Helper structure for copying the row ID. Only used by BNL and BKA in the
499  // non-iterator executor.
500  CACHE_FIELD *copy_current_rowid;
502  /** true <=> remove duplicates on this table. */
503  bool needs_duplicate_removal = false;
505  // If we have a query of the type SELECT DISTINCT t1.* FROM t1 JOIN t2
506  // ON ..., (ie., we join in one or more tables that we don't actually
507  // read any columns from), we can stop scanning t2 as soon as we see the
508  // first row. This pattern seems to be a workaround for lack of semijoins
509  // in older versions of MySQL.
512  /// Index condition for BKA access join
515  /** HAVING condition for checking prior saving a record into tmp table*/
518  // Operation between the previous QEP_TAB and this one.
520  // Regular nested loop.
523  // Aggregate (GROUP BY).
526  // Various temporary table operations, used at the end of the join.
532  // Block-nested loop (rewritten to hash join).
535  // Batch key access.
536  OT_BKA
537  } op_type = OT_NONE;
539  /* Tmp table info */
542  /* Sorting related info */
545  /**
546  If we pushed a global ORDER BY down onto this first table, that ORDER BY
547  list will be preseved here.
548  */
549  ORDER *filesort_pushed_order = nullptr;
551  /**
552  Slice number of the ref items array to switch to before reading rows from
553  this table.
554  */
557  /// @see m_quick_optim
560  /**
561  m_quick is the quick "to be used at this stage of execution".
562  It can happen that filesort uses the quick (produced by the optimizer) to
563  produce a sorted result, then the read of this result has to be done
564  without "quick", so we must reset m_quick to NULL, but we want to delay
565  freeing of m_quick or it would close the filesort's result and the table
566  prematurely.
567  In that case, we move m_quick to m_quick_optim (=> delay deletion), reset
568  m_quick to NULL (read of filesort's result will be without quick); if
569  this is a subquery which is later executed a second time,
570  QEP_TAB::reset() will restore the quick from m_quick_optim into m_quick.
571  quick_optim stands for "the quick decided by the optimizer".
572  EXPLAIN reads this member and m_condition_optim; so if you change them
573  after exposing the plan (setting plan_state), do it with the
574  LOCK_query_plan mutex.
575  */
578  /**
579  True if only index is going to be read for this table. This is the
580  optimizer's decision.
581  */
584  /**
585  True if reversed scan is used. This is the optimizer's decision.
586  */
589  /**
590  Maps of all lateral derived tables which should be refreshed when
591  execution reads a new row from this table.
592  @note that if a LDT depends on t1 and t2, and t2 is after t1 in the plan,
593  then only t2::lateral_derived_tables_depend_on_me gets the map of the
594  LDT, for efficiency (less useless calls to QEP_TAB::refresh_lateral())
595  and clarity in EXPLAIN.
596  */
601  /**
602  If this table is a temporary table used for whole-JOIN materialization
603  (e.g. before sorting): true iff the table deduplicates, typically by way
604  of an unique index.
606  Otherwise, unused.
607  */
608  bool m_temporary_table_deduplicates = false;
610  /**
611  True if iterator is a TableScanIterator. Used so that we can know whether
612  to stream directly across derived tables and into sorts (we cannot if there
613  is a ref access).
614  */
615  bool m_using_table_scan = false;
617  /**
618  If this table is a recursive reference(to a CTE), contains a pointer to the
619  iterator here. This is so that MaterializeIterator can get a list of all
620  such iterators, to coordinate rematerialization and other signals.
621  */
622  FollowTailIterator *recursive_iterator = nullptr;
624  /**
625  If this table is a multi-range row iterator (the inner part of BKA),
626  contains a pointer to the iterator here. This is solely for use during
627  construction of the iterator tree, so that when we set up the BKAIterator,
628  we have easy access to the MRR iterator.
629  */
630  MultiRangeRowIterator *mrr_iterator = nullptr;
632  QEP_TAB(const QEP_TAB &); // not defined
633  QEP_TAB &operator=(const QEP_TAB &); // not defined
634 };
636 /**
637  @returns a pointer to the QEP_TAB whose index is qtab->member. For
638  example, QEP_AT(x,first_inner) is the first_inner table of x.
639 */
640 #define QEP_AT(qtab, member) (qtab->join()->qep_tab[qtab->member])
642 /**
643  Use this class when you need a QEP_TAB not connected to any JOIN_TAB.
644 */
646  public:
647  QEP_TAB_standalone() { m_qt.set_qs(&m_qs); }
648  ~QEP_TAB_standalone() { m_qt.cleanup(); }
649  /// @returns access to the QEP_TAB
650  QEP_TAB &as_QEP_TAB() { return m_qt; }
652  private:
655 };
657 void copy_sum_funcs(Item_sum **func_ptr, Item_sum **end_ptr);
658 bool set_record_buffer(const QEP_TAB *tab);
659 bool init_sum_functions(Item_sum **func_ptr, Item_sum **end_ptr);
660 void init_tmptable_sum_functions(Item_sum **func_ptr);
661 bool update_sum_func(Item_sum **func_ptr);
662 void update_tmptable_sum_func(Item_sum **func_ptr, TABLE *tmp_table);
663 bool has_rollup_result(Item *item);
665 /*
666  If a condition cannot be applied right away, for instance because it is a
667  WHERE condition and we're on the right side of an outer join, we have to
668  return it up so that it can be applied on a higher recursion level.
669  This structure represents such a condition.
670  */
673  int table_index_to_attach_to; // -1 means “on the last possible outer join”.
674 };
678  const std::vector<Item *> &conditions, THD *thd);
680 void SplitConditions(Item *condition, QEP_TAB *current_table,
681  std::vector<Item *> *predicates_below_join,
682  std::vector<PendingCondition> *predicates_above_join,
683  std::vector<PendingCondition> *join_conditions);
686  const bool new_partition_or_eof,
687  bool *output_row_ready);
689  bool *new_partition);
690 bool bring_back_frame_row(THD *thd, Window *w, Temp_table_param *out_param,
692  int fno = 0);
695  THD *thd, QEP_TAB *qep_tab);
696 void ConvertItemsToCopy(List<Item> *items, Field **fields,
697  Temp_table_param *param, JOIN *join);
698 std::string RefToString(const TABLE_REF &ref, const KEY *key,
699  bool include_nulls);
701 #endif /* SQL_EXECUTOR_INCLUDED */
Definition: sql_executor.h:150
unsigned long long int ulonglong
Definition: my_inttypes.h:55
int join_read_const_table(JOIN_TAB *tab, POSITION *pos)
Reads content of constant table.
In final windowing step, copies all non-wf functions.
Definition: sql_executor.h:203
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 ...
bool copy_fields_and_funcs(Temp_table_param *param, const THD *thd, Copy_func_type type=CFT_ALL)
const uint table_count
Number of tables in the sj-nest.
Definition: sql_executor.h:153
Definition: sql_executor.h:272
unsigned char uchar
Definition: my_inttypes.h:51
Definition: sql_optimizer.h:175
Definition: sql_executor.h:421
Definition: table.h:180
bool init_sum_functions(Item_sum **func_ptr, Item_sum **end_ptr)
An iterator that helps invalidating caches.
Definition: composite_iterators.h:496
Item * cache_idx_cond
Index condition for BKA access join.
Definition: sql_executor.h:513
void copy_sum_funcs(Item_sum **func_ptr, Item_sum **end_ptr)
Copy result of sum functions to record in tmp_table.
bool used_uneven_bit_fields
Definition: sql_executor.h:431
std::string RefToString(const TABLE_REF &ref, const KEY *key, bool include_nulls)
Holds members common to JOIN_TAB and QEP_TAB.
Definition: sql_opt_exec_shared.h:226
Definition: sql_executor.h:527
void init_tmptable_sum_functions(Item_sum **func_ptr)
Order clause list element.
Definition: table.h:277
Definition: sql_executor.h:420
Definition: sql_executor.h:519
void set_table(TABLE *t)
Definition: sql_executor.h:315
TABLE_LIST *const sj_nest
Semi-join nest for this materialization.
Definition: sql_executor.h:151
QUICK_SELECT_I * m_quick_optim
m_quick is the quick "to be used at this stage of execution".
Definition: sql_executor.h:576
unique_ptr_destroy_only< RowIterator > iterator
Definition: sql_executor.h:427
bool used_null_fields
Definition: sql_executor.h:430
A JSON object (unordered set of key/value pairs).
Definition: opt_trace.h:813
In windowing step, copies framing window functions that read only one row per frame.
Definition: sql_executor.h:192
Some integer typedefs for easier portability.
A wrapper class which provides array bounds checking.
Definition: sql_array.h:41
uint null_bytes
Definition: sql_executor.h:122
QUICK_SELECT_I * quick_optim() const
Definition: sql_executor.h:305
Position hints for the frame buffer are saved for these kind of row accesses, cf. ...
Definition: window.h:64
bool using_table_scan() const
Definition: sql_executor.h:327
Temp_table_param * tmp_table_param
Definition: sql_executor.h:540
Owner of a QEP_shared; parent of JOIN_TAB and QEP_TAB.
Definition: sql_opt_exec_shared.h:468
uchar null_bit
Definition: sql_executor.h:79
bool has_rollup_result(Item *item)
Checks if an item has a ROLLUP NULL which needs to be written to temp table.
Definition: field.h:694
uint loosescan_key_len
Definition: sql_executor.h:404
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:94
int do_sj_dups_weedout(THD *thd, SJ_TMP_TABLE *sjtbl)
SemiJoinDuplicateElimination: Weed out duplicate row combinations.
plan_idx match_tab
Definition: sql_executor.h:412
Definition: sql_executor.h:419
QEP_shared m_qs
Definition: sql_executor.h:653
std::string join(Container cont, const std::string &delim)
join elements of an container into a string seperated by a delimiter.
Definition: string.h:144
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...
const uint mat_table_index
Index in join_tab for materialized table.
Definition: sql_executor.h:154
ushort null_byte
Definition: sql_executor.h:78
class udf_list * list
Definition: sql_executor.h:101
Definition: sql_executor.h:671
In non-windowing step, copies functions.
Definition: sql_executor.h:170
const bool is_scan
true if executing a scan, false if lookup
Definition: sql_executor.h:152
Definition: sql_executor.h:102
Definition: sql_executor.h:650
bool keyread_optim() const
Definition: sql_executor.h:308
Copies all items that are expressions containing aggregates, but are not themselves aggregates...
Definition: sql_executor.h:215
Definition: sql_executor.h:75
In windowing step, copies non framing window function, e.g.
Definition: sql_executor.h:181
bool construct_lookup_ref(THD *thd, TABLE *table, TABLE_REF *ref)
Copy the lookup key into the table ref&#39;s key buffer.
static bool quick
Common types of the Optimizer, used by optimization and execution.
static mysql_service_status_t init()
Component initialization.
Definition: table.h:1306
Definition: sql_executor.h:528
The iterator actually doing the reads from the inner table during BKA.
Definition: bka_iterator.h:261
Definition: sql_executor.h:521
bool dynamic_range() const
Definition: sql_executor.h:360
int8 plan_idx
This represents the index of a JOIN_TAB/QEP_TAB in an array.
Definition: sql_opt_exec_shared.h:39
Copies all window functions.
Definition: sql_executor.h:207
Item * cond
Definition: sql_executor.h:672
void set_temporary_table_deduplicates(bool arg)
Definition: sql_executor.h:323
In windowing step, copies framing window function, including all grouping aggregates, e.g.
Definition: sql_executor.h:175
This file includes constants used by all storage engines.
bool reversed_access() const
Definition: sql_executor.h:312
QEP_TAB m_qt
Definition: sql_executor.h:654
uint rowid_offset
Definition: sql_executor.h:77
Definition: table.h:179
bool temporary_table_deduplicates() const
Definition: sql_executor.h:320
bool make_group_fields(JOIN *main_join, JOIN *curr_join)
allocate group fields or take prepared (cached).
char * pos
bool copy_fields(Temp_table_param *param, const THD *thd, bool reverse_copy=false)
Make a copy of all simple SELECT&#39;ed fields.
bool setup_sum_funcs(THD *thd, Item_sum **func_ptr)
Call setup() for all sum functions.
Field_longlong * hash_field
Definition: sql_executor.h:131
unique_ptr_destroy_only< RowIterator > GetIteratorForDerivedTable(THD *thd, QEP_TAB *qep_tab)
bool setup_copy_fields(List< Item > &all_fields, size_t num_select_elements, THD *thd, Temp_table_param *param, Ref_item_array ref_item_array, List< Item > *res_selected_fields, List< Item > *res_all_fields)
Sets up caches for holding the values of non-aggregated expressions.
Definition: sql_executor.h:647
bool m_keyread_optim
True if only index is going to be read for this table.
Definition: sql_executor.h:582
bool m_reversed_access
True if reversed scan is used.
Definition: sql_executor.h:587
bool rematerialize
Dependent table functions have to be materialized on each new scan.
Definition: sql_executor.h:417
Class Item_sum is the base class used for special expressions that SQL calls &#39;set functions&#39;...
Definition: item_sum.h:390
Definition: aggregate_check.h:523
In windowing step, copies window functions that need frame cardinality, that is we need to read all r...
Definition: sql_executor.h:187
This is used for segregating rows in groups (e.g.
Definition: item.h:5673
int safe_index_read(QEP_TAB *tab)
int64_t int64
Definition: my_inttypes.h:67
Executor structure for the materialized semi-join info, which contains.
Definition: sql_executor.h:139
Definition: field.h:2441
Definition: sql_executor.h:166
Temp_table_param table_param
The temptable and its related info.
Definition: sql_executor.h:156
Definition: sql_executor.h:524
Header for compiler-dependent features.
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 SplitConditions(Item *condition, QEP_TAB *current_table, std::vector< Item *> *predicates_below_join, std::vector< PendingCondition > *predicates_above_join, std::vector< PendingCondition > *join_conditions)
Definition: item.h:740
unsigned int uint
bool check_unique_constraint(TABLE *table)
Check unique_constraint.
FollowTailIterator is a special version of TableScanIterator that is used as part of WITH RECURSIVE q...
Definition: basic_row_iterators.h:490
void set_using_table_scan(bool arg)
Definition: sql_executor.h:328
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)
void set_condition_optim()
Definition: sql_executor.h:307
void ConvertItemsToCopy(List< Item > *items, Field **fields, Temp_table_param *param, JOIN *join)
For historical reasons, derived table materialization and temporary table materialization didn&#39;t spec...
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:389
Definition: sql_executor.h:129
plan_idx firstmatch_return
Definition: sql_executor.h:398
uint rowid_len
Definition: sql_executor.h:123
Definition: sql_executor.h:530
bool starts_weedout() const
Return true if join_tab starts a Duplicate Weedout action.
Definition: sql_executor.h:340
uint32_t hash(const void *key, size_t length, const uint32_t initval)
Definition: hash.c:121
bool set_record_buffer(const QEP_TAB *tab)
Allocate a data buffer that the storage engine can use for fetching batches of records.
Definition: sql_executor.h:270
SJ_TMP_TABLE_TAB * tabs_end
Definition: sql_executor.h:103
static const char * key
Definition: suite_stubs.c:14
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:408
int report_handler_error(TABLE *table, int error)
Help function when we get some an error from the table handler.
Filesort * filesort
Definition: sql_executor.h:543
CACHE_FIELD * copy_current_rowid
Definition: sql_executor.h:500
Item * having
HAVING condition for checking prior saving a record into tmp table.
Definition: sql_executor.h:516
bool prepare_sum_aggregators(Item_sum **func_ptr, bool need_distinct)
uint ref_item_slice
Slice number of the ref items array to switch to before reading rows from this table.
Definition: sql_executor.h:555
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:141
Definition: sql_executor.h:529
A position of table within a join order.
Definition: sql_select.h:343
Query optimization plan node.
Definition: sql_select.h:579
SJ_TMP_TABLE * check_weed_out_table
Definition: sql_executor.h:391
bool finishes_weedout() const
Return true if join_tab finishes a Duplicate Weedout action.
Definition: sql_executor.h:343
Definition: sql_executor.h:99
bool not_used_in_distinct
Definition: sql_executor.h:510
Definition: sql_executor.h:422
Definition: key.h:111
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:597
In first windowing step, copies non-window functions which do not rely on window functions, i.e.
Definition: sql_executor.h:197
Item * condition_optim() const
Definition: sql_executor.h:304
plan_idx first_unmatched
used for optimization purposes only
Definition: sql_executor.h:414
Definition: sql_executor.h:648
void update_tmptable_sum_func(Item_sum **func_ptr, TABLE *tmp_table)
Update record 0 in tmp_table from record 1.
Use this class when you need a QEP_TAB not connected to any JOIN_TAB.
Definition: sql_executor.h:645
Definition: opt_range.h:229
SJ_TMP_TABLE * flush_weedout_table
Definition: sql_executor.h:390
bool is_confluent
Definition: sql_executor.h:112
#define NO_PLAN_IDX
undefined index
Definition: sql_opt_exec_shared.h:54
void set_keyread_optim()
Definition: sql_executor.h:309
struct TABLE::@120 reginfo
Sorting related info.
Definition: filesort.h:49
void set_quick_optim()
Definition: sql_executor.h:306
uint64_t table_map
Definition: my_table_map.h:30
int table_index_to_attach_to
Definition: sql_executor.h:673
Item * m_condition_optim
Definition: sql_executor.h:558
bool do_firstmatch() const
Return true if join_tab should perform a FirstMatch action.
Definition: sql_executor.h:334
unique_ptr_destroy_only< RowIterator > PossiblyAttachFilterIterator(unique_ptr_destroy_only< RowIterator > iterator, const std::vector< Item *> &conditions, THD *thd)
bool change_to_use_tmp_fields(List< Item > &all_fields, size_t num_select_elements, THD *thd, Ref_item_array ref_item_array, List< Item > *res_selected_fields, List< Item > *res_all_fields)
Change all funcs and sum_funcs to fields in tmp table, and create new list of all items...
bool do_loosescan() const
Return true if join_tab should perform a LooseScan action.
Definition: sql_executor.h:337
The slice with pointers to columns of table(s), ie., the actual Items.
Definition: sql_opt_exec_shared.h:670
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 ...
void restore_quick_optim_and_condition()
Used to begin a new execution of a subquery.
Definition: sql_executor.h:371
Definition: sql_executor.h:533
TABLE * table
Reference to temporary table.
Definition: sql_executor.h:157
TABLE * tmp_table
Definition: sql_executor.h:126
Definition: table.h:2481
const uint inner_table_index
Index in join_tab for first inner table.
Definition: sql_executor.h:155
QEP_TAB * qep_tab
Definition: sql_executor.h:76
Definition: sql_opt_exec_shared.h:58
bool have_confluent_row
Definition: sql_executor.h:118
bool change_refs_to_tmp_fields(List< Item > &all_fields, size_t num_select_elements, THD *thd, Ref_item_array ref_item_array, List< Item > *res_selected_fields, List< Item > *res_all_fields)
Change all sum_func refs to fields to point at fields in tmp table.
class QEP_TAB * qep_tab
Definition: table.h:1612
#define false
Definition: config_static.h:43
ulonglong unique_hash(const Field *field, ulonglong *hash)
Generate hash for a field.
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:74
Definition: items.h:34
void set_reversed_access(bool arg)
Definition: sql_executor.h:313
TABLE_LIST * table_ref
Pointer to table reference.
Definition: sql_executor.h:387
bool filesort(THD *thd, Filesort *filesort, RowIterator *source_iterator, Filesort_info *fs_info, Sort_result *sort_result, ha_rows *found_rows)
Sort a table.
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:765
Dialog Client Authentication nullptr
bool update_sum_func(Item_sum **func_ptr)
uint null_bits
Definition: sql_executor.h:121