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