MySQL  8.0.18
Source Code Documentation
sql_optimizer.h
Go to the documentation of this file.
1 #ifndef SQL_OPTIMIZER_INCLUDED
2 #define SQL_OPTIMIZER_INCLUDED
3 
4 /* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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_optimizer.h
28  Classes used for query optimizations.
29 */
30 
31 /*
32  This structure is used to collect info on potentially sargable
33  predicates in order to check whether they become sargable after
34  reading const tables.
35  We form a bitmap of indexes that can be used for sargable predicates.
36  Only such indexes are involved in range analysis.
37 */
38 
39 #include <string.h>
40 #include <sys/types.h>
41 #include <algorithm>
42 #include <memory>
43 
44 #include "my_alloc.h"
45 #include "my_base.h"
46 #include "my_compiler.h"
47 #include "my_dbug.h"
48 #include "my_table_map.h"
49 #include "sql/field.h"
50 #include "sql/item.h"
51 #include "sql/item_subselect.h"
52 #include "sql/mem_root_array.h"
53 #include "sql/opt_explain_format.h" // Explain_sort_clause
54 #include "sql/row_iterator.h"
55 #include "sql/sql_array.h"
56 #include "sql/sql_class.h"
57 #include "sql/sql_const.h"
58 #include "sql/sql_executor.h" // Next_select_func
59 #include "sql/sql_lex.h"
60 #include "sql/sql_list.h"
62 #include "sql/sql_select.h" // Key_use
63 #include "sql/table.h"
64 #include "sql/temp_table_param.h"
65 #include "template_utils.h"
66 
67 class COND_EQUAL;
68 class Item_sum;
69 class Opt_trace_context;
70 class Window;
71 struct MYSQL_LOCK;
72 
74 
75 // Key_use has a trivial destructor, no need to run it from Mem_root_array.
77 
78 class Cost_model_server;
79 
81  Field *field; /* field against which to check sargability */
82  Item **arg_value; /* values of potential keys for lookups */
83  uint num_values; /* number of values in the above array */
84 };
85 
86 struct ROLLUP {
91  List<Item> *fields_list; ///< SELECT list
92  List<Item> *all_fields; ///< Including hidden fields
93 };
94 
95 /**
96  Wrapper for ORDER* pointer to trace origins of ORDER list
97 
98  As far as ORDER is just a head object of ORDER expression
99  chain, we need some wrapper object to associate flags with
100  the whole ORDER list.
101 */
103  /**
104  Private empty class to implement type-safe NULL assignment
105 
106  This private utility class allows us to implement a constructor
107  from NULL and only NULL (or 0 -- this is the same thing) and
108  an assignment operator from NULL.
109  Assignments from other pointers still prohibited since other
110  pointer types are incompatible with the "null" type, and the
111  casting is impossible outside of ORDER_with_src class, since
112  the "null" type is private.
113  */
114  struct null {};
115 
116  public:
117  ORDER *order; ///< ORDER expression that we are wrapping with this class
118  Explain_sort_clause src; ///< origin of order list
119 
120  private:
121  int flags; ///< bitmap of Explain_sort_property
122 
123  public:
125 
127  : order(order_arg),
128  src(src_arg),
129  flags(order_arg ? ESP_EXISTS : ESP_none) {}
130 
131  /**
132  Type-safe NULL assignment
133 
134  See a commentary for the "null" type above.
135  */
137  clean();
138  return *this;
139  }
140 
141  /**
142  Type-safe constructor from NULL
143 
144  See a commentary for the "null" type above.
145  */
147 
148  /**
149  Transparent access to the wrapped order list
150 
151  These operators are safe, since we don't do any conversion of
152  ORDER_with_src value, but just an access to the wrapped
153  ORDER pointer value.
154  We can use ORDER_with_src objects instead ORDER pointers in
155  a transparent way without accessor functions.
156 
157  @note This operator also implements safe "operator bool()"
158  functionality.
159  */
160  operator ORDER *() { return order; }
161  operator const ORDER *() const { return order; }
162 
163  ORDER *operator->() const { return order; }
164 
165  void clean() {
166  order = NULL;
167  src = ESC_none;
168  flags = ESP_none;
169  }
170 
171  int get_flags() const {
173  return flags;
174  }
175 };
176 
177 class JOIN {
178  JOIN(const JOIN &rhs); /**< not implemented */
179  JOIN &operator=(const JOIN &rhs); /**< not implemented */
180 
181  public:
182  JOIN(THD *thd_arg, SELECT_LEX *select)
183  : select_lex(select),
184  unit(select->master_unit()),
185  thd(thd_arg),
186  join_tab(NULL),
187  qep_tab(NULL),
188  best_ref(NULL),
189  map2table(NULL),
190  map2qep_tab(NULL),
192  tables(0),
193  primary_tables(0),
194  const_tables(0),
195  tmp_tables(0),
196  send_group_parts(0),
199  // @todo Can this be substituted with select->is_explicitly_grouped()?
200  grouped(select->is_explicitly_grouped()),
202  all_table_map(0),
203  // Inner tables may always be considered to be constant:
207  send_records(0),
208  found_records(0),
209  examined_rows(0),
210  row_limit(0),
211  m_select_limit(0),
214  positions(NULL),
216  best_read(0.0),
217  best_rowcount(0),
218  sort_cost(0.0),
219  windowing_cost(0.0),
220  // Needed in case optimizer short-cuts, set properly in
221  // make_tmp_tables_info()
222  fields(&select->item_list),
223  group_fields(),
225  sum_funcs(NULL),
226  sum_funcs_end(),
227  tmp_table_param(thd_arg->mem_root),
228  lock(thd->lock),
229  rollup(),
230  // @todo Can this be substituted with select->is_implicitly_grouped()?
231  implicit_grouping(select->is_implicitly_grouped()),
232  select_distinct(select->is_distinct()),
241  all_fields(select->all_fields),
242  fields_list(select->fields_list),
243  tmp_all_fields(nullptr),
244  tmp_fields_list(nullptr),
245  error(0),
246  order(select->order_list.first, ESC_ORDER_BY),
247  group_list(select->group_list.first, ESC_GROUP_BY),
248  m_windows(select->m_windows),
251  explain_flags(),
252  /*
253  Those four members are meaningless before JOIN::optimize(), so force a
254  crash if they are used before that.
255  */
256  where_cond((Item *)1),
257  having_cond((Item *)1),
258  having_for_explain((Item *)1),
259  tables_list((TABLE_LIST *)1),
260  cond_equal(NULL),
261  return_tab(0),
262  ref_items(nullptr),
269  sj_tmp_tables(),
270  sjm_exec_list(),
271  group_sent(false),
273  with_json_agg(select->json_agg_func_used()),
274  optimized(false),
275  executed(false),
283  // Calculate the number of groups
284  for (ORDER *group = group_list; group; group = group->next)
286  }
287 
288  /// Query block that is optimized and executed using this JOIN
290  /// Query expression referring this query block
292  /// Thread handler
293  THD *const thd;
294 
295  /**
296  Optimal query execution plan. Initialized with a tentative plan in
297  JOIN::make_join_plan() and later replaced with the optimal plan in
298  get_best_combination().
299  */
301  /// Array of QEP_TABs
303 
304  /**
305  Array of plan operators representing the current (partial) best
306  plan. The array is allocated in JOIN::make_join_plan() and is valid only
307  inside this function. Initially (*best_ref[i]) == join_tab[i].
308  The optimizer reorders best_ref.
309  */
311  JOIN_TAB **map2table; ///< mapping between table indexes and JOIN_TABs
312  QEP_TAB **map2qep_tab; ///< mapping between table indexes and QEB_TABs
313  /*
314  The table which has an index that allows to produce the requried ordering.
315  A special value of 0x1 means that the ordering will be produced by
316  passing 1st non-const table to filesort(). NULL means no such table exists.
317  */
319  /**
320  Before plan has been created, "tables" denote number of input tables in the
321  query block and "primary_tables" is equal to "tables".
322  After plan has been created (after JOIN::get_best_combination()),
323  the JOIN_TAB objects are enumerated as follows:
324  - "tables" gives the total number of allocated JOIN_TAB objects
325  - "primary_tables" gives the number of input tables, including
326  materialized temporary tables from semi-join operation.
327  - "const_tables" are those tables among primary_tables that are detected
328  to be constant.
329  - "tmp_tables" is 0, 1 or 2 (more if windows) and counts the maximum
330  possible number of intermediate tables in post-processing (ie sorting and
331  duplicate removal).
332  Later, tmp_tables will be adjusted to the correct number of
333  intermediate tables, @see JOIN::make_tmp_tables_info.
334  - The remaining tables (ie. tables - primary_tables - tmp_tables) are
335  input tables to materialized semi-join operations.
336  The tables are ordered as follows in the join_tab array:
337  1. const primary table
338  2. non-const primary tables
339  3. intermediate sort/group tables
340  4. possible holes in array
341  5. semi-joined tables used with materialization strategy
342  */
343  uint tables; ///< Total number of tables in query block
344  uint primary_tables; ///< Number of primary input tables in query block
345  uint const_tables; ///< Number of primary tables deemed constant
346  uint tmp_tables; ///< Number of temporary tables used by query
348  /**
349  Indicates that the data will be aggregated (typically GROUP BY),
350  _and_ that it is already processed in an order that is compatible with
351  the grouping in use (e.g. because we are scanning along an index,
352  or because an earlier step sorted the data in a group-compatible order).
353 
354  Note that this flag changes value at multiple points during optimization;
355  if it's set when a temporary table is created, this means we aggregate
356  into said temporary table (end_write_group is chosen instead of end_write),
357  but if it's set later, it means that we can aggregate as we go,
358  just before sending the data to the client (end_send_group is chosen
359  instead of end_send).
360 
361  @see make_group_fields, alloc_group_fields, JOIN::exec
362  */
364  bool seen_first_record; ///< Whether we've seen at least one row already
365  bool grouped; ///< If query contains GROUP BY clause
366  bool do_send_rows; ///< If true, send produced rows using query_result
367  table_map all_table_map; ///< Set of tables contained in query
368  table_map const_table_map; ///< Set of tables found to be const
369  /**
370  Const tables which are either:
371  - not empty
372  - empty but inner to a LEFT JOIN, thus "considered" not empty for the
373  rest of execution (a NULL-complemented row will be used).
374  */
376  /**
377  Used in some loops which scan the JOIN's tables: it is the bitmap of all
378  tables which are dependencies of lateral derived tables which the loop
379  has not yet processed.
380  */
382 
383  /* Number of records produced after join + group operation */
388  // m_select_limit is used to decide if we are likely to scan the whole table.
390  /**
391  Used to fetch no more than given amount of rows per one
392  fetch operation of server side cursor.
393  The value is checked in end_send and end_send_group in fashion, similar
394  to offset_limit_cnt:
395  - fetch_limit= HA_POS_ERROR if there is no cursor.
396  - when we open a cursor, we set fetch_limit to 0,
397  - on each fetch iteration we add num_rows to fetch to fetch_limit
398  */
400 
401  /**
402  This is the result of join optimization.
403 
404  @note This is a scratch array, not used after get_best_combination().
405  */
407 
408  /******* Join optimization state members start *******/
409 
410  /* Current join optimization state */
412 
413  /* We also maintain a stack of join optimization states in * join->positions[]
414  */
415  /******* Join optimization state members end *******/
416 
418  /**
419  The cost of best complete join plan found so far during optimization,
420  after optimization phase - cost of picked join order (not taking into
421  account the changes made by test_if_skip_sort_order()).
422  */
423  double best_read;
424  /**
425  The estimated row count of the plan with best read time (see above).
426  */
428  /// Expected cost of filesort.
429  double sort_cost;
430  /// Expected cost of windowing;
435  /**
436  Describes a temporary table.
437  Each tmp table has its own tmp_table_param.
438  The one here has two roles:
439  - is transiently used as a model by create_intermediate_table(), to build
440  the tmp table's own tmp_table_param.
441  - is also used as description of the pseudo-tmp-table of grouping
442  (REF_SLICE_ORDERED_GROUP_BY) (e.g. in end_send_group()).
443  */
446 
447  ROLLUP rollup; ///< Used with rollup
448  bool implicit_grouping; ///< True if aggregated but no GROUP BY
449 
450  /**
451  At construction time, set if SELECT DISTINCT. May be reset to false
452  later, when we set up a temporary table operation that deduplicates for us.
453  */
455 
456  /**
457  If we have the GROUP BY statement in the query,
458  but the group_list was emptied by optimizer, this
459  flag is true.
460  It happens when fields in the GROUP BY are from
461  constant table
462  */
464 
465  /*
466  simple_xxxxx is set if ORDER/GROUP BY doesn't include any references
467  to other tables than the first non-constant table in the JOIN.
468  It's also set if ORDER/GROUP BY is empty.
469  Used for deciding for or against using a temporary table to compute
470  GROUP/ORDER BY.
471  */
473 
474  /*
475  m_ordered_index_usage is set if an ordered index access
476  should be used instead of a filesort when computing
477  ORDER/GROUP BY.
478  */
479  enum {
480  ORDERED_INDEX_VOID, // No ordered index avail.
481  ORDERED_INDEX_GROUP_BY, // Use index for GROUP BY
482  ORDERED_INDEX_ORDER_BY // Use index for ORDER BY
484 
485  /**
486  Is set if we have a GROUP BY and we have ORDER BY on a constant or when
487  sorting isn't required.
488  */
490 
491  /**
492  If true we need a temporary table on the result set before any
493  windowing steps, e.g. for DISTINCT or we have a query ORDER BY.
494  See details in JOIN::optimize
495  */
497 
498  /// If JOIN has lateral derived tables (is set at start of planning)
500 
501  /// Used and updated by JOIN::make_join_plan() and optimize_keyuse()
503 
504  /// List storing all expressions used in query block
506 
507  /// List storing all expressions of select list
509 
510  /**
511  This is similar to tmp_fields_list, but it also contains necessary
512  extras: expressions added for ORDER BY, GROUP BY, window clauses,
513  underlying items of split items.
514  */
516 
517  /**
518  Array of pointers to lists of expressions.
519  Each list represents the SELECT list at a certain stage of execution.
520  This array is only used when the query makes use of tmp tables: after
521  writing to tmp table (e.g. for GROUP BY), if this write also does a
522  function's calculation (e.g. of SUM), after the write the function's value
523  is in a column of the tmp table. If a SELECT list expression is the SUM,
524  and we now want to read that materialized SUM and send it forward, a new
525  expression (Item_field type instead of Item_sum), is needed. The new
526  expressions are listed in JOIN::tmp_fields_list[x]; 'x' is a number
527  (REF_SLICE_).
528  Same is applicable to tmp_all_fields.
529  @see JOIN::make_tmp_tables_info()
530  */
532 
533  int error; ///< set in optimize(), exec(), prepare_result()
534 
535  /**
536  ORDER BY and GROUP BY lists, to transform with prepare,optimize and exec
537  */
539 
540  /**
541  Any window definitions
542  */
544 
545  /**
546  True if a window requires a certain order of rows, which implies that any
547  order of rows coming out of the pre-window join will be disturbed.
548  */
550 
551  /// If we have set up tmp tables for windowing, @see make_tmp_tables_info
553 
554  /**
555  Buffer to gather GROUP BY, ORDER BY and DISTINCT QEP details for EXPLAIN
556  */
558 
559  /**
560  JOIN::having_cond is initially equal to select_lex->having_cond, but may
561  later be changed by optimizations performed by JOIN.
562  The relationship between the JOIN::having_cond condition and the
563  associated variable select_lex->having_value is so that
564  having_value can be:
565  - COND_UNDEF if a having clause was not specified in the query or
566  if it has not been optimized yet
567  - COND_TRUE if the having clause is always true, in which case
568  JOIN::having_cond is set to NULL.
569  - COND_FALSE if the having clause is impossible, in which case
570  JOIN::having_cond is set to NULL
571  - COND_OK otherwise, meaning that the having clause needs to be
572  further evaluated
573  All of the above also applies to the where_cond/select_lex->cond_value
574  pair.
575  */
576  /**
577  Optimized WHERE clause item tree (valid for one single execution).
578  Used in JOIN execution if no tables. Otherwise, attached in pieces to
579  JOIN_TABs and then not used in JOIN execution.
580  Printed by EXPLAIN EXTENDED.
581  Initialized by SELECT_LEX::get_optimizable_conditions().
582  */
584  /**
585  Optimized HAVING clause item tree (valid for one single execution).
586  Used in JOIN execution, as last "row filtering" step. With one exception:
587  may be pushed to the JOIN_TABs of temporary tables used in DISTINCT /
588  GROUP BY (see JOIN::make_tmp_tables_info()); in that case having_cond is
589  set to NULL, but is first saved to having_for_explain so that EXPLAIN
590  EXTENDED can still print it.
591  Initialized by SELECT_LEX::get_optimizable_conditions().
592  */
594  Item *having_for_explain; ///< Saved optimized HAVING for EXPLAIN
595  /**
596  Pointer set to select_lex->get_table_list() at the start of
597  optimization. May be changed (to NULL) only if optimize_aggregated_query()
598  optimizes tables away.
599  */
602  /*
603  Join tab to return to. Points to an element of join->join_tab array, or to
604  join->join_tab[-1].
605  This is used at execution stage to shortcut join enumeration. Currently
606  shortcutting is done to handle outer joins or handle semi-joins with
607  FirstMatch strategy.
608  */
610 
611  /**
612  ref_items is an array of 5 slices, each containing an array of Item
613  pointers. ref_items is used in different phases of query execution.
614  - slice 0 is initially the same as SELECT_LEX::base_ref_items, ie it is
615  the set of items referencing fields from base tables. During optimization
616  and execution it may be temporarily overwritten by slice 1-3.
617  - slice 1 is a representation of the used items when being read from
618  the first temporary table.
619  - slice 2 is a representation of the used items when being read from
620  the second temporary table.
621  - slice 3 is a representation of the used items when used in
622  aggregation but no actual temporary table is needed.
623  - slice 4 is a copy of the original slice 0. It is created if
624  slice overwriting is necessary, and it is used to restore
625  original values in slice 0 after having been overwritten.
626  - slices 5 -> N are used by windowing:
627  first are all the window's out tmp tables,
628  the next indexes are reserved for the windows' frame buffers (in the same
629  order), if any, e.g.
630 
631  One window: 5: window 1's out table
632  6: window 1's FB
633 
634  Two windows: 5: window 1's out table
635  6: window 2's out table
636  7: window 1's FB
637  8: window 2's FB
638  and so on.
639 
640  Slice 0 is allocated for the lifetime of a statement, whereas slices 1-4
641  are associated with a single optimization. The size of slice 0 determines
642  the slice size used when allocating the other slices.
643  */
645  *ref_items; // cardinality: REF_SLICE_SAVED_BASE + 1 + #windows*2
646 
647  /**
648  If slice REF_SLICE_ORDERED_GROUP_BY has been created, this is the QEP_TAB
649  which is right before calculation of items in this slice.
650  */
652 
653  /**
654  The slice currently stored in ref_items[0].
655  Used to restore the base ref_items slice from the "save" slice after it
656  has been overwritten by another slice (1-3).
657  */
659 
660  /**
661  Used only if this query block is recursive. Contains count of
662  all executions of this recursive query block, since the last
663  this->reset().
664  */
666 
667  /**
668  <> NULL if optimization has determined that execution will produce an
669  empty result before aggregation, contains a textual explanation on why
670  result is empty. Implicitly grouped queries may still produce an
671  aggregation row.
672  @todo - suggest to set to "Preparation determined that query is empty"
673  when SELECT_LEX::is_empty_query() is true.
674  */
675  const char *zero_result_cause;
676 
677  /**
678  True if, at this stage of processing, subquery materialization is allowed
679  for children subqueries of this JOIN (those in the SELECT list, in WHERE,
680  etc). If false, and we have to evaluate a subquery at this stage, then we
681  must choose EXISTS.
682  */
684  /**
685  True if plan search is allowed to use references to expressions outer to
686  this JOIN (for example may set up a 'ref' access looking up an outer
687  expression in the index, etc).
688  */
690 
691  /* Temporary tables used to weed-out semi-join duplicates */
694  /* end of allocation caching storage */
695 
696  /** Exec time only: true <=> current group has been sent */
698  /// If true, calculate found rows for this query block
700 
701  /**
702  This will force tmp table to NOT use index + update for group
703  operation as it'll cause [de]serialization for each json aggregated
704  value and is very ineffective (times worse).
705  Server should use filesort, or tmp table + filesort to resolve GROUP BY
706  with JSON aggregate functions.
707  */
709 
710  /**
711  If set, "fields" has been replaced with a set of Item_refs for rollup
712  processing; see the AggregateIterator constructor for more details.
713  This is used when constructing iterators only; it is not used during
714  execution.
715  */
717 
718  /// True if plan is const, ie it will return zero or one rows.
719  bool plan_is_const() const { return const_tables == primary_tables; }
720 
721  /**
722  True if plan contains one non-const primary table (ie not including
723  tables taking part in semi-join materialization).
724  */
726 
727  bool optimize();
728  void reset();
729  void exec();
730  bool prepare_result();
731  bool destroy();
732  bool alloc_func_list();
734  bool before_group_by, bool recompute = false);
735 
736  /**
737  Overwrites one slice of ref_items with the contents of another slice.
738  In the normal case, dst and src have the same size().
739  However: the rollup slices may have smaller size than slice_sz.
740  */
741  void copy_ref_item_slice(uint dst_slice, uint src_slice) {
742  copy_ref_item_slice(ref_items[dst_slice], ref_items[src_slice]);
743  }
745  DBUG_ASSERT(dst_arr.size() >= src_arr.size());
746  void *dest = dst_arr.array();
747  const void *src = src_arr.array();
748  if (!src_arr.is_null())
749  memcpy(dest, src, src_arr.size() * src_arr.element_size());
750  }
751 
752  /**
753  Allocate a ref_item slice, assume that slice size is in ref_items[0]
754 
755  @param thd_arg thread handler
756  @param sliceno The slice number to allocate in JOIN::ref_items
757 
758  @returns false if success, true if error
759  */
760  bool alloc_ref_item_slice(THD *thd_arg, int sliceno) {
761  DBUG_ASSERT(sliceno > 0 && ref_items[sliceno].is_null());
762  size_t count = ref_items[0].size();
763  Item **slice =
764  pointer_cast<Item **>(thd_arg->alloc(sizeof(Item *) * count));
765  if (slice == NULL) return true;
766  ref_items[sliceno] = Ref_item_array(slice, count);
767  return false;
768  }
769  /**
770  Overwrite the base slice of ref_items with the slice supplied as argument.
771 
772  @param sliceno number to overwrite the base slice with, must be 1-4 or
773  4 + windowno.
774  */
775  void set_ref_item_slice(uint sliceno) {
776  DBUG_ASSERT((int)sliceno >= 1);
777  if (current_ref_item_slice != sliceno) {
779  DBUG_PRINT("info",
780  ("ref slice %u -> %u", current_ref_item_slice, sliceno));
781  current_ref_item_slice = sliceno;
782  }
783  }
784 
785  /// @note do also consider Switch_ref_item_slice
787 
788  /**
789  Returns the clone of fields_list which is appropriate for evaluating
790  expressions at the current stage of execution; which stage is denoted by
791  the value of current_ref_item_slice.
792  */
794 
795  bool optimize_rollup();
798  Item_sum ***func);
800  List<Item> &fields);
801  bool rollup_send_data(uint idx);
804  /**
805  Release memory and, if possible, the open tables held by this execution
806  plan (and nested plans). It's used to release some tables before
807  the end of execution in order to increase concurrency and reduce
808  memory consumption.
809  */
810  void join_free();
811  /** Cleanup this JOIN. Not a full cleanup. reusable? */
812  void cleanup();
813 
814  bool clear_fields(table_map *save_nullinfo);
815  void restore_fields(table_map save_nullinfo);
816 
817  /**
818  Return whether the caller should send a row even if the join
819  produced no rows if:
820  - there is an aggregate function (sum_func_count!=0), and
821  - the query is not grouped, and
822  - a possible HAVING clause evaluates to TRUE.
823 
824  @note: if there is a having clause, it must be evaluated before
825  returning the row.
826  */
827  bool send_row_on_empty_set() const {
828  return (do_send_rows && tmp_table_param.sum_func_count != 0 &&
831  }
832 
833  bool generate_derived_keys();
834  void finalize_derived_keys();
835  bool get_best_combination();
836  bool attach_join_conditions(plan_idx last_tab);
837 
838  private:
839  bool attach_join_condition_to_nest(plan_idx first_inner, plan_idx last_tab,
840  Item *join_cond, bool is_sj_mat_cond);
841 
842  public:
845  bool force_stable_sort = false);
847  void refine_best_rowcount();
849  table_map plan_tables, uint idx);
851 
852  void mark_const_table(JOIN_TAB *table, Key_use *key);
853  /// State of execution plan. Currently used only for EXPLAIN
855  NO_PLAN, ///< No plan is ready yet
856  ZERO_RESULT, ///< Zero result cause is set
857  NO_TABLES, ///< Plan has no tables
858  PLAN_READY ///< Plan is ready
859  };
860  /// See enum_plan_state
862  bool is_optimized() const { return optimized; }
863  void set_optimized() { optimized = true; }
864  bool is_executed() const { return executed; }
865  void set_executed() { executed = true; }
866 
867  /**
868  Retrieve the cost model object to be used for this join.
869 
870  @return Cost model object for the join
871  */
872 
873  const Cost_model_server *cost_model() const {
874  DBUG_ASSERT(thd != NULL);
875  return thd->cost_model();
876  }
877 
878  /**
879  Check if FTS index only access is possible
880  */
881  bool fts_index_access(JOIN_TAB *tab);
882 
884  /**
885  Propagate dependencies between tables due to outer join relations.
886 
887  @returns false if success, true if error
888  */
889  bool propagate_dependencies();
890 
891  /**
892  Returns whether one should send the current row on to the output,
893  or ignore it. (In particular, this implements OFFSET handling
894  in the non-iterator executor.)
895  */
897  if (!do_send_rows) {
898  return false;
899  }
900  if (unit->offset_limit_cnt > 0) {
902  return false;
903  } else {
904  return true;
905  }
906  }
907 
908  /**
909  Handle offloading of query parts to the underlying engines, when
910  such is supported by their implementation.
911 
912  @returns 0 if success, 1 if error
913  */
914  int push_to_engines();
915 
916  RowIterator *root_iterator() const { return m_root_iterator.get(); }
918  return move(m_root_iterator);
919  }
921  m_root_iterator = move(iterator);
922  }
923 
924  private:
925  bool optimized; ///< flag to avoid double optimization in EXPLAIN
926 
927  /**
928  Set by exec(), reset by reset(). Note that this needs to be set
929  _during_ the query (not only when it's done executing), or the
930  dynamic range optimizer will not understand which tables have been
931  read.
932  */
933  bool executed;
934 
935  /// Final execution plan state. Currently used only for EXPLAIN
937 
938  public:
939  /*
940  When join->select_count is set, tables will not be optimized away.
941  The call to records() will be delayed until the execution phase and
942  the counting will be done on an index of Optimizer's choice.
943  The index will be decided in find_shortest_key(), called from
944  optimize_aggregated_query().
945  */
947 
948  private:
949  /**
950  Create a temporary table to be used for processing DISTINCT/ORDER
951  BY/GROUP BY.
952 
953  @note Will modify JOIN object wrt sort/group attributes
954 
955  @param tab the JOIN_TAB object to attach created table to
956  @param tmp_table_fields List of items that will be used to define
957  column types of the table.
958  @param tmp_table_group Group key to use for temporary table, NULL if none.
959  @param save_sum_fields If true, do not replace Item_sum items in
960  @c tmp_fields list with Item_field items referring
961  to fields in temporary table.
962 
963  @returns false on success, true on failure
964  */
965  bool create_intermediate_table(QEP_TAB *tab, List<Item> *tmp_table_fields,
966  ORDER_with_src &tmp_table_group,
967  bool save_sum_fields);
968 
969  /**
970  Optimize distinct when used on a subset of the tables.
971 
972  E.g.,: SELECT DISTINCT t1.a FROM t1,t2 WHERE t1.b=t2.b
973  In this case we can stop scanning t2 when we have found one t1.a
974  */
975  void optimize_distinct();
976 
977  /**
978  Function sets FT hints, initializes FT handlers and
979  checks if FT index can be used as covered.
980  */
981  bool optimize_fts_query();
982 
983  bool prune_table_partitions();
984  /**
985  Initialize key dependencies for join tables.
986 
987  TODO figure out necessity of this method. Current test
988  suite passed without this intialization.
989  */
991  JOIN_TAB *const tab_end = join_tab + tables;
992  for (JOIN_TAB *tab = join_tab; tab < tab_end; tab++)
993  tab->key_dependent = tab->dependent;
994  }
995 
996  private:
997  void set_prefix_tables();
998  void cleanup_item_list(List<Item> &items) const;
999  void set_semijoin_embedding();
1000  bool make_join_plan();
1001  bool init_planner_arrays();
1002  bool extract_const_tables();
1004  void update_sargable_from_const(SARGABLE_PARAM *sargables);
1005  bool estimate_rowcount();
1006  void optimize_keyuse();
1007  void set_semijoin_info();
1008  /**
1009  An utility function - apply heuristics and optimize access methods to tables.
1010  @note Side effect - this function could set 'Impossible WHERE' zero
1011  result.
1012  */
1013  void adjust_access_methods();
1014  void update_depend_map();
1015  void update_depend_map(ORDER *order);
1016  /**
1017  Fill in outer join related info for the execution plan structure.
1018 
1019  For each outer join operation left after simplification of the
1020  original query the function set up the following pointers in the linear
1021  structure join->join_tab representing the selected execution plan.
1022  The first inner table t0 for the operation is set to refer to the last
1023  inner table tk through the field t0->last_inner.
1024  Any inner table ti for the operation are set to refer to the first
1025  inner table ti->first_inner.
1026  The first inner table t0 for the operation is set to refer to the
1027  first inner table of the embedding outer join operation, if there is any,
1028  through the field t0->first_upper.
1029  The on expression for the outer join operation is attached to the
1030  corresponding first inner table through the field t0->on_expr_ref.
1031  Here ti are structures of the JOIN_TAB type.
1032 
1033  EXAMPLE. For the query:
1034  @code
1035  SELECT * FROM t1
1036  LEFT JOIN
1037  (t2, t3 LEFT JOIN t4 ON t3.a=t4.a)
1038  ON (t1.a=t2.a AND t1.b=t3.b)
1039  WHERE t1.c > 5,
1040  @endcode
1041 
1042  given the execution plan with the table order t1,t2,t3,t4
1043  is selected, the following references will be set;
1044  t4->last_inner=[t4], t4->first_inner=[t4], t4->first_upper=[t2]
1045  t2->last_inner=[t4], t2->first_inner=t3->first_inner=[t2],
1046  on expression (t1.a=t2.a AND t1.b=t3.b) will be attached to
1047  *t2->on_expr_ref, while t3.a=t4.a will be attached to *t4->on_expr_ref.
1048 
1049  @note
1050  The function assumes that the simplification procedure has been
1051  already applied to the join query (see simplify_joins).
1052  This function can be called only after the execution plan
1053  has been chosen.
1054  */
1055  void make_outerjoin_info();
1056 
1057  /**
1058  Initialize ref access for all tables that use it.
1059 
1060  @return False if success, True if error
1061 
1062  @note We cannot setup fields used for ref access before we have sorted
1063  the items within multiple equalities according to the final order of
1064  the tables involved in the join operation. Currently, this occurs in
1065  @see substitute_for_best_equal_field().
1066  */
1067  bool init_ref_access();
1068  bool alloc_qep(uint n);
1069  void unplug_join_tabs();
1070  bool setup_semijoin_materialized_table(JOIN_TAB *tab, uint tableno,
1071  POSITION *inner_pos,
1072  POSITION *sjm_pos);
1073 
1074  bool add_having_as_tmp_table_cond(uint curr_tmp_table);
1075  bool make_tmp_tables_info();
1076  void set_plan_state(enum_plan_state plan_state_arg);
1079  ORDER *remove_const(ORDER *first_order, Item *cond, bool change_list,
1080  bool *simple_order, bool group_by);
1081 
1082  /**
1083  Check whether this is a subquery that can be evaluated by index look-ups.
1084  If so, change subquery engine to subselect_indexsubquery_engine.
1085 
1086  @retval 1 engine was changed
1087  @retval 0 engine wasn't changed
1088  @retval -1 OOM
1089  */
1090  int replace_index_subquery();
1091 
1092  /**
1093  Optimize DISTINCT, GROUP BY, ORDER BY clauses
1094 
1095  @retval false ok
1096  @retval true an error occurred
1097  */
1099 
1100  /**
1101  Test if an index could be used to replace filesort for ORDER BY/GROUP BY
1102 
1103  @details
1104  Investigate whether we may use an ordered index as part of either
1105  DISTINCT, GROUP BY or ORDER BY execution. An ordered index may be
1106  used for only the first of any of these terms to be executed. This
1107  is reflected in the order which we check for test_if_skip_sort_order()
1108  below. However we do not check for DISTINCT here, as it would have
1109  been transformed to a GROUP BY at this stage if it is a candidate for
1110  ordered index optimization.
1111  If a decision was made to use an ordered index, the availability
1112  if such an access path is stored in 'm_ordered_index_usage' for later
1113  use by 'execute' or 'explain'
1114  */
1115  void test_skip_sort();
1116 
1117  bool alloc_indirection_slices();
1118 
1119  /**
1120  If possible, convert the executor structures to a set of row iterators,
1121  storing the result in m_root_iterator. If not, m_root_iterator will remain
1122  nullptr.
1123  */
1124  void create_iterators();
1125 
1126  /**
1127  Create iterators with the knowledge that there are going to be zero rows
1128  coming from tables (before aggregation); typically because we know that
1129  all of them would be filtered away by WHERE (e.g. SELECT * FROM t1
1130  WHERE 1=2). This will normally yield no output rows, but if we have implicit
1131  aggregation, it might yield a single one.
1132  */
1134 
1135  /** @{ Helpers for create_iterators. */
1136  void create_table_iterators();
1140  /** @} */
1141 
1142  /**
1143  An iterator you can read from to get all records for this query.
1144 
1145  May be nullptr even after create_iterators() if the current query
1146  is not supported by the iterator executor.
1147  */
1149 };
1150 
1151 /**
1152  RAII class to ease the temporary switching to a different slice of
1153  the ref item array.
1154 */
1158 
1159  public:
1160  Switch_ref_item_slice(JOIN *join_arg, uint new_v)
1161  : join(join_arg), saved(join->get_ref_item_slice()) {
1162  if (!join->ref_items[new_v].is_null()) join->set_ref_item_slice(new_v);
1163  }
1165 };
1166 
1167 /**
1168  RAII class to ease the call of LEX::mark_broken() if error.
1169  Used during preparation and optimization of DML queries.
1170 */
1172  public:
1173  Prepare_error_tracker(THD *thd_arg) : thd(thd_arg) {}
1175  if (unlikely(thd->is_error())) thd->lex->mark_broken();
1176  }
1177 
1178  private:
1179  THD *const thd;
1180 };
1181 
1182 bool uses_index_fields_only(Item *item, TABLE *tbl, uint keyno,
1183  bool other_tbls_ok);
1184 bool remove_eq_conds(THD *thd, Item *cond, Item **retcond,
1185  Item::cond_result *cond_value);
1186 bool optimize_cond(THD *thd, Item **conds, COND_EQUAL **cond_equal,
1187  List<TABLE_LIST> *join_list, Item::cond_result *cond_value);
1189  COND_EQUAL *cond_equal,
1190  JOIN_TAB **table_join_idx);
1191 bool build_equal_items(THD *thd, Item *cond, Item **retcond,
1192  COND_EQUAL *inherited, bool do_inherit,
1193  List<TABLE_LIST> *join_list,
1194  COND_EQUAL **cond_equal_ref);
1197  Item_field **fields,
1198  List<Item> outer_exprs);
1199 Item_field *get_best_field(Item_field *item_field, COND_EQUAL *cond_equal);
1200 Item *make_cond_for_table(THD *thd, Item *cond, table_map tables,
1201  table_map used_table, bool exclude_expensive_cond);
1203  uint first_unused);
1204 
1205 /**
1206  Create an order list that consists of all non-const fields and items.
1207  This is usable for e.g. converting DISTINCT into GROUP or ORDER BY.
1208 
1209  Try to put the items in "order_list" first, to allow one to optimize away
1210  a later ORDER BY.
1211  */
1212 ORDER *create_order_from_distinct(THD *thd, Ref_item_array ref_item_array,
1213  ORDER *order_list, List<Item> &fields,
1214  bool skip_aggregates,
1215  bool convert_bit_fields_to_long,
1216  bool *all_order_by_fields_used);
1217 
1218 /**
1219  Returns true if arguments are a temporal Field having no date,
1220  part and a temporal expression having a date part.
1221  @param f Field
1222  @param v Expression
1223  */
1224 inline bool field_time_cmp_date(const Field *f, const Item *v) {
1225  return f->is_temporal() && !f->is_temporal_with_date() &&
1226  v->is_temporal_with_date();
1227 }
1228 
1229 bool substitute_gc(THD *thd, SELECT_LEX *select_lex, Item *where_cond,
1230  ORDER *group_list, ORDER *order);
1231 
1232 /// RAII class to manage JOIN::deps_of_remaining_lateral_derived_tables
1236  /// All lateral tables not part of this map should be ignored
1238 
1239  public:
1240  /**
1241  Constructor.
1242  @param j the JOIN
1243  @param plan_tables_arg @see
1244  JOIN::deps_of_remaining_lateral_derived_tables
1245  */
1247  : join(j),
1248  saved(join->deps_of_remaining_lateral_derived_tables),
1249  plan_tables(plan_tables_arg) {}
1254  }
1255  void recalculate(uint next_idx) {
1256  if (join->has_lateral)
1257  /*
1258  No cur_tab given, so assume we start from a place in the plan which
1259  may be backward or forward compared to where we were before:
1260  recalculate.
1261  */
1263  next_idx);
1264  }
1265 
1266  void recalculate(JOIN_TAB *cur_tab, uint next_idx) {
1267  /*
1268  We have just added cur_tab to the plan; if it's not lateral, the map
1269  doesn't change, no need to recalculate it.
1270  */
1271  if (join->has_lateral && cur_tab->table_ref->is_derived() &&
1272  cur_tab->table_ref->derived_unit()->m_lateral_deps)
1273  recalculate(next_idx);
1274  }
1275  void init() {
1276  // Normally done once in a run of JOIN::optimize().
1277  if (join->has_lateral) {
1279  // Forget stale value:
1281  }
1282  }
1283 };
1284 
1285 /**
1286  Estimates how many times a subquery will be executed as part of a
1287  query execution. If it is a cacheable subquery, the estimate tells
1288  how many times the subquery will be executed if it is not cached.
1289 
1290  @param[in] subquery the Item that represents the subquery
1291  @param[in,out] trace optimizer trace context
1292 
1293  @return the number of times the subquery is expected to be executed
1294 */
1295 double calculate_subquery_executions(const Item_subselect *subquery,
1296  Opt_trace_context *trace);
1297 
1298 /**
1299  Class which presents a view of the current candidate table order for a JOIN.
1300 */
1302  public:
1304 
1305  /// Returns the number of tables in the candidate plan.
1306  size_t size() const { return m_join->tables; }
1307 
1308  /// Returns the table reference at the given position in the candidate plan.
1309  const TABLE_LIST *table_ref(size_t position) const {
1310  return m_join->positions[position].table->table_ref;
1311  }
1312 
1313  private:
1314  const JOIN *const m_join;
1315 };
1316 
1317 extern const char *antijoin_null_cond;
1318 
1319 /**
1320  Checks if an Item, which is constant for execution, can be evaluated during
1321  optimization. It cannot be evaluated if it contains a subquery and the
1322  OPTION_NO_SUBQUERY_DURING_OPTIMIZATION query option is active.
1323 
1324  @param item the Item to check
1325  @param select the query block that contains the Item
1326  @return false if this Item contains a subquery and subqueries cannot be
1327  evaluated during optimization, or true otherwise
1328 */
1329 bool evaluate_during_optimization(const Item *item, const SELECT_LEX *select);
1330 
1331 #endif /* SQL_OPTIMIZER_INCLUDED */
Definition: item.h:737
JOIN(THD *thd_arg, SELECT_LEX *select)
Definition: sql_optimizer.h:182
State
Definition: sql_optimizer.h:87
bool allow_outer_refs
True if plan search is allowed to use references to expressions outer to this JOIN (for example may s...
Definition: sql_optimizer.h:689
Definition: item.h:3341
void create_iterators_for_zero_rows()
Create iterators with the knowledge that there are going to be zero rows coming from tables (before a...
Definition: sql_optimizer.cc:828
#define INNER_TABLE_BIT
Definition: sql_const.h:112
bool make_tmp_tables_info()
Init tmp tables usage info.
Definition: sql_select.cc:4162
SQL_I_List< ORDER > group_list
GROUP BY clause.
Definition: sql_lex.h:1152
Definition: sql_optimizer.h:177
bool extract_func_dependent_tables()
Extract const tables based on functional dependencies.
Definition: sql_optimizer.cc:5271
void set_prefix_tables()
Assign set of available (prefix) tables to all tables in query block.
Definition: sql_optimizer.cc:4764
Original query has this clause.
Definition: opt_explain_format.h:439
Class which presents a view of the current candidate table order for a JOIN.
Definition: sql_optimizer.h:1301
void restore()
Definition: sql_optimizer.h:1251
void set_semijoin_embedding()
Set semi-join embedding join nest pointers.
Definition: sql_optimizer.cc:5572
Next_select_func first_select
Definition: sql_optimizer.h:417
void create_table_iterators()
Definition: sql_executor.cc:2620
bool is_indexed_agg_distinct(JOIN *join, List< Item_field > *out_args)
Check for the presence of AGGFN(DISTINCT a) queries that may be subject to loose index scan...
Definition: sql_optimizer.cc:7627
bool should_send_current_row()
Returns whether one should send the current row on to the output, or ignore it.
Definition: sql_optimizer.h:896
JOIN(const JOIN &rhs)
not implemented
void adjust_access_methods()
An utility function - apply heuristics and optimize access methods to tables.
Definition: sql_optimizer.cc:2587
uint tables
Before plan has been created, "tables" denote number of input tables in the query block and "primary_...
Definition: sql_optimizer.h:343
bool group_sent
Exec time only: true <=> current group has been sent.
Definition: sql_optimizer.h:697
bool clear_fields(table_map *save_nullinfo)
Clear all result fields.
Definition: sql_executor.cc:8472
bool is_error() const
true if there is an error in the error stack.
Definition: sql_class.h:2820
ulonglong table_map
Definition: my_table_map.h:32
bool attach_join_condition_to_nest(plan_idx first_inner, plan_idx last_tab, Item *join_cond, bool is_sj_mat_cond)
Helper for JOIN::attach_join_conditions().
Definition: sql_optimizer.cc:8239
bool init_ref_access()
Initialize ref access for all tables that use it.
Definition: sql_select.cc:1825
void reset()
Reset the state of this join object so that it is ready for a new execution.
Definition: sql_select.cc:1553
Bounds_checked_array< Item * > Ref_item_array
Definition: item.h:81
T pointer_cast(void *p)
Casts from one pointer type, to another, without using reinterpret_cast or C-style cast: foo f; bar *...
Definition: template_utils.h:70
ORDER_with_src group_list
Definition: sql_optimizer.h:538
ROLLUP rollup
Used with rollup.
Definition: sql_optimizer.h:447
List< Item > & all_fields
List storing all expressions used in query block.
Definition: sql_optimizer.h:505
void create_iterators()
If possible, convert the executor structures to a set of row iterators, storing the result in m_root_...
Definition: sql_executor.cc:2593
bool has_lateral
If JOIN has lateral derived tables (is set at start of planning)
Definition: sql_optimizer.h:499
const JOIN *const m_join
Definition: sql_optimizer.h:1314
Item ** arg_value
Definition: sql_optimizer.h:82
ssize_t count
Definition: memcached.c:386
List< Item > & fields_list
List storing all expressions of select list.
Definition: sql_optimizer.h:508
bool update_equalities_for_sjm()
Update equalities and keyuse references after semi-join materialization strategy is chosen...
Definition: sql_optimizer.cc:4698
Order clause list element.
Definition: table.h:276
~Switch_ref_item_slice()
Definition: sql_optimizer.h:1164
Deps_of_remaining_lateral_derived_tables(JOIN *j, table_map plan_tables_arg)
Constructor.
Definition: sql_optimizer.h:1246
bool is_temporal_with_date() const
Definition: item.h:2408
void cleanup()
Cleanup this JOIN.
Definition: sql_select.cc:3279
File containing constants that can be used throughout the server.
ha_rows m_select_limit
Definition: sql_optimizer.h:389
List< Item > * get_current_fields()
Returns the clone of fields_list which is appropriate for evaluating expressions at the current stage...
Definition: sql_optimizer.cc:10860
TABLE_LIST * table_ref
points to table reference
Definition: sql_select.h:623
Plan has no tables.
Definition: sql_optimizer.h:857
Prepare_error_tracker(THD *thd_arg)
Definition: sql_optimizer.h:1173
bool prune_table_partitions()
Prune partitions for all tables of a join (query block).
Definition: sql_optimizer.cc:2455
enum_plan_state get_plan_state() const
See enum_plan_state.
Definition: sql_optimizer.h:861
A context for reading through a single table using a chosen access method: index read...
Definition: row_iterator.h:61
bool switch_slice_for_rollup_fields(List< Item > &all_fields, List< Item > &fields)
Switch the ref item slice for rollup structures which need to use fields from the first temp table to...
Definition: sql_select.cc:3959
Ref_item_array * ref_items
ref_items is an array of 5 slices, each containing an array of Item pointers.
Definition: sql_optimizer.h:645
Item_field * get_best_field(Item_field *item_field, COND_EQUAL *cond_equal)
Get the best field substitution for a given field.
Definition: sql_optimizer.cc:3357
table_map found_const_table_map
Const tables which are either:
Definition: sql_optimizer.h:375
The slice which is used during evaluation of expressions; Item_ref::ref points there.
Definition: sql_opt_exec_shared.h:597
ha_rows send_records
Definition: sql_optimizer.h:384
bool m_windows_sort
True if a window requires a certain order of rows, which implies that any order of rows coming out of...
Definition: sql_optimizer.h:549
bool finalize_table_conditions()
Remove redundant predicates and cache constant expressions.
Definition: sql_optimizer.cc:8684
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:971
Definition: field.h:700
enum_plan_state
State of execution plan. Currently used only for EXPLAIN.
Definition: sql_optimizer.h:854
void recalculate_deps_of_remaining_lateral_derived_tables(table_map plan_tables, uint idx)
Updates JOIN::deps_of_remaining_lateral_derived_tables.
Definition: sql_optimizer.cc:2925
JOIN_TAB * table
Definition: sql_select.h:430
bool optimize()
Optimizes one query block into a query execution plan (QEP.)
Definition: sql_optimizer.cc:200
bool m_windowing_steps
If we have set up tmp tables for windowing,.
Definition: sql_optimizer.h:552
const char * antijoin_null_cond
Definition: sql_optimizer.cc:100
enum_plan_state plan_state
Final execution plan state. Currently used only for EXPLAIN.
Definition: sql_optimizer.h:936
ha_rows fetch_limit
Used to fetch no more than given amount of rows per one fetch operation of server side cursor...
Definition: sql_optimizer.h:399
Bounds_checked_array< Item_null_result * > Item_null_array
Definition: sql_optimizer.h:71
List< Semijoin_mat_exec > sjm_exec_list
Definition: sql_optimizer.h:693
uint get_ref_item_slice() const
Definition: sql_optimizer.h:786
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:79
No plan is ready yet.
Definition: sql_optimizer.h:855
Definition: opt_explain_format.h:429
List< Cached_item > group_fields
Definition: sql_optimizer.h:433
uint current_ref_item_slice
The slice currently stored in ref_items[0].
Definition: sql_optimizer.h:658
uint saved
Definition: sql_optimizer.h:1157
Item_null_array null_items
Definition: sql_optimizer.h:89
bool select_distinct
At construction time, set if SELECT DISTINCT.
Definition: sql_optimizer.h:454
Item * make_cond_for_table(THD *thd, Item *cond, table_map tables, table_map used_table, bool exclude_expensive_cond)
Extract a condition that can be checked after reading given table.
Definition: sql_optimizer.cc:8989
bool init_planner_arrays()
Initialize scratch arrays for the join order optimization.
Definition: sql_optimizer.cc:5004
bool simple_order
Definition: sql_optimizer.h:472
uint recursive_iteration_count
Used only if this query block is recursive.
Definition: sql_optimizer.h:665
bool alloc_ref_item_slice(THD *thd_arg, int sliceno)
Allocate a ref_item slice, assume that slice size is in ref_items[0].
Definition: sql_optimizer.h:760
bool grouped
If query contains GROUP BY clause.
Definition: sql_optimizer.h:365
enum_exec_method
The method chosen to execute the predicate, currently used for IN, =ANY and EXISTS predicates...
Definition: item_subselect.h:345
Definition: opt_explain_format.h:426
bool is_optimized() const
Definition: sql_optimizer.h:862
void exec()
Execute select, executor entry point.
Definition: sql_executor.cc:219
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
JOIN_TAB ** best_ref
Array of plan operators representing the current (partial) best plan.
Definition: sql_optimizer.h:310
Next_select_func get_end_select_func()
Definition: sql_executor.cc:961
THD *const thd
Thread handler.
Definition: sql_optimizer.h:293
void mark_const_table(JOIN_TAB *table, Key_use *key)
Move const tables first in the position array.
Definition: sql_optimizer.cc:8069
void assert_unchanged()
Definition: sql_optimizer.h:1252
A Key_use represents an equality predicate of the form (table.column = val), where the column is inde...
Definition: sql_select.h:170
Definition: opt_explain_format.h:425
bool get_best_combination()
Set up JOIN_TAB structs according to the picked join order in best_positions.
Definition: sql_optimizer.cc:2705
bool executed
Set by exec(), reset by reset().
Definition: sql_optimizer.h:933
Key_use_array * create_keyuse_for_table(THD *thd, uint keyparts, Item_field **fields, List< Item > outer_exprs)
Create a keyuse array for a table with a primary key.
Definition: sql_optimizer.cc:8032
bool group_optimized_away
If we have the GROUP BY statement in the query, but the group_list was emptied by optimizer...
Definition: sql_optimizer.h:463
MYSQL_LOCK * lock
Definition: sql_optimizer.h:445
bool send_row_on_empty_set() const
Return whether the caller should send a row even if the join produced no rows if: ...
Definition: sql_optimizer.h:827
Definition: item_subselect.h:73
Definition: sql_optimizer.h:87
Definition: sql_optimizer.h:86
bool optimize_fts_query()
Function sets FT hints, initializes FT handlers and checks if FT index can be used as covered...
Definition: sql_optimizer.cc:10283
List< Item > * all_fields
Including hidden fields.
Definition: sql_optimizer.h:92
QEP_TAB ** map2qep_tab
mapping between table indexes and QEB_TABs
Definition: sql_optimizer.h:312
uint primary_tables
Number of primary input tables in query block.
Definition: sql_optimizer.h:344
Zero result cause is set.
Definition: sql_optimizer.h:856
table_map saved
Definition: sql_optimizer.h:1235
bool prepare_result()
Prepare join result.
Definition: sql_select.cc:1624
Common types of the Optimizer, used by optimization and execution.
Definition: table.h:1301
void restore_fields(table_map save_nullinfo)
Restore all result fields for all tables specified in save_nullinfo.
Definition: sql_executor.cc:8500
void set_plan_state(enum_plan_state plan_state_arg)
Sets the plan&#39;s state of the JOIN.
Definition: sql_optimizer.cc:1029
bool seen_first_record
Whether we&#39;ve seen at least one row already.
Definition: sql_optimizer.h:364
bool is_derived() const
Return true if this represents a derived table (an unnamed view)
Definition: table.h:2693
bool remove_eq_conds(THD *thd, Item *cond, Item **retcond, Item::cond_result *cond_value)
Removes const and eq items.
Definition: sql_optimizer.cc:9911
int flags
bitmap of Explain_sort_property
Definition: sql_optimizer.h:121
bool clear_corr_derived_tmp_tables()
Empties all correlated materialized derived tables.
Definition: sql_select.cc:1532
bool add_having_as_tmp_table_cond(uint curr_tmp_table)
Add having condition as a filter condition, which is applied when reading from the temp table...
Definition: sql_select.cc:4062
cond_result
Definition: item.h:737
Explain_sort_clause src
origin of order list
Definition: sql_optimizer.h:118
bool evaluate_during_optimization(const Item *item, const SELECT_LEX *select)
Checks if an Item, which is constant for execution, can be evaluated during optimization.
Definition: sql_optimizer.cc:10900
int8 plan_idx
This represents the index of a JOIN_TAB/QEP_TAB in an array.
Definition: sql_opt_exec_shared.h:39
ha_rows row_limit
Definition: sql_optimizer.h:387
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:179
bool build_equal_items(THD *thd, Item *cond, Item **retcond, COND_EQUAL *inherited, bool do_inherit, List< TABLE_LIST > *join_list, COND_EQUAL **cond_equal_ref)
Build multiple equalities for a WHERE condition and all join conditions that inherit these multiple e...
Definition: sql_optimizer.cc:4040
This file includes constants used by all storage engines.
void make_outerjoin_info()
Fill in outer join related info for the execution plan structure.
Definition: sql_optimizer.cc:8098
#define DBUG_ASSERT(A)
Definition: my_dbug.h:197
void init()
Definition: sql_optimizer.h:1275
bool optimized
flag to avoid double optimization in EXPLAIN
Definition: sql_optimizer.h:925
EXPLAIN FORMAT=<format> <command>.
void optimize_distinct()
Optimize distinct when used on a subset of the tables.
Definition: sql_executor.cc:553
bool field_time_cmp_date(const Field *f, const Item *v)
Returns true if arguments are a temporal Field having no date, part and a temporal expression having ...
Definition: sql_optimizer.h:1224
bool estimate_rowcount()
Estimate the number of matched rows for each joined table.
Definition: sql_optimizer.cc:5449
bool simple_group
Definition: sql_optimizer.h:472
void test_skip_sort()
Test if an index could be used to replace filesort for ORDER BY/GROUP BY.
Definition: sql_optimizer.cc:1389
Element_type * array() const
Definition: sql_array.h:105
void unplug_join_tabs()
Definition: sql_select.cc:4797
bool substitute_gc(THD *thd, SELECT_LEX *select_lex, Item *where_cond, ORDER *group_list, ORDER *order)
Substitute all expressions in the WHERE condition and ORDER/GROUP lists that match generated columns ...
Definition: sql_optimizer.cc:942
bool select_count
Definition: sql_optimizer.h:946
bool is_temporal_with_date() const
Definition: field.h:1275
ha_rows examined_rows
Definition: sql_optimizer.h:386
ORDER * operator->() const
Definition: sql_optimizer.h:163
void recalculate(JOIN_TAB *cur_tab, uint next_idx)
Definition: sql_optimizer.h:1266
void recalculate(uint next_idx)
Definition: sql_optimizer.h:1255
ORDER_with_src & operator=(null *)
Type-safe NULL assignment.
Definition: sql_optimizer.h:136
COND_EQUAL * cond_equal
Definition: sql_optimizer.h:601
bool attach_join_conditions(plan_idx last_tab)
Attach outer join conditions to generated table conditions in an optimal way.
Definition: sql_optimizer.cc:8350
unique_ptr_destroy_only< RowIterator > attach_iterators_for_having_and_limit(unique_ptr_destroy_only< RowIterator > iterator)
Definition: sql_executor.cc:3015
Class Item_sum is the base class used for special expressions that SQL calls &#39;set functions&#39;...
Definition: item_sum.h:385
table_map all_table_map
Set of tables contained in query.
Definition: sql_optimizer.h:367
void set_optimized()
Definition: sql_optimizer.h:863
bool rollup_make_fields(List< Item > &all_fields, List< Item > &fields, Item_sum ***func)
Fill up rollup structures with pointers to fields to use.
Definition: sql_select.cc:3817
void optimize_keyuse()
Update some values in keyuse for faster choose_table_order() loop.
Definition: sql_optimizer.cc:10243
void set_root_iterator(unique_ptr_destroy_only< RowIterator > iterator)
Definition: sql_optimizer.h:920
JOIN * join
Definition: sql_optimizer.h:1234
bool unlikely(bool expr)
Definition: my_compiler.h:65
Definition: opt_explain_format.h:446
unique_ptr_destroy_only< RowIterator > m_root_iterator
An iterator you can read from to get all records for this query.
Definition: sql_optimizer.h:1148
Classes for query execution.
ORDER_with_src(null *)
Type-safe constructor from NULL.
Definition: sql_optimizer.h:146
TABLE_LIST * tables_list
Pointer set to select_lex->get_table_list() at the start of optimization.
Definition: sql_optimizer.h:600
table_map m_lateral_deps
If &#39;this&#39; is body of lateral derived table: map of tables in the same FROM clause as this derived tab...
Definition: sql_lex.h:743
Header for compiler-dependent features.
bool decide_subquery_strategy()
Decides between EXISTS and materialization; performs last steps to set up the chosen strategy...
Definition: sql_optimizer.cc:10487
ORDER_with_src(ORDER *order_arg, Explain_sort_clause src_arg)
Definition: sql_optimizer.h:126
List< Cached_item > group_fields_cache
Definition: sql_optimizer.h:433
List< Item > * fields_list
SELECT list.
Definition: sql_optimizer.h:91
JOIN_TAB ** map2table
mapping between table indexes and JOIN_TABs
Definition: sql_optimizer.h:311
bool fts_index_access(JOIN_TAB *tab)
Check if FTS index only access is possible.
Definition: sql_optimizer.cc:10339
RowIterator * root_iterator() const
Definition: sql_optimizer.h:916
void update_depend_map()
Update the dependency map for the tables.
Definition: sql_optimizer.cc:4629
SELECT_LEX_UNIT * derived_unit() const
Return the query expression of a derived table or view.
Definition: table.h:2854
const Cost_model_server * cost_model() const
Retrieve the cost model object to be used for this join.
Definition: sql_optimizer.h:873
Definition: item.h:668
double calculate_subquery_executions(const Item_subselect *subquery, Opt_trace_context *trace)
Estimates how many times a subquery will be executed as part of a query execution.
Definition: sql_optimizer.cc:10659
unsigned int uint
Definition: uca-dump.cc:29
#define true
Definition: config_static.h:44
bool make_sum_func_list(List< Item > &all_fields, List< Item > &send_fields, bool before_group_by, bool recompute=false)
Initialize &#39;sum_funcs&#39; array with all Item_sum objects.
Definition: sql_select.cc:3705
table_map const_table_map
Set of tables found to be const.
Definition: sql_optimizer.h:368
const char * zero_result_cause
<> NULL if optimization has determined that execution will produce an empty result before aggregation...
Definition: sql_optimizer.h:675
bool uses_index_fields_only(Item *item, TABLE *tbl, uint keyno, bool other_tbls_ok)
Check if given expression only uses fields covered by index keyno in the table tbl.
Definition: sql_optimizer.cc:6021
ORDER * order
ORDER expression that we are wrapping with this class.
Definition: sql_optimizer.h:117
bool skip_sort_order
Is set if we have a GROUP BY and we have ORDER BY on a constant or when sorting isn&#39;t required...
Definition: sql_optimizer.h:489
bool make_join_plan()
Calculate best possible join order and initialize the join structure.
Definition: sql_optimizer.cc:4865
Definition: sql_optimizer.h:481
uint const_tables
Number of primary tables deemed constant.
Definition: sql_optimizer.h:345
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:554
SELECT_LEX_UNIT *const unit
Query expression referring this query block.
Definition: sql_optimizer.h:291
The slice with pointers to columns of table(s), ie., the actual Items.
Definition: sql_opt_exec_shared.h:659
Definition: sql_optimizer.h:87
void update_sargable_from_const(SARGABLE_PARAM *sargables)
Update info on indexes that can be used for search lookups as reading const tables may has added new ...
Definition: sql_optimizer.cc:5426
ORDER * next
Definition: table.h:277
bool plan_is_single_table()
True if plan contains one non-const primary table (ie not including tables taking part in semi-join m...
Definition: sql_optimizer.h:725
bool is_null() const
Definition: sql_array.h:97
Key_use_array keyuse_array
Used and updated by JOIN::make_join_plan() and optimize_keyuse()
Definition: sql_optimizer.h:502
uint sum_func_count
Number of fields in the query that have aggregate functions.
Definition: temp_table_param.h:124
Candidate_table_order(const JOIN *join)
Definition: sql_optimizer.h:1303
bool implicit_grouping
True if aggregated but no GROUP BY.
Definition: sql_optimizer.h:448
bool optimize_rollup()
Optimize rollup specification.
Definition: sql_optimizer.cc:10773
enum_nested_loop_state(* Next_select_func)(JOIN *, class QEP_TAB *, bool)
Definition: sql_executor.h:88
size_t element_size() const
Definition: sql_array.h:94
bool with_json_agg
This will force tmp table to NOT use index + update for group operation as it&#39;ll cause [de]serializat...
Definition: sql_optimizer.h:708
double sort_cost
Expected cost of filesort.
Definition: sql_optimizer.h:429
Plan is ready.
Definition: sql_optimizer.h:858
Definition: sql_optimizer.h:480
unique_ptr_destroy_only< RowIterator > create_root_iterator_for_join()
Definition: sql_executor.cc:2659
double best_read
The cost of best complete join plan found so far during optimization, after optimization phase - cost...
Definition: sql_optimizer.h:423
bool optimize_cond(THD *thd, Item **conds, COND_EQUAL **cond_equal, List< TABLE_LIST > *join_list, Item::cond_result *cond_value)
Optimize conditions by.
Definition: sql_optimizer.cc:9799
Definition: sql_executor.h:406
static const char * key
Definition: suite_stubs.c:14
ha_rows offset_limit_cnt
Definition: sql_lex.h:698
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:408
bool plan_is_const() const
True if plan is const, ie it will return zero or one rows.
Definition: sql_optimizer.h:719
static MEM_ROOT mem_root
Definition: client_plugin.cc:107
table_map plan_tables
All lateral tables not part of this map should be ignored.
Definition: sql_optimizer.h:1237
int n
Definition: xcom_base.c:425
LEX * lex
Definition: sql_class.h:838
void copy_ref_item_slice(uint dst_slice, uint src_slice)
Overwrites one slice of ref_items with the contents of another slice.
Definition: sql_optimizer.h:741
bool propagate_dependencies()
Propagate dependencies between tables due to outer join relations.
Definition: sql_optimizer.cc:5126
bool rollup_send_data(uint idx)
Send all rollup levels higher than the current one to the client.
Definition: sql_executor.cc:458
unique_ptr_destroy_only< RowIterator > release_root_iterator()
Definition: sql_optimizer.h:917
uint num_values
Definition: sql_optimizer.h:83
Item * where_cond
JOIN::having_cond is initially equal to select_lex->having_cond, but may later be changed by optimiza...
Definition: sql_optimizer.h:583
Item::cond_result having_value
Definition: sql_lex.h:1137
Field * field
Definition: sql_optimizer.h:81
SELECT_LEX *const select_lex
Query block that is optimized and executed using this JOIN.
Definition: sql_optimizer.h:289
A per-session context which is always available at any point of execution, because in practice it&#39;s ...
Definition: opt_trace_context.h:88
A position of table within a join order.
Definition: sql_select.h:345
void set(Explain_sort_clause clause, Explain_sort_property property)
Set property bit flag for the clause.
Definition: opt_explain_format.h:458
JOIN & operator=(const JOIN &rhs)
not implemented
Query optimization plan node.
Definition: sql_select.h:586
bool add_sorting_to_table(uint idx, ORDER_with_src *order, bool force_stable_sort=false)
Add Filesort object to the given table to sort if with filesort.
Definition: sql_select.cc:4837
void cleanup_item_list(List< Item > &items) const
Definition: sql_select.cc:1729
void init_key_dependencies()
Initialize key dependencies for join tables.
Definition: sql_optimizer.h:990
ORDER_with_src order
ORDER BY and GROUP BY lists, to transform with prepare,optimize and exec.
Definition: sql_optimizer.h:538
Wrapper for ORDER* pointer to trace origins of ORDER list.
Definition: sql_optimizer.h:102
int push_to_engines()
Handle offloading of query parts to the underlying engines, when such is supported by their implement...
Definition: sql_optimizer.cc:847
Definition: opt_explain_format.h:427
uint elements
Definition: sql_list.h:135
void copy_ref_item_slice(Ref_item_array dst_arr, Ref_item_array src_arr)
Definition: sql_optimizer.h:744
int get_flags() const
Definition: sql_optimizer.h:171
POSITION * positions
Definition: sql_optimizer.h:411
bool replaced_items_for_rollup
If set, "fields" has been replaced with a set of Item_refs for rollup processing; see the AggregateIt...
Definition: sql_optimizer.h:716
List< Item > * tmp_all_fields
This is similar to tmp_fields_list, but it also contains necessary extras: expressions added for ORDE...
Definition: sql_optimizer.h:515
ORDER * create_order_from_distinct(THD *thd, Ref_item_array ref_item_array, ORDER *order_list, List< Item > &fields, bool skip_aggregates, bool convert_bit_fields_to_long, bool *all_order_by_fields_used)
Create an order list that consists of all non-const fields and items.
Definition: sql_optimizer.cc:10140
Definition: item_cmpfunc.h:2440
Item_sum *** sum_funcs_end
Definition: sql_optimizer.h:434
enum_nested_loop_state sub_select(JOIN *join, QEP_TAB *const qep_tab, bool end_of_records)
Retrieve records ends with a given beginning from the result of a join.
Definition: sql_executor.cc:3423
bool do_send_rows
If true, send produced rows using query_result.
Definition: sql_optimizer.h:366
bool extract_const_tables()
Extract const tables based on row counts.
Definition: sql_optimizer.cc:5177
size_t size() const
Definition: sql_array.h:95
bool alloc_qep(uint n)
Definition: sql_optimizer.cc:1059
void set_executed()
Definition: sql_optimizer.h:865
uint tmp_tables
Number of temporary tables used by query.
Definition: sql_optimizer.h:346
void refine_best_rowcount()
Refine the best_rowcount estimation based on what happens after tables have been joined: LIMIT and ty...
Definition: sql_optimizer.cc:10835
int error
set in optimize(), exec(), prepare_result()
Definition: sql_optimizer.h:533
Definition: sql_optimizer.h:80
Ref_item_array * ref_item_arrays
Definition: sql_optimizer.h:90
#define HA_POS_ERROR
Definition: my_base.h:1132
bool create_intermediate_table(QEP_TAB *tab, List< Item > *tmp_table_fields, ORDER_with_src &tmp_table_group, bool save_sum_fields)
Create a temporary table to be used for processing DISTINCT/ORDER BY/GROUP BY.
Definition: sql_executor.cc:331
Definition: sql_optimizer.h:482
uint build_bitmap_for_nested_joins(List< TABLE_LIST > *join_list, uint first_unused)
Assign each nested join structure a bit in nested_join_map.
Definition: sql_optimizer.cc:4585
RAII class to manage JOIN::deps_of_remaining_lateral_derived_tables.
Definition: sql_optimizer.h:1233
T * first
The first element in the list.
Definition: sql_list.h:49
bool rollup_write_data(uint idx, QEP_TAB *qep_tab)
Write all rollup levels higher than the current one to a temp table.
Definition: sql_executor.cc:523
#define NULL
Definition: types.h:55
bool rollup_process_const_fields()
Wrap all constant Items in GROUP BY list.
Definition: sql_select.cc:3777
List< Item > * fields
Definition: sql_optimizer.h:432
int replace_index_subquery()
Check whether this is a subquery that can be evaluated by index look-ups.
Definition: sql_optimizer.cc:1138
uint send_group_parts
Definition: sql_optimizer.h:347
ORDER_with_src()
Definition: sql_optimizer.h:124
bool alloc_func_list()
Make an array of pointers to sum_functions to speed up sum_func calculation.
Definition: sql_select.cc:3655
Item * substitute_for_best_equal_field(THD *thd, Item *cond, COND_EQUAL *cond_equal, JOIN_TAB **table_join_idx)
Substitute every field reference in a condition by the best equal field and eliminate all multiple eq...
Definition: sql_optimizer.cc:4340
void join_free()
Release memory and, if possible, the open tables held by this execution plan (and nested plans)...
Definition: sql_select.cc:3219
bool is_executed() const
Definition: sql_optimizer.h:864
const Cost_model_server * cost_model() const
Retrieve the optimizer cost model for this connection.
Definition: sql_class.h:3903
table_map deps_of_remaining_lateral_derived_tables
Used in some loops which scan the JOIN&#39;s tables: it is the bitmap of all tables which are dependencie...
Definition: sql_optimizer.h:381
void * alloc(size_t size)
Definition: sql_class.h:301
bool destroy()
Clean up and destroy join object.
Definition: sql_select.cc:1665
bool child_subquery_can_materialize
True if, at this stage of processing, subquery materialization is allowed for children subqueries of ...
Definition: sql_optimizer.h:683
QEP_TAB * ref_slice_immediately_before_group_by
If slice REF_SLICE_ORDERED_GROUP_BY has been created, this is the QEP_TAB which is right before calcu...
Definition: sql_optimizer.h:651
bool compare_costs_of_subquery_strategies(Item_exists_subselect::enum_exec_method *method)
Tells what is the cheapest between IN->EXISTS and subquery materialization, in terms of cost...
Definition: sql_optimizer.cc:10548
List< Window > m_windows
Any window definitions.
Definition: sql_optimizer.h:543
JOIN * join
Definition: sql_optimizer.h:1156
bool is_temporal() const
Definition: field.h:1271
Definition: opt_explain_format.h:438
bool is_distinct() const
Definition: sql_lex.h:1419
bool calc_found_rows
If true, calculate found rows for this query block.
Definition: sql_optimizer.h:699
SQL_I_List< ORDER > order_list
ORDER BY clause.
Definition: sql_lex.h:1223
RAII class to ease the call of LEX::mark_broken() if error.
Definition: sql_optimizer.h:1171
Item * having_for_explain
Saved optimized HAVING for EXPLAIN.
Definition: sql_optimizer.h:594
~Deps_of_remaining_lateral_derived_tables()
Definition: sql_optimizer.h:1250
ORDER * remove_const(ORDER *first_order, Item *cond, bool change_list, bool *simple_order, bool group_by)
Remove all constants and check if ORDER only contains simple expressions.
Definition: sql_optimizer.cc:9646
bool need_tmp_before_win
If true we need a temporary table on the result set before any windowing steps, e.g.
Definition: sql_optimizer.h:496
Definition: opt_explain_format.h:424
void mark_broken(bool broken=true)
Certain permanent transformations (like in2exists), if they fail, may leave the LEX in an inconsisten...
Definition: sql_lex.h:3489
plan_idx return_tab
Definition: sql_optimizer.h:609
size_t size() const
Returns the number of tables in the candidate plan.
Definition: sql_optimizer.h:1306
POSITION * best_positions
This is the result of join optimization.
Definition: sql_optimizer.h:406
Explain_sort_clause
Enumeration of ORDER BY, GROUP BY and DISTINCT clauses for array indexing.
Definition: opt_explain_format.h:423
enum JOIN::@116 m_ordered_index_usage
Switch_ref_item_slice(JOIN *join_arg, uint new_v)
Definition: sql_optimizer.h:1160
State state
Definition: sql_optimizer.h:88
List< Item > * tmp_fields_list
Array of pointers to lists of expressions.
Definition: sql_optimizer.h:531
JOIN_TAB * join_tab
Optimal query execution plan.
Definition: sql_optimizer.h:300
Definition: table.h:2468
List< TABLE > sj_tmp_tables
Definition: sql_optimizer.h:692
ha_rows found_records
Definition: sql_optimizer.h:385
RAII class to ease the temporary switching to a different slice of the ref item array.
Definition: sql_optimizer.h:1155
void set_ref_item_slice(uint sliceno)
Overwrite the base slice of ref_items with the slice supplied as argument.
Definition: sql_optimizer.h:775
void clean()
Definition: sql_optimizer.h:165
Definition: lock.h:38
Temp_table_param tmp_table_param
Describes a temporary table.
Definition: sql_optimizer.h:444
QEP_TAB * qep_tab
Array of QEP_TABs.
Definition: sql_optimizer.h:302
bool generate_derived_keys()
Add keys to derived tables&#39;/views&#39; result tables in a list.
Definition: sql_optimizer.cc:8761
Explain_format_flags explain_flags
Buffer to gather GROUP BY, ORDER BY and DISTINCT QEP details for EXPLAIN.
Definition: sql_optimizer.h:557
Item_sum ** sum_funcs
Definition: sql_optimizer.h:434
double windowing_cost
Expected cost of windowing;.
Definition: sql_optimizer.h:431
void set_semijoin_info()
Set the first_sj_inner_tab and last_sj_inner_tab fields for all tables inside the semijoin nests of t...
Definition: sql_select.cc:1848
Item * having_cond
Optimized HAVING clause item tree (valid for one single execution).
Definition: sql_optimizer.h:593
#define false
Definition: config_static.h:43
~Prepare_error_tracker()
Definition: sql_optimizer.h:1174
Mem_root_array< Key_use > Key_use_array
Definition: sql_optimizer.h:76
bool optimize_distinct_group_order()
Optimize DISTINCT, GROUP BY, ORDER BY clauses.
Definition: sql_optimizer.cc:1203
Definition: sql_optimizer.h:87
API for getting cost estimates for server operations that are not directly related to a table object...
Definition: opt_costmodel.h:41
ha_rows best_rowcount
The estimated row count of the plan with best read time (see above).
Definition: sql_optimizer.h:427
my_off_t ha_rows
Definition: my_base.h:1130
bool alloc_indirection_slices()
Definition: sql_optimizer.cc:141
const TABLE_LIST * table_ref(size_t position) const
Returns the table reference at the given position in the candidate plan.
Definition: sql_optimizer.h:1309
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:70
Definition: items.h:34
bool streaming_aggregation
Indicates that the data will be aggregated (typically GROUP BY), and that it is already processed in ...
Definition: sql_optimizer.h:363
bool setup_semijoin_materialized_table(JOIN_TAB *tab, uint tableno, POSITION *inner_pos, POSITION *sjm_pos)
Setup the materialized table for a semi-join nest.
Definition: sql_select.cc:2598
TABLE * sort_by_table
Definition: sql_optimizer.h:318
void finalize_derived_keys()
For each materialized derived table/view, informs every TABLE of the key it will (not) use...
Definition: sql_optimizer.cc:8782
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:778
THD *const thd
Definition: sql_optimizer.h:1179
Private empty class to implement type-safe NULL assignment.
Definition: sql_optimizer.h:114