MySQL 9.5.0
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, 2025, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work 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 either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27/**
28 @file sql/sql_optimizer.h
29 Classes used for query optimizations.
30*/
31
32#include <sys/types.h>
33
34#include <cstring>
35#include <memory>
36#include <utility>
37
38#include "field_types.h"
39#include "my_alloc.h"
40#include "my_base.h"
41#include "my_dbug.h"
42#include "my_table_map.h"
43#include "sql/field.h"
44#include "sql/item.h"
46#include "sql/mem_root_array.h"
47#include "sql/opt_explain_format.h" // Explain_sort_clause
48#include "sql/sql_executor.h"
49#include "sql/sql_lex.h"
50#include "sql/sql_list.h"
52#include "sql/sql_select.h" // Key_use
53#include "sql/table.h"
55
56enum class Subquery_strategy : int;
57class Item_multi_eq;
58class Item_subselect;
59class Item_sum;
61class THD;
62class Window;
63struct AccessPath;
64struct COND_EQUAL;
65struct MYSQL_LOCK;
66
67template <class T>
68class mem_root_deque;
69
70// Key_use has a trivial destructor, no need to run it from Mem_root_array.
72
74
75/*
76 This structure is used to collect info on potentially sargable
77 predicates in order to check whether they become sargable after
78 reading const tables.
79 We form a bitmap of indexes that can be used for sargable predicates.
80 Only such indexes are involved in range analysis.
81*/
82
84 Field *field; /* field against which to check sargability */
85 Item **arg_value; /* values of potential keys for lookups */
86 uint num_values; /* number of values in the above array */
87};
88
89/**
90 Wrapper for ORDER* pointer to trace origins of ORDER list
91
92 As far as ORDER is just a head object of ORDER expression
93 chain, we need some wrapper object to associate flags with
94 the whole ORDER list.
95*/
97 public:
98 ORDER *order; ///< ORDER expression that we are wrapping with this class
99 Explain_sort_clause src; ///< origin of order list
100
101 private:
102 int flags; ///< bitmap of Explain_sort_property
103 // Status of const condition removal from the ORDER Expression
105
106 public:
108
110 bool const_optimized_arg = false)
111 : order(order_arg),
112 src(src_arg),
113 flags(order_arg ? ESP_EXISTS : ESP_none),
114 m_const_optimized(const_optimized_arg) {}
115
116 bool empty() const { return order == nullptr; }
117
118 void clean() {
119 order = nullptr;
120 src = ESC_none;
121 flags = ESP_none;
122 m_const_optimized = false;
123 }
124
125 int get_flags() const {
126 assert(order);
127 return flags;
128 }
129
130 bool is_const_optimized() const { return m_const_optimized; }
131};
132
133class JOIN {
134 public:
135 JOIN(THD *thd_arg, Query_block *select);
136 JOIN(const JOIN &rhs) = delete;
137 JOIN &operator=(const JOIN &rhs) = delete;
138
139 /// Query expression referring this query block
142 }
143
144 /// Query block that is optimized and executed using this JOIN
146 /// Thread handler
147 THD *const thd;
148
149 /**
150 Optimal query execution plan. Initialized with a tentative plan in
151 JOIN::make_join_plan() and later replaced with the optimal plan in
152 get_best_combination().
153 */
155 /// Array of QEP_TABs
156 QEP_TAB *qep_tab{nullptr};
157
158 /**
159 Array of plan operators representing the current (partial) best
160 plan. The array is allocated in JOIN::make_join_plan() and is valid only
161 inside this function. Initially (*best_ref[i]) == join_tab[i].
162 The optimizer reorders best_ref.
163 */
164 JOIN_TAB **best_ref{nullptr};
165 /// mapping between table indexes and JOIN_TABs
166 JOIN_TAB **map2table{nullptr};
167 /*
168 The table which has an index that allows to produce the required ordering.
169 A special value of 0x1 means that the ordering will be produced by
170 passing 1st non-const table to filesort(). NULL means no such table exists.
171 */
173
174 // Temporary tables that need to be cleaned up after the query.
175 // Only used for the hypergraph optimizer; the non-hypergraph optimizer
176 // uses QEP_TABs to hold the list of tables (including temporary tables).
179
180 // Allocated on the MEM_ROOT, but can hold some objects
181 // that allocate on the heap and thus need destruction.
183 };
186
187 // Similarly, filesorts that need to be cleaned up after the query.
188 // Only used for the hypergraph optimizer, for the same reason as above.
190
191 /**
192 Before plan has been created, "tables" denote number of input tables in the
193 query block and "primary_tables" is equal to "tables".
194 After plan has been created (after JOIN::get_best_combination()),
195 the JOIN_TAB objects are enumerated as follows:
196 - "tables" gives the total number of allocated JOIN_TAB objects
197 - "primary_tables" gives the number of input tables, including
198 materialized temporary tables from semi-join operation.
199 - "const_tables" are those tables among primary_tables that are detected
200 to be constant.
201 - "tmp_tables" is 0, 1 or 2 (more if windows) and counts the maximum
202 possible number of intermediate tables in post-processing (ie sorting and
203 duplicate removal).
204 Later, tmp_tables will be adjusted to the correct number of
205 intermediate tables, @see JOIN::make_tmp_tables_info.
206 - The remaining tables (ie. tables - primary_tables - tmp_tables) are
207 input tables to materialized semi-join operations.
208 The tables are ordered as follows in the join_tab array:
209 1. const primary table
210 2. non-const primary tables
211 3. intermediate sort/group tables
212 4. possible holes in array
213 5. semi-joined tables used with materialization strategy
214 */
215 uint tables{0}; ///< Total number of tables in query block
216 uint primary_tables{0}; ///< Number of primary input tables in query block
217 uint const_tables{0}; ///< Number of primary tables deemed constant
218 uint tmp_tables{0}; ///< Number of temporary tables used by query
220 /**
221 Indicates that the data will be aggregated (typically GROUP BY),
222 _and_ that it is already processed in an order that is compatible with
223 the grouping in use (e.g. because we are scanning along an index,
224 or because an earlier step sorted the data in a group-compatible order).
225
226 Note that this flag changes value at multiple points during optimization;
227 if it's set when a temporary table is created, this means we aggregate
228 into said temporary table (end_write_group is chosen instead of end_write),
229 but if it's set later, it means that we can aggregate as we go,
230 just before sending the data to the client (end_send_group is chosen
231 instead of end_send).
232
233 @see make_group_fields, alloc_group_fields, JOIN::exec
234 */
236 /// If query contains GROUP BY clause
238 /// Set of tables contained in query
240 table_map const_table_map; ///< Set of tables found to be const
241 /**
242 Const tables which are either:
243 - not empty
244 - empty but inner to a LEFT JOIN, thus "considered" not empty for the
245 rest of execution (a NULL-complemented row will be used).
246 */
248 /**
249 This is the bitmap of all tables which are dependencies of
250 lateral derived tables which are not (yet) part of the partial
251 plan. (The value is a logical 'or' of zero or more
252 Table_ref.map() values.)
253
254 When we are building the join order, there is a partial plan (an
255 ordered sequence of JOIN_TABs), and an unordered set of JOIN_TABs
256 not yet added to the plan. Due to backtracking, the partial plan
257 may both grow and shrink. When we add a new table to the plan, we
258 may wish to set up join buffering, so that rows from the preceding
259 table are buffered. If any of the remaining tables are derived
260 tables that depends on any of the predecessors of the table we
261 are adding (i.e. a lateral dependency), join buffering would be
262 inefficient. (@see setup_join_buffering() for a detailed
263 explanation of why this is so.)
264
265 For this reason we need to maintain this table_map of lateral
266 dependencies of tables not yet in the plan. Whenever we add a new
267 table to the plan, we update the map by calling
268 Optimize_table_order::recalculate_lateral_deps_incrementally().
269 And when we remove a table, we restore the previous map value
270 using a Tabel_map_restorer object.
271
272 As an example, assume that we join four tables, t1, t2, t3 and
273 d1, where d1 is a derived table that depends on t1:
274
275 SELECT * FROM t1 JOIN t2 ON t1.a=t2.b JOIN t3 ON t2.c=t3.d
276 JOIN LATERAL (SELECT DISTINCT e AS x FROM t4 WHERE t4.f=t1.c)
277 AS d1 ON t3.e=d1.x;
278
279 Now, if our partial plan is t1->t2, the map (of lateral
280 dependencies of the remaining tables) will contain t1.
281 This tells us that we should not use join buffering when joining t1
282 with t2. But if the partial plan is t1->d2->t2, the map will be
283 empty. We may thus use join buffering when joining d2 with t2.
284 */
286
287 /* Number of records produced after join + group operation */
292 // m_select_limit is used to decide if we are likely to scan the whole table.
294 /**
295 Used to fetch no more than given amount of rows per one
296 fetch operation of server side cursor.
297 The value is checked in end_send and end_send_group in fashion, similar
298 to offset_limit_cnt:
299 - fetch_limit= HA_POS_ERROR if there is no cursor.
300 - when we open a cursor, we set fetch_limit to 0,
301 - on each fetch iteration we add num_rows to fetch to fetch_limit
302 */
304
305 /**
306 This is the result of join optimization.
307
308 @note This is a scratch array, not used after get_best_combination().
309 */
311
312 /******* Join optimization state members start *******/
313
314 /* Current join optimization state */
316
317 /* We also maintain a stack of join optimization states in * join->positions[]
318 */
319 /******* Join optimization state members end *******/
320
321 /// A hook that secondary storage engines can use to override the executor
322 /// completely.
325
326 /**
327 The cost of best complete join plan found so far during optimization,
328 after optimization phase - cost of picked join order (not taking into
329 account the changes made by test_if_skip_sort_order(). Exception: Single
330 table query cost is updated after access change in
331 test_if_skip_sort_order()).
332 */
333 double best_read{0.0};
334 /**
335 The estimated row count of the plan with best read time (see above).
336 */
338 /// Expected cost of filesort.
339 double sort_cost{0.0};
340 /// Expected cost of windowing;
341 double windowing_cost{0.0};
345
346 // For destroying fields otherwise owned by RemoveDuplicatesIterator.
348
349 Item_sum **sum_funcs{nullptr};
350 /**
351 Describes a temporary table.
352 Each tmp table has its own tmp_table_param.
353 The one here is transiently used as a model by create_intermediate_table(),
354 to build the tmp table's own tmp_table_param.
355 */
358
359 enum class RollupState { NONE, INITED, READY };
361 bool implicit_grouping; ///< True if aggregated but no GROUP BY
362
363 /**
364 At construction time, set if SELECT DISTINCT. May be reset to false
365 later, when we set up a temporary table operation that deduplicates for us.
366 */
368
369 /**
370 If we have the GROUP BY statement in the query,
371 but the group_list was emptied by optimizer, this
372 flag is true.
373 It happens when fields in the GROUP BY are from
374 constant table
375 */
377
378 /*
379 simple_xxxxx is set if ORDER/GROUP BY doesn't include any references
380 to other tables than the first non-constant table in the JOIN.
381 It's also set if ORDER/GROUP BY is empty.
382 Used for deciding for or against using a temporary table to compute
383 GROUP/ORDER BY.
384 */
385 bool simple_order{false};
386 bool simple_group{false};
387
388 /*
389 m_ordered_index_usage is set if an ordered index access
390 should be used instead of a filesort when computing
391 ORDER/GROUP BY.
392 */
393 enum {
394 ORDERED_INDEX_VOID, // No ordered index avail.
395 ORDERED_INDEX_GROUP_BY, // Use index for GROUP BY
396 ORDERED_INDEX_ORDER_BY // Use index for ORDER BY
397 } m_ordered_index_usage{ORDERED_INDEX_VOID};
398
399 /**
400 Is set if we have a GROUP BY and we have ORDER BY on a constant or when
401 sorting isn't required.
402 */
403 bool skip_sort_order{false};
404
405 /**
406 If true we need a temporary table on the result set before any
407 windowing steps, e.g. for DISTINCT or we have a query ORDER BY.
408 See details in JOIN::optimize
409 */
411
412 /// If JOIN has lateral derived tables (is set at start of planning)
413 bool has_lateral{false};
414
415 /// Used and updated by JOIN::make_join_plan() and optimize_keyuse()
417
418 /**
419 Array of pointers to lists of expressions.
420 Each list represents the SELECT list at a certain stage of execution,
421 and also contains necessary extras: expressions added for ORDER BY,
422 GROUP BY, window clauses, underlying items of split items.
423 This array is only used when the query makes use of tmp tables: after
424 writing to tmp table (e.g. for GROUP BY), if this write also does a
425 function's calculation (e.g. of SUM), after the write the function's value
426 is in a column of the tmp table. If a SELECT list expression is the SUM,
427 and we now want to read that materialized SUM and send it forward, a new
428 expression (Item_field type instead of Item_sum), is needed. The new
429 expressions are listed in JOIN::tmp_fields_list[x]; 'x' is a number
430 (REF_SLICE_).
431 @see JOIN::make_tmp_tables_info()
432 */
434
435 int error{0}; ///< set in optimize(), exec(), prepare_result()
436
437 /**
438 Incremented each time clear_hash_tables() is run, signaling to
439 HashJoinIterators that they cannot keep their hash tables anymore
440 (since outer references may have changed).
441 */
443
444 /**
445 ORDER BY and GROUP BY lists, to transform with prepare,optimize and exec
446 */
448
449 // Used so that AggregateIterator knows which items to signal when the rollup
450 // level changes. Obviously only used in the presence of rollup.
455
456 /**
457 Any window definitions
458 */
460
461 /**
462 True if a window requires a certain order of rows, which implies that any
463 order of rows coming out of the pre-window join will be disturbed.
464 */
465 bool m_windows_sort{false};
466
467 /// If we have set up tmp tables for windowing, @see make_tmp_tables_info
468 bool m_windowing_steps{false};
469
470 /**
471 Buffer to gather GROUP BY, ORDER BY and DISTINCT QEP details for EXPLAIN
472 */
474
475 /**
476 JOIN::having_cond is initially equal to query_block->having_cond, but may
477 later be changed by optimizations performed by JOIN.
478 The relationship between the JOIN::having_cond condition and the
479 associated variable query_block->having_value is so that
480 having_value can be:
481 - COND_UNDEF if a having clause was not specified in the query or
482 if it has not been optimized yet
483 - COND_TRUE if the having clause is always true, in which case
484 JOIN::having_cond is set to NULL.
485 - COND_FALSE if the having clause is impossible, in which case
486 JOIN::having_cond is set to NULL
487 - COND_OK otherwise, meaning that the having clause needs to be
488 further evaluated
489 All of the above also applies to the where_cond/query_block->cond_value
490 pair.
491 */
492 /**
493 Optimized WHERE clause item tree (valid for one single execution).
494 Used in JOIN execution if no tables. Otherwise, attached in pieces to
495 JOIN_TABs and then not used in JOIN execution.
496 Printed by EXPLAIN EXTENDED.
497 Initialized by Query_block::get_optimizable_conditions().
498 */
500 /**
501 Optimized HAVING clause item tree (valid for one single execution).
502 Used in JOIN execution, as last "row filtering" step. With one exception:
503 may be pushed to the JOIN_TABs of temporary tables used in DISTINCT /
504 GROUP BY (see JOIN::make_tmp_tables_info()); in that case having_cond is
505 set to NULL, but is first saved to having_for_explain so that EXPLAIN
506 EXTENDED can still print it.
507 Initialized by Query_block::get_optimizable_conditions().
508 */
510 Item *having_for_explain; ///< Saved optimized HAVING for EXPLAIN
511 /**
512 Pointer set to query_block->get_table_list() at the start of
513 optimization. May be changed (to NULL) only if optimize_aggregated_query()
514 optimizes tables away.
515 */
518 /*
519 Join tab to return to. Points to an element of join->join_tab array, or to
520 join->join_tab[-1].
521 This is used at execution stage to shortcut join enumeration. Currently
522 shortcutting is done to handle outer joins or handle semi-joins with
523 FirstMatch strategy.
524 */
526
527 /**
528 ref_items is an array of 4+ slices, each containing an array of Item
529 pointers. ref_items is used in different phases of query execution.
530 - slice 0 is initially the same as Query_block::base_ref_items, ie it is
531 the set of items referencing fields from base tables. During optimization
532 and execution it may be temporarily overwritten by slice 1-3.
533 - slice 1 is a representation of the used items when being read from
534 the first temporary table.
535 - slice 2 is a representation of the used items when being read from
536 the second temporary table.
537 - slice 3 is a copy of the original slice 0. It is created if
538 slice overwriting is necessary, and it is used to restore
539 original values in slice 0 after having been overwritten.
540 - slices 4 -> N are used by windowing: all the window's out tmp tables,
541
542 Two windows: 4: window 1's out table
543 5: window 2's out table
544
545 and so on.
546
547 Slice 0 is allocated for the lifetime of a statement, whereas slices 1-3
548 are associated with a single optimization. The size of slice 0 determines
549 the slice size used when allocating the other slices.
550 */
552 nullptr}; // cardinality: REF_SLICE_SAVED_BASE + 1 + #windows*2
553
554 /**
555 The slice currently stored in ref_items[0].
556 Used to restore the base ref_items slice from the "save" slice after it
557 has been overwritten by another slice (1-3).
558 */
560
561 /**
562 Used only if this query block is recursive. Contains count of
563 all executions of this recursive query block, since the last
564 this->reset().
565 */
567
568 /**
569 <> NULL if optimization has determined that execution will produce an
570 empty result before aggregation, contains a textual explanation on why
571 result is empty. Implicitly grouped queries may still produce an
572 aggregation row.
573 @todo - suggest to set to "Preparation determined that query is empty"
574 when Query_block::is_empty_query() is true.
575 */
576 const char *zero_result_cause{nullptr};
577
578 /**
579 True if, at this stage of processing, subquery materialization is allowed
580 for children subqueries of this JOIN (those in the SELECT list, in WHERE,
581 etc). If false, and we have to evaluate a subquery at this stage, then we
582 must choose EXISTS.
583 */
585 /**
586 True if plan search is allowed to use references to expressions outer to
587 this JOIN (for example may set up a 'ref' access looking up an outer
588 expression in the index, etc).
589 */
590 bool allow_outer_refs{false};
591
592 /* Temporary tables used to weed-out semi-join duplicates */
595 /* end of allocation caching storage */
596
597 /** Exec time only: true <=> current group has been sent */
598 bool group_sent{false};
599 /// If true, calculate found rows for this query block
600 bool calc_found_rows{false};
601
602 /**
603 This will force tmp table to NOT use index + update for group
604 operation as it'll cause [de]serialization for each json aggregated
605 value and is very ineffective (times worse).
606 Server should use filesort, or tmp table + filesort to resolve GROUP BY
607 with JSON aggregate functions.
608 */
610
611 /// True if plan is const, ie it will return zero or one rows.
612 bool plan_is_const() const { return const_tables == primary_tables; }
613
614 /**
615 True if plan contains one non-const primary table (ie not including
616 tables taking part in semi-join materialization).
617 */
619
620 /**
621 Returns true if any of the items in JOIN::fields contains a call to the
622 full-text search function MATCH, which is not wrapped in an aggregation
623 function.
624 */
625 bool contains_non_aggregated_fts() const;
626
627 bool optimize(bool finalize_access_paths);
628 void reset();
629 bool prepare_result();
630 void destroy();
631 bool alloc_func_list();
633 bool before_group_by, bool recompute = false);
634
635 /**
636 Overwrites one slice of ref_items with the contents of another slice.
637 In the normal case, dst and src have the same size().
638 However: the rollup slices may have smaller size than slice_sz.
639 */
640 void copy_ref_item_slice(uint dst_slice, uint src_slice) {
641 copy_ref_item_slice(ref_items[dst_slice], ref_items[src_slice]);
642 }
644 assert(dst_arr.size() >= src_arr.size());
645 void *dest = dst_arr.array();
646 const void *src = src_arr.array();
647 if (!src_arr.is_null())
648 memcpy(dest, src, src_arr.size() * src_arr.element_size());
649 }
650
651 /**
652 Allocate a ref_item slice, assume that slice size is in ref_items[0]
653
654 @param thd_arg thread handler
655 @param sliceno The slice number to allocate in JOIN::ref_items
656
657 @returns false if success, true if error
658 */
659 bool alloc_ref_item_slice(THD *thd_arg, int sliceno);
660
661 /**
662 Overwrite the base slice of ref_items with the slice supplied as argument.
663
664 @param sliceno number to overwrite the base slice with, must be 1-4 or
665 4 + windowno.
666 */
667 void set_ref_item_slice(uint sliceno) {
668 assert((int)sliceno >= 1);
669 if (current_ref_item_slice != sliceno) {
671 DBUG_PRINT("info", ("JOIN %p ref slice %u -> %u", this,
672 current_ref_item_slice, sliceno));
673 current_ref_item_slice = sliceno;
674 }
675 }
676
677 /// @note do also consider Switch_ref_item_slice
679
680 /**
681 Returns the clone of fields_list which is appropriate for evaluating
682 expressions at the current stage of execution; which stage is denoted by
683 the value of current_ref_item_slice.
684 */
686
687 bool optimize_rollup();
689 /**
690 Release memory and, if possible, the open tables held by this execution
691 plan (and nested plans). It's used to release some tables before
692 the end of execution in order to increase concurrency and reduce
693 memory consumption.
694 */
695 void join_free();
696 /** Cleanup this JOIN. Not a full cleanup. reusable? */
697 void cleanup();
698
699 bool clear_fields(table_map *save_nullinfo);
700 void restore_fields(table_map save_nullinfo);
701
702 private:
703 /**
704 Return whether the caller should send a row even if the join
705 produced no rows if:
706 - the query is implicitly grouped
707 - OR if the query has ROLLUP and
708 - a possible HAVING clause evaluates to TRUE.
709
710 @note: if there is a having clause, it must be evaluated before
711 returning the row.
712 */
716 }
717
718 public:
722 bool attach_join_conditions(plan_idx last_tab);
723
724 private:
725 bool attach_join_condition_to_nest(plan_idx first_inner, plan_idx last_tab,
726 Item *join_cond, bool is_sj_mat_cond);
727
728 public:
731 bool sort_before_group);
735 table_map plan_tables, uint idx) const;
736 bool clear_sj_tmp_tables();
739
741 /// State of execution plan. Currently used only for EXPLAIN
743 NO_PLAN, ///< No plan is ready yet
744 ZERO_RESULT, ///< Zero result cause is set
745 NO_TABLES, ///< Plan has no tables
746 PLAN_READY ///< Plan is ready
747 };
748 /// See enum_plan_state
750 bool is_optimized() const { return optimized; }
751 void set_optimized() { optimized = true; }
752 bool is_executed() const { return executed; }
753 void set_executed() { executed = true; }
754
755 /**
756 Retrieve the cost model object to be used for this join.
757
758 @return Cost model object for the join
759 */
760
761 const Cost_model_server *cost_model() const;
762
763 /**
764 Check if FTS index only access is possible
765 */
766 bool fts_index_access(JOIN_TAB *tab);
767
769 /**
770 Propagate dependencies between tables due to outer join relations.
771
772 @returns false if success, true if error
773 */
775
776 /**
777 Handle offloading of query parts to the underlying engines, when
778 such is supported by their implementation.
779
780 @returns false if success, true if error
781 */
782 bool push_to_engines();
783
786
787 /**
788 If this query block was planned twice, once with and once without conditions
789 added by in2exists, changes the root access path to the one without
790 in2exists. If not (ie., there were never any such conditions in the first
791 place), does nothing.
792 */
794
795 /**
796 In the case of rollup (only): After the base slice list was made, we may
797 have modified the field list to add rollup group items and sum switchers,
798 but there may be Items with refs that refer to the base slice. This function
799 refreshes the base slice (and its copy, REF_SLICE_SAVED_BASE) with a fresh
800 copy of the list from “fields”.
801
802 When we get rid of slices entirely, we can get rid of this, too.
803 */
804 void refresh_base_slice();
805
806 /**
807 Similar to refresh_base_slice(), but refreshes only the specified slice.
808 */
809 void assign_fields_to_slice(int sliceno);
810
811 /**
812 Whether this query block needs finalization (see
813 FinalizePlanForQueryBlock()) before it can be actually used.
814 This only happens when using the hypergraph join optimizer.
815 */
816 bool needs_finalize{false};
817
818 private:
819 bool optimized{false}; ///< flag to avoid double optimization in EXPLAIN
820
821 /**
822 Set by exec(), reset by reset(). Note that this needs to be set
823 _during_ the query (not only when it's done executing), or the
824 dynamic range optimizer will not understand which tables have been
825 read.
826 */
827 bool executed{false};
828
829 /// Final execution plan state. Currently used only for EXPLAIN
831
832 public:
833 /*
834 When join->select_count is set, tables will not be optimized away.
835 The call to records() will be delayed until the execution phase and
836 the counting will be done on an index of Optimizer's choice.
837 The index will be decided in find_shortest_key(), called from
838 optimize_aggregated_query().
839 */
840 bool select_count{false};
841
842 private:
843 /**
844 Create a temporary table to be used for processing DISTINCT/ORDER
845 BY/GROUP BY.
846
847 @note Will modify JOIN object wrt sort/group attributes
848
849 @param tab the JOIN_TAB object to attach created table to
850 @param tmp_table_fields List of items that will be used to define
851 column types of the table.
852 @param tmp_table_group Group key to use for temporary table, empty if none.
853 @param save_sum_fields If true, do not replace Item_sum items in
854 @c tmp_fields list with Item_field items referring
855 to fields in temporary table.
856 @param alias alias name for temporary file
857 @returns false on success, true on failure
858 */
860 const mem_root_deque<Item *> &tmp_table_fields,
861 ORDER_with_src &tmp_table_group,
862 bool save_sum_fields,
863 const char *alias = nullptr);
864
865 /**
866 Optimize distinct when used on a subset of the tables.
867
868 E.g.,: SELECT DISTINCT t1.a FROM t1,t2 WHERE t1.b=t2.b
869 In this case we can stop scanning t2 when we have found one t1.a
870 */
871 void optimize_distinct();
872
873 /**
874 Function sets FT hints, initializes FT handlers and
875 checks if FT index can be used as covered.
876 */
877 bool optimize_fts_query();
878
879 /**
880 Checks if the chosen plan suffers from a problem related to full-text search
881 and streaming aggregation, which is likely to cause wrong results or make
882 the query misbehave in other ways, and raises an error if so. Only to be
883 called for queries with full-text search and GROUP BY WITH ROLLUP.
884
885 If there are calls to MATCH in the SELECT list (including the hidden
886 elements lifted there from other clauses), and they are not inside an
887 aggregate function, the results of the MATCH clause need to be materialized
888 before streaming aggregation is performed. The hypergraph optimizer adds a
889 materialization step before aggregation if needed (see
890 CreateStreamingAggregationPath()), but the old optimizer only does that for
891 implicitly grouped queries. For explicitly grouped queries, it instead
892 disables streaming aggregation for the queries that would need a
893 materialization step to work correctly (see JOIN::test_skip_sort()).
894
895 For explicitly grouped queries WITH ROLLUP, however, streaming aggregation
896 is currently the only alternative. In many cases it still works correctly
897 because an intermediate materialization step has been added for some other
898 reason, typically for a sort. For now, in those cases where a
899 materialization step has not been added, we raise an error instead of going
900 ahead with an invalid execution plan.
901
902 @return true if an error was raised.
903 */
904 bool check_access_path_with_fts() const;
905
907 /**
908 Initialize key dependencies for join tables.
909
910 TODO figure out necessity of this method. Current test
911 suite passed without this initialization.
912 */
914 JOIN_TAB *const tab_end = join_tab + tables;
915 for (JOIN_TAB *tab = join_tab; tab < tab_end; tab++)
916 tab->key_dependent = tab->dependent;
917 }
918
919 private:
920 void set_prefix_tables();
921 void cleanup_item_list(const mem_root_deque<Item *> &items) const;
923 bool make_join_plan();
924 bool init_planner_arrays();
928 bool estimate_rowcount();
929 void optimize_keyuse();
930 void set_semijoin_info();
931 /**
932 An utility function - apply heuristics and optimize access methods to tables.
933 @note Side effect - this function could set 'Impossible WHERE' zero
934 result.
935 */
937 void update_depend_map();
939 /**
940 Fill in outer join related info for the execution plan structure.
941
942 For each outer join operation left after simplification of the
943 original query the function set up the following pointers in the linear
944 structure join->join_tab representing the selected execution plan.
945 The first inner table t0 for the operation is set to refer to the last
946 inner table tk through the field t0->last_inner.
947 Any inner table ti for the operation are set to refer to the first
948 inner table ti->first_inner.
949 The first inner table t0 for the operation is set to refer to the
950 first inner table of the embedding outer join operation, if there is any,
951 through the field t0->first_upper.
952 The on expression for the outer join operation is attached to the
953 corresponding first inner table through the field t0->on_expr_ref.
954 Here ti are structures of the JOIN_TAB type.
955
956 EXAMPLE. For the query:
957 @code
958 SELECT * FROM t1
959 LEFT JOIN
960 (t2, t3 LEFT JOIN t4 ON t3.a=t4.a)
961 ON (t1.a=t2.a AND t1.b=t3.b)
962 WHERE t1.c > 5,
963 @endcode
964
965 given the execution plan with the table order t1,t2,t3,t4
966 is selected, the following references will be set;
967 t4->last_inner=[t4], t4->first_inner=[t4], t4->first_upper=[t2]
968 t2->last_inner=[t4], t2->first_inner=t3->first_inner=[t2],
969 on expression (t1.a=t2.a AND t1.b=t3.b) will be attached to
970 *t2->on_expr_ref, while t3.a=t4.a will be attached to *t4->on_expr_ref.
971
972 @note
973 The function assumes that the simplification procedure has been
974 already applied to the join query (see simplify_joins).
975 This function can be called only after the execution plan
976 has been chosen.
977 */
978 void make_outerjoin_info();
979
980 /**
981 Initialize ref access for all tables that use it.
982
983 @return False if success, True if error
984
985 @note We cannot setup fields used for ref access before we have sorted
986 the items within multiple equalities according to the final order of
987 the tables involved in the join operation. Currently, this occurs in
988 @see substitute_for_best_equal_field().
989 */
990 bool init_ref_access();
991 bool alloc_qep(uint n);
992 void unplug_join_tabs();
993 bool setup_semijoin_materialized_table(JOIN_TAB *tab, uint tableno,
994 POSITION *inner_pos,
995 POSITION *sjm_pos);
996
997 bool add_having_as_tmp_table_cond(uint curr_tmp_table);
999 void set_plan_state(enum_plan_state plan_state_arg);
1001 ORDER *remove_const(ORDER *first_order, Item *cond, bool change_list,
1002 bool *simple_order, bool group_by);
1003
1004 /**
1005 Check whether this is a subquery that can be evaluated by index look-ups.
1006 If so, change subquery engine to subselect_indexsubquery_engine.
1007
1008 @retval 1 engine was changed
1009 @retval 0 engine wasn't changed
1010 @retval -1 OOM or other error
1011 */
1013
1014 /**
1015 Optimize DISTINCT, GROUP BY, ORDER BY clauses
1016
1017 @retval false ok
1018 @retval true an error occurred
1019 */
1021
1022 /**
1023 Test if an index could be used to replace filesort for ORDER BY/GROUP BY
1024
1025 @details
1026 Investigate whether we may use an ordered index as part of either
1027 DISTINCT, GROUP BY or ORDER BY execution. An ordered index may be
1028 used for only the first of any of these terms to be executed. This
1029 is reflected in the order which we check for test_if_skip_sort_order()
1030 below. However we do not check for DISTINCT here, as it would have
1031 been transformed to a GROUP BY at this stage if it is a candidate for
1032 ordered index optimization.
1033 If a decision was made to use an ordered index, the availability
1034 if such an access path is stored in 'm_ordered_index_usage' for later
1035 use by 'execute' or 'explain'
1036 */
1037 void test_skip_sort();
1038
1040
1041 /**
1042 Convert the executor structures to a set of access paths, storing
1043 the result in m_root_access_path.
1044 */
1045 void create_access_paths();
1046
1047 public:
1048 /**
1049 Create access paths with the knowledge that there are going to be zero rows
1050 coming from tables (before aggregation); typically because we know that
1051 all of them would be filtered away by WHERE (e.g. SELECT * FROM t1
1052 WHERE 1=2). This will normally yield no output rows, but if we have implicit
1053 aggregation, it might yield a single one.
1054 */
1056
1057 private:
1059
1060 /** @{ Helpers for create_access_paths. */
1063 AccessPath *path) const;
1065 /** @} */
1066
1067 /**
1068 An access path you can read from to get all records for this query
1069 (after you create an iterator from it).
1070 */
1072
1073 /**
1074 If this query block contains conditions synthesized during IN-to-EXISTS
1075 conversion: A second query plan with all such conditions removed.
1076 See comments in JOIN::optimize().
1077 */
1079};
1080
1081/**
1082 Use this in a function which depends on best_ref listing tables in the
1083 final join order. If 'tables==0', one is not expected to consult best_ref
1084 cells, and best_ref may not even have been allocated.
1085*/
1086#define ASSERT_BEST_REF_IN_JOIN_ORDER(join) \
1087 do { \
1088 assert((join)->tables == 0 || ((join)->best_ref && !(join)->join_tab)); \
1089 } while (0)
1090
1091/**
1092 RAII class to ease the temporary switching to a different slice of
1093 the ref item array.
1094*/
1097 uint saved;
1098
1099 public:
1100 Switch_ref_item_slice(JOIN *join_arg, uint new_v)
1101 : join(join_arg), saved(join->get_ref_item_slice()) {
1102 if (!join->ref_items[new_v].is_null()) join->set_ref_item_slice(new_v);
1103 }
1105};
1106
1108 bool include_hidden, bool can_skip_aggs);
1109bool uses_index_fields_only(Item *item, TABLE *tbl, uint keyno,
1110 bool other_tbls_ok);
1111bool remove_eq_conds(THD *thd, Item *cond, Item **retcond,
1112 Item::cond_result *cond_value);
1113bool optimize_cond(THD *thd, Item **conds, COND_EQUAL **cond_equal,
1114 mem_root_deque<Table_ref *> *join_list,
1115 Item::cond_result *cond_value);
1117 COND_EQUAL *cond_equal,
1118 JOIN_TAB **table_join_idx);
1122 THD *thd, uint keyparts, Item_field **fields,
1123 const mem_root_deque<Item *> &outer_exprs);
1124Item_field *get_best_field(Item_field *item_field, COND_EQUAL *cond_equal);
1125Item *make_cond_for_table(THD *thd, Item *cond, table_map tables,
1126 table_map used_table, bool exclude_expensive_cond);
1128 uint first_unused);
1129
1130/**
1131 Create an order list that consists of all non-const fields and items.
1132 This is usable for e.g. converting DISTINCT into GROUP or ORDER BY.
1133 Is ref_item_array is non-null (is_null() returns false), the items
1134 will point into the slice given by it. Otherwise, it points directly
1135 into *fields (this is the only reason why fields is not const).
1136
1137 Try to put the items in "order_list" first, to allow one to optimize away
1138 a later ORDER BY.
1139 */
1141 ORDER *order_list,
1142 mem_root_deque<Item *> *fields,
1143 bool skip_aggregates,
1144 bool *all_order_by_fields_used);
1145
1146/**
1147 Returns true if arguments are a temporal Field having no date,
1148 part and a temporal expression having a date part.
1149 @param f Field
1150 @param v Expression
1151 */
1152inline bool field_time_cmp_date(const Field *f, const Item *v) {
1153 const enum_field_types ft = f->type();
1154 return is_temporal_type(ft) && !is_temporal_type_with_date(ft) &&
1156}
1157
1158bool substitute_gc(THD *thd, Query_block *query_block, Item *where_cond,
1159 ORDER *group_list, ORDER *order);
1160
1161/**
1162 This class restores a table_map object to its original value
1163 when '*this' is destroyed.
1164 */
1166 /** The location to be restored.*/
1168 /** The original value to restore.*/
1170
1171 public:
1172 /**
1173 Constructor.
1174 @param map The table map that we wish to restore.
1175 */
1178
1179 // This class is not intended to be copied.
1182
1185 void assert_unchanged() const { assert(*m_location == m_saved_value); }
1186};
1187
1188/**
1189 Estimates how many times a subquery will be executed as part of a
1190 query execution. If it is a cacheable subquery, the estimate tells
1191 how many times the subquery will be executed if it is not cached.
1192
1193 @param[in] subquery the Item that represents the subquery
1194 @param[in,out] trace optimizer trace context
1195
1196 @return the number of times the subquery is expected to be executed
1197*/
1198double calculate_subquery_executions(const Item_subselect *subquery,
1199 Opt_trace_context *trace);
1200
1201extern const char *antijoin_null_cond;
1202
1203/**
1204 Checks if an Item, which is constant for execution, can be evaluated during
1205 optimization. It cannot be evaluated if it contains a subquery and the
1206 OPTION_NO_SUBQUERY_DURING_OPTIMIZATION query option is active.
1207
1208 @param item the Item to check
1209 @param select the query block that contains the Item
1210 @return false if this Item contains a subquery and subqueries cannot be
1211 evaluated during optimization, or true otherwise
1212*/
1213bool evaluate_during_optimization(const Item *item, const Query_block *select);
1214
1215/**
1216 Find the multiple equality predicate containing a field.
1217
1218 The function retrieves the multiple equalities accessed through
1219 the cond_equal structure from current level and up looking for
1220 an equality containing a field. It stops retrieval as soon as the equality
1221 is found and set up inherited_fl to true if it's found on upper levels.
1222
1223 @param cond_equal multiple equalities to search in
1224 @param item_field field to look for
1225 @param[out] inherited_fl set up to true if multiple equality is found
1226 on upper levels (not on current level of
1227 cond_equal)
1228
1229 @return
1230 - Item_multi_eq for the found multiple equality predicate if a success;
1231 - nullptr otherwise.
1232*/
1234 const Item_field *item_field,
1235 bool *inherited_fl);
1236
1237/**
1238 Find an artificial cap for ref access. This is mostly a crutch to mitigate
1239 that we don't estimate the cache effects of ref accesses properly
1240 (ie., normally, if we do many, they will hit cache instead of being
1241 separate seeks). Given to find_cost_for_ref().
1242 */
1243double find_worst_seeks(const TABLE *table, double num_rows,
1244 double table_scan_cost);
1245
1246/**
1247 Whether a ref lookup of “right_item” on “field” will give an exact
1248 comparison in all cases, ie., one can remove any further checks on
1249 field = right_item. If not, there may be false positives, and one
1250 needs to keep the comparison after the ref lookup.
1251
1252 @param thd thread handler
1253 @param field field that is looked up through an index
1254 @param right_item value used to perform look up
1255 @param can_evaluate whether the function is allowed to evaluate right_item
1256 (if true, right_item must be const-for-execution)
1257 @param[out] subsumes true if an exact comparison can be done, false otherwise
1258
1259 @returns false if success, true if error
1260 */
1261bool ref_lookup_subsumes_comparison(THD *thd, Field *field, Item *right_item,
1262 bool can_evaluate, bool *subsumes);
1263
1264/**
1265 Checks if we need to create iterators for this query. We usually have to. The
1266 exception is if a secondary engine is used, and that engine will offload the
1267 query execution to an external executor using #JOIN::override_executor_func.
1268 In this case, the external executor will use its own execution structures and
1269 we don't need to bother with creating the iterators needed by the MySQL
1270 executor.
1271 */
1272bool IteratorsAreNeeded(const THD *thd, AccessPath *root_path);
1273
1274/**
1275 Estimates the number of base table row accesses that will be performed when
1276 executing a query using the given plan.
1277
1278 @param path The access path representing the plan.
1279 @param num_evaluations The number of times this path is expected to be
1280 evaluated during a single execution of the query.
1281 @param limit The maximum number of rows expected to be read from this path.
1282 @return An estimate of the number of row accesses.
1283 */
1284double EstimateRowAccesses(const AccessPath *path, double num_evaluations,
1285 double limit);
1286
1287/**
1288 Returns true if "item" can be used as a hash join condition between the tables
1289 given by "left_side" and "right_side". This is used to determine whether an
1290 equijoin condition needs to be attached as an "extra" condition.
1291
1292 It can be used as a hash join condition if the item on one side of the
1293 equality references some table in left_side and none in right_side, and the
1294 other side of the equality references some table in right_side and none in
1295 left_side.
1296
1297 @param item An equality that is a candidate for joining the left side tables
1298 with the right side tables.
1299 @param left_side The tables on the left side of the join.
1300 @param right_side The tables on the right side of the join.
1301
1302 @retval true If the equality can be used as a hash join condition.
1303 @retval false If the equality must be added as an extra condition to be
1304 evaluated after the join.
1305*/
1306bool IsHashEquijoinCondition(const Item_eq_base *item, table_map left_side,
1307 table_map right_side);
1308
1309/**
1310 Simply counts the ORDER elements.
1311*/
1312size_t CountOrderElements(const ORDER *order);
1313
1314#endif /* SQL_OPTIMIZER_INCLUDED */
bool is_null() const
Definition: sql_array.h:158
Element_type * array() const
Definition: sql_array.h:166
size_t size() const
Definition: sql_array.h:155
size_t element_size() const
Definition: sql_array.h:154
API for getting cost estimates for server operations that are not directly related to a table object.
Definition: opt_costmodel.h:54
Definition: opt_explain_format.h:451
Definition: field.h:570
virtual enum_field_types type() const =0
Base class for the equality comparison operators = and <=>.
Definition: item_cmpfunc.h:1045
Definition: item.h:4466
The class Item_multi_eq is used to represent conjunctions of equality predicates of the form field1 =...
Definition: item_cmpfunc.h:2702
Base class that is common to all subqueries and subquery predicates.
Definition: item_subselect.h:80
Class Item_sum is the base class used for special expressions that SQL calls 'set functions'.
Definition: item_sum.h:399
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:928
bool is_temporal_with_date() const
Definition: item.h:3372
cond_result
Definition: item.h:991
@ COND_FALSE
Definition: item.h:991
Query optimization plan node.
Definition: sql_select.h:602
Definition: sql_optimizer.h:133
const Cost_model_server * cost_model() const
Retrieve the cost model object to be used for this join.
Definition: sql_optimizer.cc:11468
bool skip_sort_order
Is set if we have a GROUP BY and we have ORDER BY on a constant or when sorting isn't required.
Definition: sql_optimizer.h:403
Table_ref * tables_list
Pointer set to query_block->get_table_list() at the start of optimization.
Definition: sql_optimizer.h:516
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:8739
void set_root_access_path(AccessPath *path)
Definition: sql_optimizer.h:785
bool calc_found_rows
If true, calculate found rows for this query block.
Definition: sql_optimizer.h:600
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:618
enum JOIN::@190 ORDERED_INDEX_VOID
void mark_const_table(JOIN_TAB *table, Key_use *key)
Move const tables first in the position array.
Definition: sql_optimizer.cc:8570
JOIN_TAB * join_tab
Optimal query execution plan.
Definition: sql_optimizer.h:154
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:303
Item_sum ** sum_funcs
Definition: sql_optimizer.h:349
List< Cached_item > group_fields
Definition: sql_optimizer.h:343
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:465
MYSQL_LOCK * lock
Definition: sql_optimizer.h:357
bool executed
Set by exec(), reset by reset().
Definition: sql_optimizer.h:827
QEP_TAB * qep_tab
Array of QEP_TABs.
Definition: sql_optimizer.h:156
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:713
ha_rows found_records
Definition: sql_optimizer.h:289
uint recursive_iteration_count
Used only if this query block is recursive.
Definition: sql_optimizer.h:566
void copy_ref_item_slice(Ref_item_array dst_arr, Ref_item_array src_arr)
Definition: sql_optimizer.h:643
bool child_subquery_can_materialize
True if, at this stage of processing, subquery materialization is allowed for children subqueries of ...
Definition: sql_optimizer.h:584
Prealloced_array< Item_rollup_group_item *, 4 > rollup_group_items
Definition: sql_optimizer.h:451
COND_EQUAL * cond_equal
Definition: sql_optimizer.h:517
JOIN_TAB ** map2table
mapping between table indexes and JOIN_TABs
Definition: sql_optimizer.h:166
ha_rows m_select_limit
Definition: sql_optimizer.h:293
POSITION * positions
Definition: sql_optimizer.h:315
uint current_ref_item_slice
The slice currently stored in ref_items[0].
Definition: sql_optimizer.h:559
bool is_executed() const
Definition: sql_optimizer.h:752
uint tables
Before plan has been created, "tables" denote number of input tables in the query block and "primary_...
Definition: sql_optimizer.h:215
bool has_lateral
If JOIN has lateral derived tables (is set at start of planning)
Definition: sql_optimizer.h:413
bool need_tmp_before_win
If true we need a temporary table on the result set before any windowing steps, e....
Definition: sql_optimizer.h:410
Prealloced_array< Item_rollup_sum_switcher *, 4 > rollup_sums
Definition: sql_optimizer.h:453
uint tmp_tables
Number of temporary tables used by query.
Definition: sql_optimizer.h:218
int error
set in optimize(), exec(), prepare_result()
Definition: sql_optimizer.h:435
bool plan_is_const() const
True if plan is const, ie it will return zero or one rows.
Definition: sql_optimizer.h:612
table_map const_table_map
Set of tables found to be const.
Definition: sql_optimizer.h:240
Prealloced_array< TemporaryTableToCleanup, 1 > temp_tables
Definition: sql_optimizer.h:184
Query_block *const query_block
Query block that is optimized and executed using this JOIN.
Definition: sql_optimizer.h:145
bool select_distinct
At construction time, set if SELECT DISTINCT.
Definition: sql_optimizer.h:367
RollupState
Definition: sql_optimizer.h:359
List< TABLE > sj_tmp_tables
Definition: sql_optimizer.h:593
table_map found_const_table_map
Const tables which are either:
Definition: sql_optimizer.h:247
bool simple_order
Definition: sql_optimizer.h:385
void set_executed()
Definition: sql_optimizer.h:753
List< Window > m_windows
Any window definitions.
Definition: sql_optimizer.h:459
Explain_format_flags explain_flags
Buffer to gather GROUP BY, ORDER BY and DISTINCT QEP details for EXPLAIN.
Definition: sql_optimizer.h:473
mem_root_deque< Item * > * tmp_fields
Array of pointers to lists of expressions.
Definition: sql_optimizer.h:433
uint const_tables
Number of primary tables deemed constant.
Definition: sql_optimizer.h:217
Prealloced_array< Filesort *, 1 > filesorts_to_cleanup
Definition: sql_optimizer.h:189
ha_rows examined_rows
Definition: sql_optimizer.h:290
ha_rows row_limit
Definition: sql_optimizer.h:291
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:590
JOIN_TAB ** best_ref
Array of plan operators representing the current (partial) best plan.
Definition: sql_optimizer.h:164
Item * having_for_explain
Saved optimized HAVING for EXPLAIN.
Definition: sql_optimizer.h:510
RollupState rollup_state
Definition: sql_optimizer.h:360
AccessPath * root_access_path() const
Definition: sql_optimizer.h:784
ha_rows send_records
Definition: sql_optimizer.h:288
Override_executor_func override_executor_func
Definition: sql_optimizer.h:324
plan_idx return_tab
Definition: sql_optimizer.h:525
enum_plan_state plan_state
Final execution plan state. Currently used only for EXPLAIN.
Definition: sql_optimizer.h:830
Item * having_cond
Optimized HAVING clause item tree (valid for one single execution).
Definition: sql_optimizer.h:509
void make_outerjoin_info()
Fill in outer join related info for the execution plan structure.
Definition: sql_optimizer.cc:8599
mem_root_deque< Item * > * fields
Definition: sql_optimizer.h:342
Temp_table_param tmp_table_param
Describes a temporary table.
Definition: sql_optimizer.h:356
bool select_count
Definition: sql_optimizer.h:840
bool m_windowing_steps
If we have set up tmp tables for windowing,.
Definition: sql_optimizer.h:468
bool finalize_table_conditions(THD *thd)
Remove redundant predicates and cache constant expressions.
Definition: sql_optimizer.cc:9258
bool fts_index_access(JOIN_TAB *tab)
Check if FTS index only access is possible.
Definition: sql_optimizer.cc:10975
void optimize_keyuse()
Update some values in keyuse for faster choose_table_order() loop.
Definition: sql_optimizer.cc:10877
bool with_json_agg
This will force tmp table to NOT use index + update for group operation as it'll cause [de]serializat...
Definition: sql_optimizer.h:609
uint send_group_parts
Definition: sql_optimizer.h:219
AccessPath * m_root_access_path_no_in2exists
If this query block contains conditions synthesized during IN-to-EXISTS conversion: A second query pl...
Definition: sql_optimizer.h:1078
@ ORDERED_INDEX_GROUP_BY
Definition: sql_optimizer.h:395
@ ORDERED_INDEX_VOID
Definition: sql_optimizer.h:394
@ ORDERED_INDEX_ORDER_BY
Definition: sql_optimizer.h:396
ORDER_with_src group_list
Definition: sql_optimizer.h:447
double sort_cost
Expected cost of filesort.
Definition: sql_optimizer.h:339
bool generate_derived_keys()
Add keys to derived tables'/views' result tables in a list.
Definition: sql_optimizer.cc:9337
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:10916
enum_plan_state
State of execution plan. Currently used only for EXPLAIN.
Definition: sql_optimizer.h:742
@ NO_TABLES
Plan has no tables.
Definition: sql_optimizer.h:745
@ NO_PLAN
No plan is ready yet.
Definition: sql_optimizer.h:743
@ ZERO_RESULT
Zero result cause is set.
Definition: sql_optimizer.h:744
@ PLAN_READY
Plan is ready.
Definition: sql_optimizer.h:746
Key_use_array keyuse_array
Used and updated by JOIN::make_join_plan() and optimize_keyuse()
Definition: sql_optimizer.h:416
bool group_sent
Exec time only: true <=> current group has been sent.
Definition: sql_optimizer.h:598
bool needs_finalize
Whether this query block needs finalization (see FinalizePlanForQueryBlock()) before it can be actual...
Definition: sql_optimizer.h:816
void init_key_dependencies()
Initialize key dependencies for join tables.
Definition: sql_optimizer.h:913
void set_ref_item_slice(uint sliceno)
Overwrite the base slice of ref_items with the slice supplied as argument.
Definition: sql_optimizer.h:667
List< Cached_item > group_fields_cache
Definition: sql_optimizer.h:344
bool contains_non_aggregated_fts() const
Returns true if any of the items in JOIN::fields contains a call to the full-text search function MAT...
Definition: sql_optimizer.cc:11009
bool streaming_aggregation
Indicates that the data will be aggregated (typically GROUP BY), and that it is already processed in ...
Definition: sql_optimizer.h:235
void set_optimized()
Definition: sql_optimizer.h:751
uint primary_tables
Number of primary input tables in query block.
Definition: sql_optimizer.h:216
bool optimize_rollup()
Optimize rollup specification.
Definition: sql_optimizer.cc:11425
THD *const thd
Thread handler.
Definition: sql_optimizer.h:147
table_map all_table_map
Set of tables contained in query.
Definition: sql_optimizer.h:239
bool attach_join_conditions(plan_idx last_tab)
Attach outer join conditions to generated table conditions in an optimal way.
Definition: sql_optimizer.cc:8850
bool decide_subquery_strategy()
Decides between EXISTS and materialization; performs last steps to set up the chosen strategy.
Definition: sql_optimizer.cc:11139
List< Semijoin_mat_exec > sjm_exec_list
Definition: sql_optimizer.h:594
JOIN(const JOIN &rhs)=delete
TABLE * sort_by_table
Definition: sql_optimizer.h:172
Ref_item_array * ref_items
ref_items is an array of 4+ slices, each containing an array of Item pointers.
Definition: sql_optimizer.h:551
double windowing_cost
Expected cost of windowing;.
Definition: sql_optimizer.h:341
enum_plan_state get_plan_state() const
See enum_plan_state.
Definition: sql_optimizer.h:749
JOIN & operator=(const JOIN &rhs)=delete
ORDER_with_src order
ORDER BY and GROUP BY lists, to transform with prepare,optimize and exec.
Definition: sql_optimizer.h:447
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:376
double best_read
The cost of best complete join plan found so far during optimization, after optimization phase - cost...
Definition: sql_optimizer.h:333
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:10268
bool implicit_grouping
True if aggregated but no GROUP BY.
Definition: sql_optimizer.h:361
POSITION * best_positions
This is the result of join optimization.
Definition: sql_optimizer.h:310
void finalize_derived_keys()
For each materialized derived table/view, informs every TABLE of the key it will (not) use,...
Definition: sql_optimizer.cc:9357
bool optimized
flag to avoid double optimization in EXPLAIN
Definition: sql_optimizer.h:819
bool compare_costs_of_subquery_strategies(Subquery_strategy *method)
Tells what is the cheapest between IN->EXISTS and subquery materialization, in terms of cost,...
Definition: sql_optimizer.cc:11200
bool is_optimized() const
Definition: sql_optimizer.h:750
const char * zero_result_cause
<> NULL if optimization has determined that execution will produce an empty result before aggregation...
Definition: sql_optimizer.h:576
Query_expression * query_expression() const
Query expression referring this query block.
Definition: sql_optimizer.h:140
mem_root_deque< Item * > * get_current_fields()
Returns the clone of fields_list which is appropriate for evaluating expressions at the current stage...
Definition: sql_optimizer.cc:11462
bool(*)(JOIN *, Query_result *) Override_executor_func
A hook that secondary storage engines can use to override the executor completely.
Definition: sql_optimizer.h:323
void clear_hash_tables()
Definition: sql_optimizer.h:738
uint get_ref_item_slice() const
Definition: sql_optimizer.h:678
List< Cached_item > semijoin_deduplication_fields
Definition: sql_optimizer.h:347
bool grouped
If query contains GROUP BY clause.
Definition: sql_optimizer.h:237
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:11436
AccessPath * m_root_access_path
An access path you can read from to get all records for this query (after you create an iterator from...
Definition: sql_optimizer.h:1071
ha_rows best_rowcount
The estimated row count of the plan with best read time (see above).
Definition: sql_optimizer.h:337
Item * where_cond
JOIN::having_cond is initially equal to query_block->having_cond, but may later be changed by optimiz...
Definition: sql_optimizer.h:499
bool simple_group
Definition: sql_optimizer.h:386
uint64_t hash_table_generation
Incremented each time clear_hash_tables() is run, signaling to HashJoinIterators that they cannot kee...
Definition: sql_optimizer.h:442
table_map deps_of_remaining_lateral_derived_tables
This is the bitmap of all tables which are dependencies of lateral derived tables which are not (yet)...
Definition: sql_optimizer.h:285
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:640
A Key_use represents an equality predicate of the form (table.column = val), where the column is inde...
Definition: sql_select.h:177
Definition: sql_list.h:494
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:432
Wrapper for ORDER* pointer to trace origins of ORDER list.
Definition: sql_optimizer.h:96
bool empty() const
Definition: sql_optimizer.h:116
bool is_const_optimized() const
Definition: sql_optimizer.h:130
ORDER_with_src(ORDER *order_arg, Explain_sort_clause src_arg, bool const_optimized_arg=false)
Definition: sql_optimizer.h:109
int get_flags() const
Definition: sql_optimizer.h:125
bool m_const_optimized
Definition: sql_optimizer.h:104
void clean()
Definition: sql_optimizer.h:118
ORDER * order
ORDER expression that we are wrapping with this class.
Definition: sql_optimizer.h:98
ORDER_with_src()
Definition: sql_optimizer.h:107
Explain_sort_clause src
origin of order list
Definition: sql_optimizer.h:99
int flags
bitmap of Explain_sort_property
Definition: sql_optimizer.h:102
A per-session context which is always available at any point of execution, because in practice it's a...
Definition: opt_trace_context.h:94
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:71
Definition: sql_executor.h:256
enum_op_type
Definition: sql_executor.h:403
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1179
Item::cond_result having_value
Definition: sql_lex.h:2116
Query_expression * master_query_expression() const
Definition: sql_lex.h:1290
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:643
Definition: query_result.h:60
RAII class to ease the temporary switching to a different slice of the ref item array.
Definition: sql_optimizer.h:1095
Switch_ref_item_slice(JOIN *join_arg, uint new_v)
Definition: sql_optimizer.h:1100
uint saved
Definition: sql_optimizer.h:1097
JOIN * join
Definition: sql_optimizer.h:1096
~Switch_ref_item_slice()
Definition: sql_optimizer.h:1104
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
This class restores a table_map object to its original value when '*this' is destroyed.
Definition: sql_optimizer.h:1165
Table_map_restorer(table_map *map)
Constructor.
Definition: sql_optimizer.h:1176
Table_map_restorer & operator=(const Table_map_restorer &)=delete
table_map *const m_location
The location to be restored.
Definition: sql_optimizer.h:1167
~Table_map_restorer()
Definition: sql_optimizer.h:1183
const table_map m_saved_value
The original value to restore.
Definition: sql_optimizer.h:1169
void restore()
Definition: sql_optimizer.h:1184
void assert_unchanged() const
Definition: sql_optimizer.h:1185
Table_map_restorer(const Table_map_restorer &)=delete
Definition: table.h:2933
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:97
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:110
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:111
bool is_temporal_type(enum_field_types type)
Tests if field type is temporal, i.e.
Definition: field_common_properties.h:115
bool is_temporal_type_with_date(enum_field_types type)
Tests if field type is temporal and has date part, i.e.
Definition: field_common_properties.h:156
This file contains the field type.
enum_field_types
Column types for MySQL Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:55
void optimize_distinct()
Optimize distinct when used on a subset of the tables.
Definition: sql_executor.cc:409
AccessPath * create_root_access_path_for_join()
Definition: sql_executor.cc:3155
AccessPath * attach_access_paths_for_having_qualify_limit(AccessPath *path) const
Definition: sql_executor.cc:3497
AccessPath * attach_access_path_for_update_or_delete(AccessPath *path) const
Definition: sql_executor.cc:3089
bool create_intermediate_table(QEP_TAB *tab, const mem_root_deque< Item * > &tmp_table_fields, ORDER_with_src &tmp_table_group, bool save_sum_fields, const char *alias=nullptr)
Create a temporary table to be used for processing DISTINCT/ORDER BY/GROUP BY.
Definition: sql_executor.cc:242
void restore_fields(table_map save_nullinfo)
Restore all result fields for all tables specified in save_nullinfo.
Definition: sql_executor.cc:4818
QEP_TAB::enum_op_type get_end_select_func()
Definition: sql_executor.cc:637
void create_access_paths()
Convert the executor structures to a set of access paths, storing the result in m_root_access_path.
Definition: sql_executor.cc:3126
void create_access_paths_for_index_subquery()
Definition: sql_executor.cc:3541
bool clear_fields(table_map *save_nullinfo)
Set all column values from all input tables to NULL.
Definition: sql_executor.cc:4795
bool clear_corr_derived_tmp_tables()
Empties all correlated materialized derived tables.
Definition: sql_select.cc:1909
bool alloc_func_list()
Make an array of pointers to sum_functions to speed up sum_func calculation.
Definition: sql_select.cc:4181
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:3777
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:5911
bool add_sorting_to_table(uint idx, ORDER_with_src *order, bool sort_before_group)
Add Filesort object to the given table to sort if with filesort.
Definition: sql_select.cc:5107
bool clear_sj_tmp_tables()
Remove all rows from all temp tables used by NL-semijoin runtime.
Definition: sql_select.cc:1899
bool alloc_qep(uint n)
Definition: sql_optimizer.cc:1332
void change_to_access_path_without_in2exists()
If this query block was planned twice, once with and once without conditions added by in2exists,...
Definition: sql_optimizer.cc:1131
void unplug_join_tabs()
Definition: sql_select.cc:5079
uint get_tmp_table_rec_length(const mem_root_deque< Item * > &items, bool include_hidden, bool can_skip_aggs)
Definition: sql_optimizer.cc:6336
bool push_to_engines()
Handle offloading of query parts to the underlying engines, when such is supported by their implement...
Definition: sql_optimizer.cc:1167
void assign_fields_to_slice(int sliceno)
Similar to refresh_base_slice(), but refreshes only the specified slice.
Definition: sql_select.cc:5067
bool make_tmp_tables_info()
Init tmp tables usage info.
Definition: sql_select.cc:4465
bool make_join_plan()
Calculate best possible join order and initialize the join structure.
Definition: sql_optimizer.cc:5352
void set_semijoin_embedding()
Set semi-join embedding join nest pointers.
Definition: sql_optimizer.cc:6084
bool optimize_distinct_group_order()
Optimize DISTINCT, GROUP BY, ORDER BY clauses.
Definition: sql_optimizer.cc:1479
JOIN(THD *thd_arg, Query_block *select)
Definition: sql_optimizer.cc:171
table_map calculate_deps_of_remaining_lateral_derived_tables(table_map plan_tables, uint idx) const
Finds the dependencies of the remaining lateral derived tables.
Definition: sql_optimizer.cc:3328
void set_prefix_tables()
Assign set of available (prefix) tables to all tables in query block.
Definition: sql_optimizer.cc:5245
void cleanup()
Cleanup this JOIN.
Definition: sql_select.cc:3824
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:6581
Item_multi_eq * find_item_equal(COND_EQUAL *cond_equal, const Item_field *item_field, bool *inherited_fl)
Find the multiple equality predicate containing a field.
Definition: sql_optimizer.cc:3743
void test_skip_sort()
Test if an index could be used to replace filesort for ORDER BY/GROUP BY.
Definition: sql_optimizer.cc:1665
bool propagate_dependencies()
Propagate dependencies between tables due to outer join relations.
Definition: sql_optimizer.cc:5601
void adjust_access_methods()
An utility function - apply heuristics and optimize access methods to tables.
Definition: sql_optimizer.cc:2977
bool estimate_rowcount()
Estimate the number of matched rows for each joined table.
Definition: sql_optimizer.cc:5949
bool prune_table_partitions()
Prune partitions for all tables of a join (query block).
Definition: sql_optimizer.cc:2826
uint build_bitmap_for_nested_joins(mem_root_deque< Table_ref * > *join_list, uint first_unused)
Assign each nested join structure a bit in nested_join_map.
Definition: sql_optimizer.cc:5070
void refresh_base_slice()
In the case of rollup (only): After the base slice list was made, we may have modified the field list...
Definition: sql_select.cc:5054
AccessPath * create_access_paths_for_zero_rows() const
Create access paths with the knowledge that there are going to be zero rows coming from tables (befor...
Definition: sql_optimizer.cc:1137
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.cc:211
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:3221
void join_free()
Release memory and, if possible, the open tables held by this execution plan (and nested plans).
Definition: sql_select.cc:3756
bool make_sum_func_list(const mem_root_deque< Item * > &fields, bool before_group_by, bool recompute=false)
Initialize 'sum_funcs' array with all Item_sum objects.
Definition: sql_select.cc:4229
bool extract_func_dependent_tables()
Extract const tables based on functional dependencies.
Definition: sql_optimizer.cc:5750
bool init_planner_arrays()
Initialize scratch arrays for the join order optimization.
Definition: sql_optimizer.cc:5482
bool substitute_gc(THD *thd, Query_block *query_block, 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:1213
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:2352
bool prepare_result()
Prepare join result.
Definition: sql_select.cc:1995
void destroy()
Clean up and destroy join object.
Definition: sql_select.cc:2013
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:4308
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:4817
double find_worst_seeks(const TABLE *table, double num_rows, double table_scan_cost)
Find an artificial cap for ref access.
Definition: sql_optimizer.cc:5927
const char * antijoin_null_cond
Definition: sql_optimizer.cc:128
bool alloc_indirection_slices()
Definition: sql_optimizer.cc:221
void reset()
Reset the state of this join object so that it is ready for a new execution.
Definition: sql_select.cc:1930
bool optimize(bool finalize_access_paths)
Optimizes one query block into a query execution plan (QEP.)
Definition: sql_optimizer.cc:344
bool init_ref_access()
Initialize ref access for all tables that use it.
Definition: sql_select.cc:2329
bool get_best_combination()
Set up JOIN_TAB structs according to the picked join order in best_positions.
Definition: sql_optimizer.cc:3097
bool extract_const_tables()
Extract const tables based on row counts.
Definition: sql_optimizer.cc:5652
bool update_equalities_for_sjm()
Update equalities and keyuse references after semi-join materialization strategy is chosen.
Definition: sql_optimizer.cc:5181
void set_plan_state(enum_plan_state plan_state_arg)
Sets the plan's state of the JOIN.
Definition: sql_optimizer.cc:1304
bool check_access_path_with_fts() const
Checks if the chosen plan suffers from a problem related to full-text search and streaming aggregatio...
Definition: sql_optimizer.cc:261
void cleanup_item_list(const mem_root_deque< Item * > &items) const
Definition: sql_select.cc:2111
int replace_index_subquery()
Check whether this is a subquery that can be evaluated by index look-ups.
Definition: sql_optimizer.cc:1412
void update_depend_map()
Update the dependency map for the tables.
Definition: sql_optimizer.cc:5112
Subquery_strategy
Classes that represent predicates over table subqueries: [NOT] EXISTS, [NOT] IN, ANY/SOME and ALL.
Definition: item_subselect.h:438
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
This file includes constants used by all storage engines.
my_off_t ha_rows
Definition: my_base.h:1217
#define HA_POS_ERROR
Definition: my_base.h:1219
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:181
uint64_t table_map
Definition: my_table_map.h:30
static char * path
Definition: mysqldump.cc:150
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
std::string join(const detail::range auto &rng, std::string_view delim)
join elements of a range into a string separated by a delimiter.
Definition: string.h:74
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2898
EXPLAIN FORMAT=<format> <command>.
Explain_sort_clause
Enumeration of ORDER BY, GROUP BY and DISTINCT clauses for array indexing.
Definition: opt_explain_format.h:428
@ ESC_none
Definition: opt_explain_format.h:429
@ ESP_EXISTS
Original query has this clause.
Definition: opt_explain_format.h:444
@ ESP_none
Definition: opt_explain_format.h:443
required string key
Definition: replication_asynchronous_connection_failover.proto:60
Classes for query execution.
Common types of the Optimizer, used by optimization and execution.
int plan_idx
This represents the index of a JOIN_TAB/QEP_TAB in an array.
Definition: sql_opt_exec_shared.h:54
@ REF_SLICE_ACTIVE
The slice which is used during evaluation of expressions; Item_ref::ref points there.
Definition: sql_opt_exec_shared.h:621
size_t CountOrderElements(const ORDER *order)
Simply counts the ORDER elements.
Definition: build_interesting_orders.cc:313
bool evaluate_during_optimization(const Item *item, const Query_block *select)
Checks if an Item, which is constant for execution, can be evaluated during optimization.
Definition: sql_optimizer.cc:11507
bool IsHashEquijoinCondition(const Item_eq_base *item, table_map left_side, table_map right_side)
Returns true if "item" can be used as a hash join condition between the tables given by "left_side" a...
Definition: sql_optimizer.cc:11824
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:9573
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:11310
Key_use_array * create_keyuse_for_table(THD *thd, uint keyparts, Item_field **fields, const mem_root_deque< Item * > &outer_exprs)
Create a keyuse array for a table with a primary key.
Definition: sql_optimizer.cc:8533
double EstimateRowAccesses(const AccessPath *path, double num_evaluations, double limit)
Estimates the number of base table row accesses that will be performed when executing a query using t...
Definition: sql_optimizer.cc:11664
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:1152
ORDER * create_order_from_distinct(THD *thd, Ref_item_array ref_item_array, ORDER *order_list, mem_root_deque< Item * > *fields, bool skip_aggregates, bool *all_order_by_fields_used)
Create an order list that consists of all non-const fields and items.
Definition: sql_optimizer.cc:10786
bool is_indexed_agg_distinct(JOIN *join, mem_root_deque< 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:8112
bool IteratorsAreNeeded(const THD *thd, AccessPath *root_path)
Checks if we need to create iterators for this query.
Definition: sql_optimizer.cc:11548
bool optimize_cond(THD *thd, Item **conds, COND_EQUAL **cond_equal, mem_root_deque< Table_ref * > *join_list, Item::cond_result *cond_value)
Optimize conditions by.
Definition: sql_optimizer.cc:10417
bool remove_eq_conds(THD *thd, Item *cond, Item **retcond, Item::cond_result *cond_value)
Removes const and eq items.
Definition: sql_optimizer.cc:10533
bool ref_lookup_subsumes_comparison(THD *thd, Field *field, Item *right_item, bool can_evaluate, bool *subsumes)
Whether a ref lookup of “right_item” on “field” will give an exact comparison in all cases,...
Definition: sql_optimizer.cc:8977
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:238
Definition: item_cmpfunc.h:2856
Definition: sql_optimizer.h:177
Temp_table_param * temp_table_param
Definition: sql_optimizer.h:182
TABLE * table
Definition: sql_optimizer.h:178
Definition: lock.h:39
Definition: table.h:298
A position of table within a join order.
Definition: sql_select.h:355
Definition: sql_optimizer.h:83
Item ** arg_value
Definition: sql_optimizer.h:85
Field * field
Definition: sql_optimizer.h:84
uint num_values
Definition: sql_optimizer.h:86
Definition: table.h:1435
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:44
int n
Definition: xcom_base.cc:509