MySQL 26.10.0
Source Code Documentation
access_path.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_JOIN_OPTIMIZER_ACCESS_PATH_H
25#define SQL_JOIN_OPTIMIZER_ACCESS_PATH_H
26
27#include <assert.h>
28#include <stdint.h>
29#include <cmath>
30#include <cstddef>
31#include <span>
32#include <type_traits>
33#include <utility>
34#include <vector>
35
36#include "my_alloc.h"
37#include "my_base.h"
38#include "my_table_map.h"
39#include "sql/item.h"
40// IWYU suggests removing row_iterator.h, but then the inlined short form of
41// CreateIteratorFromAccessPath() fails to compile. So use a pragma to keep it.
42#include "sql/iterators/row_iterator.h" // IWYU pragma: keep
47#include "sql/join_type.h"
48#include "sql/mem_root_array.h"
49#include "sql/olap.h"
50#include "sql/sql_class.h"
51#include "sql/table.h"
52
54class Filesort;
56class Item_func_match;
57class JOIN;
58class KEY;
60class QEP_TAB;
61class QUICK_RANGE;
62class SJ_TMP_TABLE;
63class Table_function;
65class Window;
66struct AccessPath;
69struct Index_lookup;
70struct KEY_PART;
71struct POSITION;
73
74/**
75 A specification that two specific relational expressions
76 (e.g., two tables, or a table and a join between two other tables)
77 should be joined together. The actual join conditions, if any,
78 live inside the “expr” object, as does the join type etc.
79 */
83
84 // If this join is made using a hash join, estimates the width
85 // of each row as stored in the hash table, in bytes.
87
88 // Cached result of EstimateHashJoinKeyWidth(expr). Populated after
89 // MakeJoinHypergraph() and InjectCastNodes() complete, used by
90 // ProposeHashJoin() during plan enumeration.
92
93 // The set of (additional) functional dependencies that are active
94 // after this join predicate has been applied. E.g. if we're joining
95 // on t1.x = t2.x, there will be a bit for that functional dependency.
96 // We don't currently support more complex join conditions, but there's
97 // no conceptual reason why we couldn't, e.g. a join on a = b + c
98 // could give rise to the FD {b, c} → a and possibly even {a, b} → c
99 // or {a, c} → b.
100 //
101 // Used in the processing of interesting orders.
103
104 // A less compact form of functional_dependencies, used during building
105 // (FunctionalDependencySet bitmaps are only available after all functional
106 // indexes have been collected and Build() has been called).
108
109 // A semijoin on the following format:
110 //
111 // SELECT ... FROM t1 WHERE EXISTS
112 // (SELECT ... FROM t2 WHERE t1.f1=t2.f2 AND t1.f3=t2.f4 ... t1.fn=t2.fm)
113 //
114 // may be transformed into an equivalent inner join:
115 //
116 // SELECT ... FROM (SELECT DISTINCT f2, f4...fm FROM t2) d JOIN t1
117 // ON t1.f1=d.f2 AND t1.f3=d.f4 ... t1.fn=d.fm
118 //
119 // If this is a suitable semijoin: This field will identify the the
120 // grouping given by (f2, f4..fm). (@see
121 // LogicalOrderings::RemapOrderingIndex() for a description of how this
122 // value can be mapped to an actual ordering). The join
123 // optimizer will then consider deduplicating on it and applying the
124 // above transform. If no such grouping was found, this field will be -1.
126
127 // Same as ordering_idx_needed_for_semijoin_rewrite, but given to the
128 // RemoveDuplicatesIterator for doing the actual grouping. Allocated
129 // on the MEM_ROOT. Can be empty, in which case a LIMIT 1 would do.
130 std::span<Item *> semijoin_group{};
131};
132
133/**
134 A filter of some sort that is not a join condition (those are stored
135 in JoinPredicate objects). AND conditions are typically split up into
136 multiple Predicates.
137 */
138struct Predicate {
140
141 // condition->used_tables(), converted to a NodeMap.
143
144 // tables referred to by the condition, plus any tables whose values
145 // can null any of those tables. (Even when reordering outer joins,
146 // at least one of those tables will still be present on the
147 // left-hand side of the outer join, so this is sufficient.)
148 //
149 // As a special case, we allow setting RAND_TABLE_BIT, even though it
150 // is normally part of a table_map, not a NodeMap.
152
154
155 // Whether this predicate is a join condition after all; it was promoted
156 // to a WHERE predicate since it was part of a cycle (see the comment in
157 // AddCycleEdges()). If it is, it is usually ignored so that we don't
158 // double-apply join conditions -- but if the join in question was not
159 // applied (because the cycle was broken at this point), the predicate
160 // would come into play. This is normally registered on the join itself
161 // (see RelationalExpression::join_predicate_bitmap), but having the bit
162 // on the predicate itself is used to avoid trying to push it down as a
163 // sargable predicate.
164 bool was_join_condition = false;
165
166 // Whether this predicate references tables that could be NULL-complemented
167 // later by an outer join. This could for example be true for degenerate outer
168 // join conditions that are pushed down as a table filter on one of the inner
169 // tables, or for join conditions in inner joins that are on the inner side of
170 // an outer join.
171 //
172 // We keep track of this here in order to prevent collection of functional
173 // dependencies from such predicates if the functional dependencies are not
174 // valid after the outer join.
176
177 // If this is a join condition that came from a multiple equality,
178 // and we have decided to create a mesh from that multiple equality,
179 // returns the index of it into the “multiple_equalities” array
180 // in MakeJoinHypergraph(). (You don't actually need the array to
181 // use this; it's just an opaque index to deduplicate between different
182 // predicates.) Otherwise, -1.
184
185 // See the equivalent fields in JoinPredicate.
188
189 // The list of all subqueries referred to in this predicate, if any.
190 // The optimizer uses this to add their materialized/non-materialized
191 // costs when evaluating filters.
193};
194
198};
199
200/// To indicate that a row estimate is not yet made.
201inline constexpr double kUnknownRowCount = -1.0;
202
203/// To indicate that a cost estimate is not yet made. We use a large negative
204/// value to avoid getting a positive result if we by mistake add this to
205/// a real (positive) cost.
206inline constexpr double kUnknownCost = -1e12;
207
208/// Calculate the cost of reading the first row from an access path, given
209/// estimates for init cost, total cost and the number of rows returned.
210inline double FirstRowCost(double init_cost, double total_cost,
211 double output_rows) {
212 assert(init_cost >= 0.0);
213 assert(total_cost >= init_cost);
214 assert(output_rows >= 0.0);
215 if (output_rows <= 1.0) {
216 return total_cost;
217 }
218 return init_cost + (total_cost - init_cost) / output_rows;
219}
220
221/**
222 Access paths are a query planning structure that correspond 1:1 to iterators,
223 in that an access path contains pretty much exactly the information
224 needed to instantiate given iterator, plus some information that is only
225 needed during planning, such as costs. (The new join optimizer will extend
226 this somewhat in the future. Some iterators also need the query block,
227 ie., JOIN object, they are part of, but that is implicitly available when
228 constructing the tree.)
229
230 AccessPath objects build on a variant, ie., they can hold an access path of
231 any type (table scan, filter, hash join, sort, etc.), although only one at the
232 same time. Currently, they contain 32 bytes of base information that is common
233 to any access path (type identifier, costs, etc.), and then up to 40 bytes
234 that is type-specific (e.g. for a table scan, the TABLE object). It would be
235 nice if we could squeeze it down to 64 and fit a cache line exactly, but it
236 does not seem to be easy without fairly large contortions.
237
238 We could have solved this by inheritance, but the fixed-size design makes it
239 possible to replace an access path when a better one is found, without
240 introducing a new allocation, which will be important when using them as a
241 planning structure.
242 */
244 enum Type : uint8_t {
245 // Basic access paths (those with no children, at least nominally).
246 // NOTE: When adding more paths to this section, also update GetBasicTable()
247 // to handle them.
267
268 // Basic access paths that don't correspond to a specific table.
275
276 // Joins.
281
282 // Composite access paths.
298
299 // Access paths that modify tables.
303
304 /// A general enum to describe the safety of a given operation.
305 /// Currently we only use this to describe row IDs, but it can easily
306 /// be reused for safety of updating a table we're reading from
307 /// (the Halloween problem), or just generally unreproducible results
308 /// (e.g. a TABLESAMPLE changing due to external factors).
309 ///
310 /// Less safe values have higher numerical values.
311 enum Safety : uint8_t {
312 /// The given operation is always safe on this access path.
313 SAFE = 0,
314
315 /// The given operation is safe if this access path is scanned once,
316 /// but not if it's scanned multiple times (e.g. used on the inner side
317 /// of a nested-loop join). A typical example of this is a derived table
318 /// or CTE that is rematerialized on each scan, so that references to
319 /// the old values (such as row IDs) are no longer valid.
321
322 /// The given operation is unsafe on this access path, no matter how many
323 /// or few times it's scanned. Often, it may help to materialize it
324 /// (assuming the materialization itself doesn't use the operation
325 /// in question).
326 UNSAFE = 2
327 };
328
329 /// Whether it is safe to get row IDs (for sorting) from this access path.
331
332 /// Whether this access path counts as one that scans a base table,
333 /// and thus should be counted towards examined_rows. It can sometimes
334 /// seem a bit arbitrary which iterators count towards examined_rows
335 /// and which ones do not, so the only canonical reference is the tests.
336 bool count_examined_rows : 1 {false};
337
338 /// Whether this access path contains a GROUP_INDEX_SKIP_SCAN
339 bool has_group_skip_scan : 1 {false};
340
341#ifndef NDEBUG
342 /// Whether this access path is forced preferred over all others by means
343 /// of a SET DEBUG force_subplan_0x... statement.
344 bool forced_by_dbug : 1 {false};
345#endif
346
347 /// For UPDATE and DELETE statements: The node index of a table which can be
348 /// updated or deleted from immediately as the rows are read from the
349 /// iterator, if this path is only read from once. -1 if there is no such
350 /// table in this path.
351 ///
352 /// Note that this is an index into CostingReceiver's array of nodes, and is
353 /// not necessarily equal to the table number within the query block given by
354 /// Table_ref::tableno().
355 ///
356 /// The table, if any, is currently always the outermost table in the path.
357 ///
358 /// It is possible to have plans where it would be safe to operate
359 /// "immediately" on more than one table. For example, if we do a merge join,
360 /// it is safe to perform immediate deletes on tables on the inner side of the
361 /// join, since both sides are read only once. (However, we currently do not
362 /// support merge joins.)
363 ///
364 /// Another possibility is when the outer table of a nested loop join is
365 /// guaranteed to return at most one row (typically, a unique index lookup
366 /// aka. eq_ref). Then it's safe to delete immediately from both sides of the
367 /// nested loop join. But we don't to this yet.
368 ///
369 /// Hash joins read both sides exactly once, However, with hash joins, the
370 /// scans on the inner tables are not positioned on the correct row when the
371 /// result of the join is returned, so the immediate delete logic will need to
372 /// be changed to reposition the underlying scans before doing the immediate
373 /// deletes. While this can be done, it makes the benefit of immediate deletes
374 /// less obvious for these tables, and it can also be a loss in some cases,
375 /// because we lose the deduplication provided by the Unique object used for
376 /// buffered deletes (the immediate deletes could end up spending time
377 /// repositioning to already deleted rows). So we currently don't attempt to
378 /// do immediate deletes from inner tables of hash joins either.
379 ///
380 /// The outer table of a hash join can be deleted from immediately if the
381 /// inner table fits in memory. If the hash join spills to disk, though,
382 /// neither the rows of the outer table nor the rows of the inner table come
383 /// out in the order of the underlying scan, so it is not safe in general to
384 /// perform immediate deletes on the outer table of a hash join.
385 ///
386 /// If support for immediate operations on multiple tables is added,
387 /// this member could be changed from a node index to a NodeMap.
389
390 /// Which ordering the rows produced by this path follow, if any
391 /// (see interesting_orders.h). This is really a LogicalOrderings::StateIndex,
392 /// but we don't want to add a dependency on interesting_orders.h from
393 /// this file, so we use the base type instead of the typedef here.
395
396 /// If an iterator has been instantiated for this access path, points to the
397 /// iterator. Used for constructing iterators that need to talk to each other
398 /// (e.g. for recursive CTEs, or BKA join), and also for locating timing
399 /// information in EXPLAIN ANALYZE queries.
401
402 double cost() const { return m_cost; }
403
404 double init_cost() const { return m_init_cost; }
405
406 /// The cost of reading the first row.
407 double first_row_cost() const {
409 }
410
411 double init_once_cost() const { return m_init_once_cost; }
412
413 double cost_before_filter() const { return m_cost_before_filter; }
414
415 void set_cost(double val) {
416 assert(std::isfinite(val));
417 assert(val >= 0.0 || val == kUnknownCost);
418 m_cost = val;
419 }
420
421 void set_init_cost(double val) {
422 assert(std::isfinite(val));
423 assert(val >= 0.0 || val == kUnknownCost);
424 m_init_cost = val;
425 }
426
427 void set_init_once_cost(double val) {
428 assert(std::isfinite(val));
429 assert(val >= 0.0);
430 m_init_once_cost = val;
431 }
432
433 void set_cost_before_filter(double val) {
434 assert(std::isfinite(val));
435 assert(val >= 0.0 || val == kUnknownCost);
437 }
438
439 /// Return the cost of scanning the given path for the second time
440 /// (or later) in the given query block. This is really the interesting
441 /// metric, not init_once_cost in itself, but since nearly all paths
442 /// have zero init_once_cost, storing that instead allows us to skip
443 /// a lot of repeated path->init_once_cost = path->init_cost calls
444 /// in the code.
445 double rescan_cost() const { return cost() - init_once_cost(); }
446
447 /// Return true if costs and row counts are consistent.
448 bool HasConsistentCostsAndRows(const JoinHypergraph &graph) const;
449
450 /// If no filter, identical to num_output_rows.
452
453 /// Bitmap of WHERE predicates that we are including on this access path,
454 /// referring to the “predicates” array internal to the join optimizer.
455 /// Since bit masks are much cheaper to deal with than creating Item
456 /// objects, and we don't invent new conditions during join optimization
457 /// (all of them are known when we begin optimization), we stick to
458 /// manipulating bit masks during optimization, saying which filters will be
459 /// applied at this node (a 1-bit means the filter will be applied here; if
460 /// there are multiple ones, they are ANDed together).
461 ///
462 /// This is used during join optimization only; before iterators are
463 /// created, we will add FILTER access paths to represent these instead,
464 /// removing the dependency on the array. Said FILTER paths are by
465 /// convention created with materialize_subqueries = false, since the by far
466 /// most common case is that there are no subqueries in the predicate.
467 /// In other words, if you wish to represent a filter with
468 /// materialize_subqueries = true, you will need to make an explicit FILTER
469 /// node.
470 ///
471 /// See also nested_loop_join().equijoin_predicates, which is for filters
472 /// being applied _before_ nested-loop joins, but is otherwise the same idea.
473 ///
474 /// Note that the higher bits of this bitset, those starting at the position
475 /// given by JoinHypergraph::num_filter_predicates, do not represent filter
476 /// predicates, but rather applied sargable join predicates. @see
477 /// #applied_sargable_join_predicates() for more details.
479
480 /// Bitmap of sargable join predicates that have already been applied
481 /// in this access path by means of an index lookup (ref access),
482 /// again referring to “predicates”, and thus should not be counted again
483 /// for selectivity. Note that the filter may need to be applied
484 /// nevertheless (especially in case of type conversions); see
485 /// subsumed_sargable_join_predicates.
486 ///
487 /// Since these refer to the same array as filter_predicates, they will
488 /// never overlap with filter_predicates, and so we can reuse the same
489 /// memory using an alias (a union would not be allowed, since OverflowBitset
490 /// is a class with non-trivial default constructor), even though the meaning
491 /// is entirely separate. If N = num_filter_predicates in the hypergraph, then
492 /// bits 0..(N-1) belong to filter_predicates, and the rest to
493 /// applied_sargable_join_predicates.
495 return filter_predicates;
496 }
498 return filter_predicates;
499 }
500
501 /// Bitmap of WHERE predicates that touch tables we have joined in,
502 /// but that we could not apply yet (for instance because they reference
503 /// other tables, or because because we could not push them down into
504 /// the nullable side of outer joins). Used during planning only
505 /// (see filter_predicates).
506 ///
507 /// Note that the higher bits of this bitset, those starting at the position
508 /// given by JoinHypergraph::num_filter_predicates, do not represent delayed
509 /// predicates, but rather subsumed sargable join predicates. @see
510 /// #subsumed_sargable_join_predicates() for more details.
512
513 /// Similar to applied_sargable_join_predicates, bitmap of sargable
514 /// join predicates that have been applied and will subsume the join
515 /// predicate entirely, ie., not only should the selectivity not be
516 /// double-counted, but the predicate itself is redundant and need not
517 /// be applied as a filter. (It is an error to have a bit set here but not
518 /// in applied_sargable_join_predicates.)
520 return delayed_predicates;
521 }
523 return delayed_predicates;
524 }
525
526 /// If nonzero, a bitmap of other tables whose joined-in rows must already be
527 /// loaded when rows from this access path are evaluated; that is, this
528 /// access path must be put on the inner side of a nested-loop join (or
529 /// multiple such joins) where the outer side includes all of the given
530 /// tables.
531 ///
532 /// The most obvious case for this is dependent tables in LATERAL, but a more
533 /// common case is when we have pushed join conditions referring to those
534 /// tables; e.g., if this access path represents t1 and we have a condition
535 /// t1.x=t2.x that is pushed down into an index lookup (ref access), t2 will
536 /// be set in this bitmap. We can still join in other tables, deferring t2,
537 /// but the bit(s) will then propagate, and we cannot be on the right side of
538 /// a hash join until parameter_tables is zero again. (Also see
539 /// DisallowParameterizedJoinPath() for when we disallow such deferring,
540 /// as an optimization.)
541 ///
542 /// As a special case, we allow setting RAND_TABLE_BIT, even though it
543 /// is normally part of a table_map, not a NodeMap. In this case, it specifies
544 /// that the access path is entirely noncachable, because it depends on
545 /// something nondeterministic or an outer reference, and thus can never be on
546 /// the right side of a hash join, ever.
548
549 /// Auxiliary data used by a secondary storage engine while processing the
550 /// access path during optimization and execution. The secondary storage
551 /// engine is free to store any useful information in this member, for example
552 /// extra statistics or cost estimates. The data pointed to is fully owned by
553 /// the secondary storage engine, and it is the responsibility of the
554 /// secondary engine to manage the memory and make sure it is properly
555 /// destroyed.
556 void *secondary_engine_data{nullptr};
557
558 /// Signature used to uniquely identify the access path.
559 /// 0 meaning non-initialized.
560 size_t signature{0};
561
562 // Accessors for the union below.
563 auto &table_scan() {
564 assert(type == TABLE_SCAN);
565 return u.table_scan;
566 }
567 const auto &table_scan() const {
568 assert(type == TABLE_SCAN);
569 return u.table_scan;
570 }
571 auto &sample_scan() {
572 assert(type == SAMPLE_SCAN);
573 return u.sample_scan;
574 }
575 const auto &sample_scan() const {
576 assert(type == SAMPLE_SCAN);
577 return u.sample_scan;
578 }
579 auto &index_scan() {
580 assert(type == INDEX_SCAN);
581 return u.index_scan;
582 }
583 const auto &index_scan() const {
584 assert(type == INDEX_SCAN);
585 return u.index_scan;
586 }
588 assert(type == INDEX_DISTANCE_SCAN);
589 return u.index_distance_scan;
590 }
591 const auto &index_distance_scan() const {
592 assert(type == INDEX_DISTANCE_SCAN);
593 return u.index_distance_scan;
594 }
595 auto &ref() {
596 assert(type == REF);
597 return u.ref;
598 }
599 const auto &ref() const {
600 assert(type == REF);
601 return u.ref;
602 }
603 auto &ref_or_null() {
604 assert(type == REF_OR_NULL);
605 return u.ref_or_null;
606 }
607 const auto &ref_or_null() const {
608 assert(type == REF_OR_NULL);
609 return u.ref_or_null;
610 }
611 auto &eq_ref() {
612 assert(type == EQ_REF);
613 return u.eq_ref;
614 }
615 const auto &eq_ref() const {
616 assert(type == EQ_REF);
617 return u.eq_ref;
618 }
620 assert(type == PUSHED_JOIN_REF);
621 return u.pushed_join_ref;
622 }
623 const auto &pushed_join_ref() const {
624 assert(type == PUSHED_JOIN_REF);
625 return u.pushed_join_ref;
626 }
628 assert(type == FULL_TEXT_SEARCH);
629 return u.full_text_search;
630 }
631 const auto &full_text_search() const {
632 assert(type == FULL_TEXT_SEARCH);
633 return u.full_text_search;
634 }
635 auto &const_table() {
636 assert(type == CONST_TABLE);
637 return u.const_table;
638 }
639 const auto &const_table() const {
640 assert(type == CONST_TABLE);
641 return u.const_table;
642 }
643 auto &mrr() {
644 assert(type == MRR);
645 return u.mrr;
646 }
647 const auto &mrr() const {
648 assert(type == MRR);
649 return u.mrr;
650 }
651 auto &follow_tail() {
652 assert(type == FOLLOW_TAIL);
653 return u.follow_tail;
654 }
655 const auto &follow_tail() const {
656 assert(type == FOLLOW_TAIL);
657 return u.follow_tail;
658 }
660 assert(type == INDEX_RANGE_SCAN);
661 return u.index_range_scan;
662 }
663 const auto &index_range_scan() const {
664 assert(type == INDEX_RANGE_SCAN);
665 return u.index_range_scan;
666 }
667 auto &index_merge() {
668 assert(type == INDEX_MERGE);
669 return u.index_merge;
670 }
671 const auto &index_merge() const {
672 assert(type == INDEX_MERGE);
673 return u.index_merge;
674 }
676 assert(type == ROWID_INTERSECTION);
677 return u.rowid_intersection;
678 }
679 const auto &rowid_intersection() const {
680 assert(type == ROWID_INTERSECTION);
681 return u.rowid_intersection;
682 }
683 auto &rowid_union() {
684 assert(type == ROWID_UNION);
685 return u.rowid_union;
686 }
687 const auto &rowid_union() const {
688 assert(type == ROWID_UNION);
689 return u.rowid_union;
690 }
692 assert(type == INDEX_SKIP_SCAN);
693 return u.index_skip_scan;
694 }
695 const auto &index_skip_scan() const {
696 assert(type == INDEX_SKIP_SCAN);
697 return u.index_skip_scan;
698 }
700 assert(type == GROUP_INDEX_SKIP_SCAN);
701 return u.group_index_skip_scan;
702 }
703 const auto &group_index_skip_scan() const {
704 assert(type == GROUP_INDEX_SKIP_SCAN);
705 return u.group_index_skip_scan;
706 }
709 return u.dynamic_index_range_scan;
710 }
711 const auto &dynamic_index_range_scan() const {
713 return u.dynamic_index_range_scan;
714 }
717 return u.materialized_table_function;
718 }
719 const auto &materialized_table_function() const {
721 return u.materialized_table_function;
722 }
724 assert(type == UNQUALIFIED_COUNT);
725 return u.unqualified_count;
726 }
727 const auto &unqualified_count() const {
728 assert(type == UNQUALIFIED_COUNT);
729 return u.unqualified_count;
730 }
732 assert(type == TABLE_VALUE_CONSTRUCTOR);
733 return u.table_value_constructor;
734 }
735 const auto &table_value_constructor() const {
736 assert(type == TABLE_VALUE_CONSTRUCTOR);
737 return u.table_value_constructor;
738 }
740 assert(type == FAKE_SINGLE_ROW);
741 return u.fake_single_row;
742 }
743 const auto &fake_single_row() const {
744 assert(type == FAKE_SINGLE_ROW);
745 return u.fake_single_row;
746 }
747 auto &zero_rows() {
748 assert(type == ZERO_ROWS);
749 return u.zero_rows;
750 }
751 const auto &zero_rows() const {
752 assert(type == ZERO_ROWS);
753 return u.zero_rows;
754 }
756 assert(type == ZERO_ROWS_AGGREGATED);
757 return u.zero_rows_aggregated;
758 }
759 const auto &zero_rows_aggregated() const {
760 assert(type == ZERO_ROWS_AGGREGATED);
761 return u.zero_rows_aggregated;
762 }
763 auto &hash_join() {
764 assert(type == HASH_JOIN);
765 return u.hash_join;
766 }
767 const auto &hash_join() const {
768 assert(type == HASH_JOIN);
769 return u.hash_join;
770 }
771 auto &bka_join() {
772 assert(type == BKA_JOIN);
773 return u.bka_join;
774 }
775 const auto &bka_join() const {
776 assert(type == BKA_JOIN);
777 return u.bka_join;
778 }
780 assert(type == NESTED_LOOP_JOIN);
781 return u.nested_loop_join;
782 }
783 const auto &nested_loop_join() const {
784 assert(type == NESTED_LOOP_JOIN);
785 return u.nested_loop_join;
786 }
789 return u.nested_loop_semijoin_with_duplicate_removal;
790 }
793 return u.nested_loop_semijoin_with_duplicate_removal;
794 }
795 auto &filter() {
796 assert(type == FILTER);
797 return u.filter;
798 }
799 const auto &filter() const {
800 assert(type == FILTER);
801 return u.filter;
802 }
803 auto &sort() {
804 assert(type == SORT);
805 return u.sort;
806 }
807 const auto &sort() const {
808 assert(type == SORT);
809 return u.sort;
810 }
811 auto &aggregate() {
812 assert(type == AGGREGATE);
813 return u.aggregate;
814 }
815 const auto &aggregate() const {
816 assert(type == AGGREGATE);
817 return u.aggregate;
818 }
820 assert(type == TEMPTABLE_AGGREGATE);
821 return u.temptable_aggregate;
822 }
823 const auto &temptable_aggregate() const {
824 assert(type == TEMPTABLE_AGGREGATE);
825 return u.temptable_aggregate;
826 }
827 auto &limit_offset() {
828 assert(type == LIMIT_OFFSET);
829 return u.limit_offset;
830 }
831 const auto &limit_offset() const {
832 assert(type == LIMIT_OFFSET);
833 return u.limit_offset;
834 }
835 auto &stream() {
836 assert(type == STREAM);
837 return u.stream;
838 }
839 const auto &stream() const {
840 assert(type == STREAM);
841 return u.stream;
842 }
843 auto &materialize() {
844 assert(type == MATERIALIZE);
845 return u.materialize;
846 }
847 const auto &materialize() const {
848 assert(type == MATERIALIZE);
849 return u.materialize;
850 }
853 return u.materialize_information_schema_table;
854 }
857 return u.materialize_information_schema_table;
858 }
859 auto &append() {
860 assert(type == APPEND);
861 return u.append;
862 }
863 const auto &append() const {
864 assert(type == APPEND);
865 return u.append;
866 }
867 auto &window() {
868 assert(type == WINDOW);
869 return u.window;
870 }
871 const auto &window() const {
872 assert(type == WINDOW);
873 return u.window;
874 }
875 auto &weedout() {
876 assert(type == WEEDOUT);
877 return u.weedout;
878 }
879 const auto &weedout() const {
880 assert(type == WEEDOUT);
881 return u.weedout;
882 }
884 assert(type == REMOVE_DUPLICATES);
885 return u.remove_duplicates;
886 }
887 const auto &remove_duplicates() const {
888 assert(type == REMOVE_DUPLICATES);
889 return u.remove_duplicates;
890 }
893 return u.remove_duplicates_on_index;
894 }
895 const auto &remove_duplicates_on_index() const {
897 return u.remove_duplicates_on_index;
898 }
899 auto &alternative() {
900 assert(type == ALTERNATIVE);
901 return u.alternative;
902 }
903 const auto &alternative() const {
904 assert(type == ALTERNATIVE);
905 return u.alternative;
906 }
908 assert(type == CACHE_INVALIDATOR);
909 return u.cache_invalidator;
910 }
911 const auto &cache_invalidator() const {
912 assert(type == CACHE_INVALIDATOR);
913 return u.cache_invalidator;
914 }
915 auto &delete_rows() {
916 assert(type == DELETE_ROWS);
917 return u.delete_rows;
918 }
919 const auto &delete_rows() const {
920 assert(type == DELETE_ROWS);
921 return u.delete_rows;
922 }
923 auto &update_rows() {
924 assert(type == UPDATE_ROWS);
925 return u.update_rows;
926 }
927 const auto &update_rows() const {
928 assert(type == UPDATE_ROWS);
929 return u.update_rows;
930 }
931
932 double num_output_rows() const { return m_num_output_rows; }
933
934 void set_num_output_rows(double val) {
935 assert(std::isfinite(val));
936 assert(val == kUnknownRowCount || val >= 0.0);
937 m_num_output_rows = val;
938 }
939
940 private:
941 /// Expected number of output rows.
943
944 /// Expected cost to read all of this access path once.
946
947 /// Expected cost to initialize this access path; ie., cost to read
948 /// k out of N rows would be init_cost + (k/N) * (cost - init_cost).
949 /// Note that EXPLAIN prints out cost of reading the _first_ row
950 /// because it is easier for the user and also easier to measure in
951 /// EXPLAIN ANALYZE, but it is easier to do calculations with a pure
952 /// initialization cost, so that is what we use in this member.
953 /// kUnknownCost for unknown.
955
956 /// Of init_cost, how much of the initialization needs only to be done
957 /// once per query block. (This is a cost, not a proportion.)
958 /// Ie., if the access path can reuse some its initialization work
959 /// if Init() is called multiple times, this member will be nonzero.
960 /// A typical example is a materialized table with rematerialize=false;
961 /// the second time Init() is called, it's a no-op. Most paths will have
962 /// init_once_cost = 0.0, ie., repeated scans will cost the same.
963 /// We do not intend to use this field to model cache effects.
964 ///
965 /// This is currently not printed in EXPLAIN, only optimizer trace.
966 double m_init_once_cost{0.0};
967
968 /// If no filter, identical to cost. init_cost is always the same
969 /// (filters have zero initialization cost).
971
972 // We'd prefer if this could be an std::variant, but we don't have C++17 yet.
973 // It is private to force all access to be through the type-checking
974 // accessors.
975 //
976 // For information about the meaning of each value, see the corresponding
977 // row iterator constructors.
978 union {
979 struct {
982 struct {
983 TABLE *table;
987 struct {
988 TABLE *table;
989 int idx;
993 struct {
994 TABLE *table;
995 int idx;
997 bool reverse;
999 struct {
1000 TABLE *table;
1002 bool use_order;
1003 bool reverse;
1005 struct {
1006 TABLE *table;
1008 bool use_order;
1010 struct {
1011 TABLE *table;
1014 struct {
1015 TABLE *table;
1017 bool use_order;
1020 struct {
1021 TABLE *table;
1023 bool use_order;
1027 struct {
1028 TABLE *table;
1031 struct {
1032 TABLE *table;
1038 struct {
1039 TABLE *table;
1041 struct {
1042 // The key part(s) we are scanning on. Note that this may be an array.
1043 // You can get the table we are working on by looking into
1044 // used_key_parts[0].field->table (it is not stored directly, to avoid
1045 // going over the AccessPath size limits).
1047
1048 // The actual ranges we are scanning over (originally derived from “key”).
1049 // Not a Bounds_checked_array, to save 4 bytes on the length.
1051 unsigned num_ranges;
1052
1053 unsigned mrr_flags;
1055
1056 // Which index (in the TABLE) we are scanning over, and how many of its
1057 // key parts we are using.
1058 unsigned index;
1060
1061 // If true, the scan can return rows in rowid order.
1063
1064 // If true, the scan _should_ return rows in rowid order.
1065 // Should only be set if can_be_used_for_ror == true.
1067
1068 // If true, this plan can be used for index merge scan.
1070
1071 // See row intersection for more details.
1073
1074 // Whether we are scanning over a geometry key part.
1075 bool geometry : 1;
1076
1077 // Whether we need a reverse scan. Only supported if geometry == false.
1078 bool reverse : 1;
1079
1080 // For a reverse scan, if we are using extended key parts. It is needed,
1081 // to set correct flags when retrieving records.
1084 struct {
1085 TABLE *table;
1090 struct {
1091 TABLE *table;
1093
1094 // Clustered primary key scan, if any.
1096
1097 bool forced_by_hint;
1100
1101 // If true, the first child scan should reuse table->file instead of
1102 // creating its own. This is true if the intersection is the topmost
1103 // range scan, but _not_ if it's below a union. (The reasons for this
1104 // are unknown.) It can also be negated by logic involving
1105 // retrieve_full_rows and is_covering, again for unknown reasons.
1106 //
1107 // This is not only for performance; multi-table delete has a hidden
1108 // dependency on this behavior when running against certain types of
1109 // tables (e.g. MyISAM), as it assumes table->file is correctly positioned
1110 // when deleting (and not all table types can transfer the position of one
1111 // handler to another by using position()).
1112 bool reuse_handler;
1113
1114 // true if no row retrieval phase is necessary.
1117 struct {
1118 TABLE *table;
1120 bool forced_by_hint;
1122 struct {
1123 TABLE *table;
1124 unsigned index;
1125 unsigned num_used_key_parts;
1126 bool forced_by_hint;
1127
1128 // Large, and has nontrivial destructors, so split out into
1129 // its own allocation.
1132 struct {
1133 TABLE *table;
1134 unsigned index;
1135 unsigned num_used_key_parts;
1136 bool forced_by_hint;
1137
1138 // Large, so split out into its own allocation.
1141 struct {
1142 TABLE *table;
1143 QEP_TAB *qep_tab; // Used only for buffering.
1145 struct {
1146 TABLE *table;
1150 struct {
1152
1153 struct {
1156 struct {
1157 // Explain-only table information for a single partitioned const table
1158 // whose row was fetched before iterator execution. Other fake-row uses,
1159 // including table-independent ones, leave this pointer null.
1160 const TABLE *table;
1162 struct {
1163 // The child is optional. It is only used for keeping track of which
1164 // tables are pruned away by this path, and it is only needed when this
1165 // path is on the inner side of an outer join. See ZeroRowsIterator for
1166 // details. The child of a ZERO_ROWS access path will not be visited by
1167 // WalkAccessPaths(). It will be visited by WalkTablesUnderAccessPath()
1168 // only if called with include_pruned_tables = true. No iterator is
1169 // created for the child, and the child is not shown by EXPLAIN.
1171 // Used for EXPLAIN only.
1172 // TODO(sgunders): make an enum.
1173 const char *cause;
1175 struct {
1176 // Used for EXPLAIN only.
1177 // TODO(sgunders): make an enum.
1178 const char *cause;
1180
1181 struct {
1185 bool store_rowids; // Whether we are below a weedout or not.
1189 struct {
1194 bool store_rowids; // Whether we are below a weedout or not.
1197 struct {
1199 JoinType join_type; // Somewhat redundant wrt. join_predicate.
1203
1204 // Equijoin filters to apply before the join, if any.
1205 // Indexes into join_predicate->expr->equijoin_conditions.
1206 // Non-equijoin conditions are always applied.
1207 // If already_expanded_predicates is true, do not re-expand.
1209
1210 // NOTE: Due to the nontrivial constructor on equijoin_predicates,
1211 // this struct needs an initializer, or the union would not be
1212 // default-constructible. If we need more than one union member
1213 // with such an initializer, we would probably need to change
1214 // equijoin_predicates into a uint64_t type-punned to an OverflowBitset.
1215 } nested_loop_join = {nullptr, nullptr, JoinType::INNER, false, false,
1216 nullptr, {}};
1217 struct {
1219 const TABLE *table;
1221 size_t key_len;
1223
1224 struct {
1227
1228 // This parameter, unlike nearly all others, is not passed to the the
1229 // actual iterator. Instead, if true, it signifies that when creating
1230 // the iterator, all materializable subqueries in “condition” should be
1231 // materialized (with any in2exists condition removed first). In the
1232 // very rare case that there are two or more such subqueries, this is
1233 // an all-or-nothing decision, for simplicity.
1234 //
1235 // See FinalizeMaterializedSubqueries().
1238 struct {
1242
1243 // If filesort is nullptr: A new filesort will be created at the
1244 // end of optimization, using this order and flags. Otherwise: Only
1245 // used by EXPLAIN.
1252 struct {
1256 struct {
1260 TABLE *table;
1264 struct {
1266 ha_rows limit;
1270 // Only used when the LIMIT is on a UNION with SQL_CALC_FOUND_ROWS.
1271 // See Query_expression::send_records.
1274 struct {
1276 JOIN *join;
1278 TABLE *table;
1280 int ref_slice;
1282 struct {
1283 // NOTE: The only legal access paths within table_path are
1284 // TABLE_SCAN, REF, REF_OR_NULL, EQ_REF, ALTERNATIVE,
1285 // CONST_TABLE (somewhat nonsensical), INDEX_SCAN and DYNAMIC_INDEX_SCAN
1287
1288 // Large, and has nontrivial destructors, so split out
1289 // into its own allocation.
1291 /** The total cost of executing the queries that we materialize.*/
1293 /// The number of materialized rows (as opposed to the number of rows
1294 /// fetched by table_path). Needed for 'explain'.
1297 struct {
1300 Item *condition;
1302 struct {
1305 struct {
1310 int ref_slice;
1313 struct {
1318 struct {
1319 using ItemSpan = std::span<Item *>;
1321
1322 /// @cond IGNORE
1323 // These functions somehow triggers a doxygen warning. (Presumably
1324 // a doxygen bug.)
1325 ItemSpan &group_items() {
1326 return reinterpret_cast<ItemSpan &>(m_group_items);
1327 }
1328
1329 const ItemSpan &group_items() const {
1330 return reinterpret_cast<const ItemSpan &>(m_group_items);
1331 }
1332 /// @endcond
1333
1334 private:
1335 // gcc 11 does not support a span as a union member. Replace this
1336 // with "std::span<Item *> group_items" when we move to newer gcc version.
1337 alignas(alignof(ItemSpan)) std::byte m_group_items[sizeof(ItemSpan)];
1339 struct {
1341 TABLE *table;
1342 KEY *key;
1345 struct {
1347
1348 // For the ref.
1352 struct {
1354 const char *name;
1356 struct {
1362 struct {
1368 } u;
1369};
1371 "AccessPath must be trivially destructible, as it is allocated "
1372 "on the MEM_ROOT and not wrapped in unique_ptr_destroy_only"
1373 "(because multiple candidates during planning could point to "
1374 "the same access paths, and refcounting would be expensive)");
1375static_assert(sizeof(AccessPath) <= 152,
1376 "We are creating a lot of access paths in the join "
1377 "optimizer, so be sure not to bloat it without noticing. "
1378 "(104 bytes for the base, 52 bytes for the variant.)");
1379
1380inline void CopyBasicProperties(const AccessPath &from, AccessPath *to) {
1382 to->set_cost(from.cost());
1383 to->set_init_cost(from.init_cost());
1386 to->safe_for_rowid = from.safe_for_rowid;
1387 to->ordering_state = from.ordering_state;
1389 to->signature = from.signature;
1390}
1391
1392/// Return the name of an AccessPath::Type enumerator.
1393std::string_view AccessPathTypeName(AccessPath::Type type);
1394
1395// Trivial factory functions for all of the types of access paths above.
1396
1398 bool count_examined_rows) {
1399 AccessPath *path = new (thd->mem_root) AccessPath;
1401 path->count_examined_rows = count_examined_rows;
1402 path->table_scan().table = table;
1403 return path;
1404}
1405
1407 double sampling_percentage,
1408 bool count_examined_rows) {
1409 AccessPath *path = new (thd->mem_root) AccessPath;
1411 path->count_examined_rows = count_examined_rows;
1412 path->sample_scan().table = table;
1413 path->sample_scan().sampling_percentage = sampling_percentage;
1414 return path;
1415}
1416
1418 bool use_order, bool reverse,
1419 bool count_examined_rows) {
1420 AccessPath *path = new (thd->mem_root) AccessPath;
1422 path->count_examined_rows = count_examined_rows;
1423 path->index_scan().table = table;
1424 path->index_scan().idx = idx;
1425 path->index_scan().use_order = use_order;
1426 path->index_scan().reverse = reverse;
1427 return path;
1428}
1429
1431 bool use_order, bool reverse,
1432 bool count_examined_rows) {
1433 AccessPath *path = new (thd->mem_root) AccessPath;
1434 path->type = AccessPath::REF;
1435 path->count_examined_rows = count_examined_rows;
1436 path->ref().table = table;
1437 path->ref().ref = ref;
1438 path->ref().use_order = use_order;
1439 path->ref().reverse = reverse;
1440 return path;
1441}
1442
1444 Index_lookup *ref, bool use_order,
1445 bool count_examined_rows) {
1446 AccessPath *path = new (thd->mem_root) AccessPath;
1448 path->count_examined_rows = count_examined_rows;
1449 path->ref_or_null().table = table;
1450 path->ref_or_null().ref = ref;
1451 path->ref_or_null().use_order = use_order;
1452 return path;
1453}
1454
1456 bool count_examined_rows) {
1457 AccessPath *path = new (thd->mem_root) AccessPath;
1458 path->type = AccessPath::EQ_REF;
1459 path->count_examined_rows = count_examined_rows;
1460 path->eq_ref().table = table;
1461 path->eq_ref().ref = ref;
1462 return path;
1463}
1464
1466 Index_lookup *ref, bool use_order,
1467 bool is_unique,
1468 bool count_examined_rows) {
1469 AccessPath *path = new (thd->mem_root) AccessPath;
1471 path->count_examined_rows = count_examined_rows;
1472 path->pushed_join_ref().table = table;
1473 path->pushed_join_ref().ref = ref;
1474 path->pushed_join_ref().use_order = use_order;
1475 path->pushed_join_ref().is_unique = is_unique;
1476 return path;
1477}
1478
1481 Item_func_match *ft_func,
1482 bool use_order, bool use_limit,
1483 bool count_examined_rows) {
1484 AccessPath *path = new (thd->mem_root) AccessPath;
1486 path->count_examined_rows = count_examined_rows;
1487 path->full_text_search().table = table;
1488 path->full_text_search().ref = ref;
1489 path->full_text_search().use_order = use_order;
1490 path->full_text_search().use_limit = use_limit;
1491 path->full_text_search().ft_func = ft_func;
1492 return path;
1493}
1494
1497 bool count_examined_rows) {
1498 AccessPath *path = new (thd->mem_root) AccessPath;
1500 path->count_examined_rows = count_examined_rows;
1501 path->set_num_output_rows(1.0);
1502 path->set_cost(0.0);
1503 path->set_init_cost(0.0);
1504 path->set_init_once_cost(0.0);
1505 path->const_table().table = table;
1506 path->const_table().ref = ref;
1507 return path;
1508}
1509
1511 int mrr_flags) {
1512 AccessPath *path = new (thd->mem_root) AccessPath;
1513 path->type = AccessPath::MRR;
1514 path->mrr().table = table;
1515 path->mrr().ref = ref;
1516 path->mrr().mrr_flags = mrr_flags;
1517
1518 // This will be filled in when the BKA iterator is created.
1519 path->mrr().bka_path = nullptr;
1520
1521 return path;
1522}
1523
1525 bool count_examined_rows) {
1526 AccessPath *path = new (thd->mem_root) AccessPath;
1528 path->count_examined_rows = count_examined_rows;
1529 path->follow_tail().table = table;
1530 return path;
1531}
1532
1534 THD *thd, TABLE *table, QEP_TAB *qep_tab, bool count_examined_rows) {
1535 AccessPath *path = new (thd->mem_root) AccessPath;
1537 path->count_examined_rows = count_examined_rows;
1538 path->dynamic_index_range_scan().table = table;
1539 path->dynamic_index_range_scan().qep_tab = qep_tab;
1540 return path;
1541}
1542
1544 THD *thd, TABLE *table, Table_function *table_function,
1545 AccessPath *table_path) {
1546 AccessPath *path = new (thd->mem_root) AccessPath;
1548 path->materialized_table_function().table = table;
1549 path->materialized_table_function().table_function = table_function;
1550 path->materialized_table_function().table_path = table_path;
1551 return path;
1552}
1553
1555 AccessPath *path = new (thd->mem_root) AccessPath;
1557 return path;
1558}
1559
1561 const JOIN *join);
1562
1564 THD *thd, AccessPath *outer, AccessPath *inner, const TABLE *table,
1565 KEY *key, size_t key_len) {
1566 AccessPath *path = new (thd->mem_root) AccessPath;
1568 path->nested_loop_semijoin_with_duplicate_removal().outer = outer;
1569 path->nested_loop_semijoin_with_duplicate_removal().inner = inner;
1570 path->nested_loop_semijoin_with_duplicate_removal().table = table;
1571 path->nested_loop_semijoin_with_duplicate_removal().key = key;
1572 path->nested_loop_semijoin_with_duplicate_removal().key_len = key_len;
1573 path->has_group_skip_scan =
1575 return path;
1576}
1577
1579 Item *condition) {
1580 AccessPath *path = new (thd->mem_root) AccessPath;
1581 path->type = AccessPath::FILTER;
1582 path->filter().child = child;
1583 path->filter().condition = condition;
1584 path->filter().materialize_subqueries = false;
1585 path->has_group_skip_scan = child->has_group_skip_scan;
1586 return path;
1587}
1588
1589// Not inline, because it needs access to filesort internals
1590// (which are forward-declared in this file).
1592 ORDER *order, bool count_examined_rows);
1593
1595 olap_type olap) {
1596 AccessPath *path = new (thd->mem_root) AccessPath;
1598 path->aggregate().child = child;
1599 path->aggregate().olap = olap;
1600 path->has_group_skip_scan = child->has_group_skip_scan;
1601 return path;
1602}
1603
1605 THD *thd, AccessPath *subquery_path, JOIN *join,
1606 Temp_table_param *temp_table_param, TABLE *table, AccessPath *table_path,
1607 int ref_slice) {
1608 AccessPath *path = new (thd->mem_root) AccessPath;
1610 path->temptable_aggregate().subquery_path = subquery_path;
1611 path->temptable_aggregate().join = join;
1612 path->temptable_aggregate().temp_table_param = temp_table_param;
1613 path->temptable_aggregate().table = table;
1614 path->temptable_aggregate().table_path = table_path;
1615 path->temptable_aggregate().ref_slice = ref_slice;
1616 return path;
1617}
1618
1620 ha_rows limit, ha_rows offset,
1621 bool count_all_rows,
1622 bool reject_multiple_rows,
1623 ha_rows *send_records_override) {
1625 AccessPath *path = new (thd->mem_root) AccessPath;
1627 path->immediate_update_delete_table = child->immediate_update_delete_table;
1628 path->limit_offset().child = child;
1629 path->limit_offset().limit = limit;
1630 path->limit_offset().offset = offset;
1631 path->limit_offset().count_all_rows = count_all_rows;
1632 path->limit_offset().reject_multiple_rows = reject_multiple_rows;
1633 path->limit_offset().send_records_override = send_records_override;
1634 CopyBasicProperties(*child, path);
1636 return path;
1637}
1638
1640 bool count_examined_rows,
1641 const TABLE *table = nullptr) {
1642 AccessPath *path = new (thd->mem_root) AccessPath;
1644 path->count_examined_rows = count_examined_rows;
1645 path->fake_single_row().table = table;
1646 path->set_num_output_rows(1.0);
1647 path->set_cost(0.0);
1648 path->set_init_cost(0.0);
1649 path->set_init_once_cost(0.0);
1650 return path;
1651}
1652
1654 const char *cause) {
1655 AccessPath *path = new (thd->mem_root) AccessPath;
1657 path->zero_rows().child = child;
1658 path->zero_rows().cause = cause;
1659 path->set_num_output_rows(0.0);
1660 path->set_cost(0.0);
1661 path->set_init_cost(0.0);
1662 path->set_init_once_cost(0.0);
1663 path->num_output_rows_before_filter = 0.0;
1664 path->set_cost_before_filter(0.0);
1665 return path;
1666}
1667
1668inline AccessPath *NewZeroRowsAccessPath(THD *thd, const char *cause) {
1669 return NewZeroRowsAccessPath(thd, /*child=*/nullptr, cause);
1670}
1671
1673 const char *cause) {
1674 AccessPath *path = new (thd->mem_root) AccessPath;
1676 path->zero_rows_aggregated().cause = cause;
1677 path->set_num_output_rows(1.0);
1678 path->set_cost(0.0);
1679 path->set_init_cost(0.0);
1680 return path;
1681}
1682
1684 Temp_table_param *temp_table_param,
1685 TABLE *table, int ref_slice);
1686
1689 JOIN *join, bool copy_items,
1690 Temp_table_param *temp_table_param) {
1691 assert(path != nullptr);
1693 MaterializePathParameters::Operand &operand = array[0];
1694 operand.subquery_path = path;
1695 operand.select_number = select_number;
1696 operand.join = join;
1698 operand.copy_items = copy_items;
1699 operand.temp_table_param = temp_table_param;
1700 return array;
1701}
1702
1706 AccessPath *table_path, Common_table_expr *cte, Query_expression *unit,
1707 int ref_slice, bool rematerialize, ha_rows limit_rows,
1708 bool reject_multiple_rows,
1713 param->m_operands = std::move(operands);
1714 if (rematerialize) {
1715 // There's no point in adding invalidators if we're rematerializing
1716 // every time anyway.
1717 param->invalidators = nullptr;
1718 } else {
1719 param->invalidators = invalidators;
1720 }
1721 param->table = table;
1722 param->cte = cte;
1723 param->unit = unit;
1724 param->ref_slice = ref_slice;
1725 param->rematerialize = rematerialize;
1726 param->limit_rows = (table == nullptr || table->is_union_or_table()
1727 ? limit_rows
1728 :
1729 // INTERSECT, EXCEPT: Enforced by TableScanIterator,
1730 // see its constructor
1731 HA_POS_ERROR);
1732 param->reject_multiple_rows = reject_multiple_rows;
1733 param->deduplication_reason = dedup_reason;
1734
1735#ifndef NDEBUG
1736 for (MaterializePathParameters::Operand &operand : param->m_operands) {
1737 assert(operand.subquery_path != nullptr);
1738 }
1739#endif
1740
1741 AccessPath *path = new (thd->mem_root) AccessPath;
1743 path->materialize().table_path = table_path;
1744 path->materialize().param = param;
1745 path->materialize().subquery_cost = kUnknownCost;
1746 path->materialize().subquery_rows = kUnknownRowCount;
1747 if (rematerialize) {
1748 path->safe_for_rowid = AccessPath::SAFE_IF_SCANNED_ONCE;
1749 } else {
1750 // The default; this is just to be explicit in the code.
1751 path->safe_for_rowid = AccessPath::SAFE;
1752 }
1753 return path;
1754}
1755
1757 THD *thd, AccessPath *table_path, Table_ref *table_list, Item *condition) {
1758 AccessPath *path = new (thd->mem_root) AccessPath;
1760 path->materialize_information_schema_table().table_path = table_path;
1761 path->materialize_information_schema_table().table_list = table_list;
1762 path->materialize_information_schema_table().condition = condition;
1763 return path;
1764}
1765
1766/// Add path costs c1 and c2, but handle kUnknownCost correctly.
1767inline double AddCost(double c1, double c2) {
1768 // If one is undefined, use the other, as we have nothing else.
1769 if (c1 == kUnknownCost) {
1770 return c2;
1771 } else if (c2 == kUnknownCost) {
1772 return c1;
1773 } else {
1774 return c1 + c2;
1775 }
1776}
1777
1778/// Add row counts c1 and c2, but handle kUnknownRowCount correctly.
1779inline double AddRowCount(double c1, double c2) {
1780 // If one is undefined, use the other, as we have nothing else.
1781 if (c1 == kUnknownRowCount) {
1782 return c2;
1783 } else if (c2 == kUnknownRowCount) {
1784 return c1;
1785 } else {
1786 return c1 + c2;
1787 }
1788}
1789
1790// The Mem_root_array must be allocated on a MEM_ROOT that lives at least for as
1791// long as the access path.
1793 THD *thd, Mem_root_array<AppendPathParameters> *children) {
1794 AccessPath *path = new (thd->mem_root) AccessPath;
1795 path->type = AccessPath::APPEND;
1796 path->append().children = children;
1797 double num_output_rows = kUnknownRowCount;
1798 for (const AppendPathParameters &child : *children) {
1799 path->set_cost(AddCost(path->cost(), child.path->cost()));
1800 path->set_init_cost(AddCost(path->init_cost(), child.path->init_cost()));
1801 path->set_init_once_cost(path->init_once_cost() +
1802 child.path->init_once_cost());
1803 num_output_rows =
1804 AddRowCount(num_output_rows, child.path->num_output_rows());
1805 }
1806 path->set_num_output_rows(num_output_rows);
1807 return path;
1808}
1809
1811 Window *window,
1812 Temp_table_param *temp_table_param,
1813 int ref_slice, bool needs_buffering) {
1814 AccessPath *path = new (thd->mem_root) AccessPath;
1815 path->type = AccessPath::WINDOW;
1816 path->window().child = child;
1817 path->window().window = window;
1818 path->window().temp_table = nullptr;
1819 path->window().temp_table_param = temp_table_param;
1820 path->window().ref_slice = ref_slice;
1821 path->window().needs_buffering = needs_buffering;
1822 path->set_num_output_rows(child->num_output_rows());
1823 return path;
1824}
1825
1827 SJ_TMP_TABLE *weedout_table) {
1828 AccessPath *path = new (thd->mem_root) AccessPath;
1829 path->type = AccessPath::WEEDOUT;
1830 path->weedout().child = child;
1831 path->weedout().weedout_table = weedout_table;
1832 path->weedout().tables_to_get_rowid_for =
1833 0; // Must be handled by the caller.
1834 return path;
1835}
1836
1838 THD *thd, AccessPath *child, std::span<Item *> group_items) {
1839 AccessPath *path = new (thd->mem_root) AccessPath;
1841 path->remove_duplicates().child = child;
1842 path->remove_duplicates().group_items() = group_items;
1843 path->has_group_skip_scan = child->has_group_skip_scan;
1844 return path;
1845}
1846
1848 THD *thd, AccessPath *child, TABLE *table, KEY *key,
1849 unsigned loosescan_key_len) {
1850 AccessPath *path = new (thd->mem_root) AccessPath;
1852 path->remove_duplicates_on_index().child = child;
1853 path->remove_duplicates_on_index().table = table;
1854 path->remove_duplicates_on_index().key = key;
1855 path->remove_duplicates_on_index().loosescan_key_len = loosescan_key_len;
1856 path->has_group_skip_scan = child->has_group_skip_scan;
1857 return path;
1858}
1859
1861 AccessPath *table_scan_path,
1862 Index_lookup *used_ref) {
1863 AccessPath *path = new (thd->mem_root) AccessPath;
1865 path->alternative().table_scan_path = table_scan_path;
1866 path->alternative().child = child;
1867 path->alternative().used_ref = used_ref;
1868 return path;
1869}
1870
1872 const char *name) {
1873 AccessPath *path = new (thd->mem_root) AccessPath;
1875 path->cache_invalidator().child = child;
1876 path->cache_invalidator().name = name;
1877 return path;
1878}
1879
1882 table_map immediate_tables);
1883
1885 table_map update_tables,
1886 table_map immediate_tables);
1887
1888/**
1889 Modifies "path" and the paths below it so that they provide row IDs for
1890 all tables.
1891
1892 This also figures out how the row IDs should be retrieved for each table in
1893 the input to the path. If the handler of the table is positioned on the
1894 correct row while reading the input, handler::position() can be called to get
1895 the row ID from the handler. However, if the input iterator returns rows
1896 without keeping the position of the underlying handlers in sync, calling
1897 handler::position() will not be able to provide the row IDs. Specifically,
1898 hash join and BKA join do not keep the underlying handlers positioned on the
1899 right row. Therefore, this function will instruct every hash join or BKA join
1900 below "path" to maintain row IDs in the join buffer, and updating handler::ref
1901 in every input table for each row they return. Then "path" does not need to
1902 call handler::position() to get it (nor should it, since calling it would
1903 overwrite the correct row ID with a stale one).
1904
1905 The tables on which "path" should call handler::position() are stored in a
1906 `tables_to_get_rowid_for` bitset in "path". For all the other tables, it can
1907 assume that handler::ref already contains the correct row ID.
1908 */
1910
1913 bool eligible_for_batch_mode);
1914
1915// A short form of CreateIteratorFromAccessPath() that implicitly uses the THD's
1916// MEM_ROOT for storage, which is nearly always what you want. (The only caller
1917// that does anything else is DynamicRangeIterator.)
1919 THD *thd, AccessPath *path, JOIN *join, bool eligible_for_batch_mode) {
1921 eligible_for_batch_mode);
1922}
1923
1924void SetCostOnTableAccessPath(const Cost_model_server &cost_model,
1925 const POSITION *pos, bool is_after_filter,
1926 AccessPath *path);
1927
1928/**
1929 Return the TABLE* referred from 'path' if it is a basic access path,
1930 else a nullptr is returned. Temporary tables, such as those used by
1931 sorting, aggregate and subquery materialization are not returned.
1932*/
1934
1935/**
1936 Applies the secondary storage engine nrows modification function, if any.
1937
1938 @param params input params for the callback function.
1939 Refer to typedef for the actual input parameters explainations.
1940
1941 @return true if secondary engine has proposed modification to ap's nrows.
1942*/
1944 const SecondaryEngineNrowsParameters &params);
1945
1946/**
1947 Returns whether SecondaryNrows is applicable given the parameters.
1948
1949 @param path access path to be verified.
1950 @param graph current query block hypergraph.
1951
1952 @return true if nrows hook is applicable.
1953*/
1955 const JoinHypergraph *graph);
1956
1957/**
1958 Returns a map of all tables read when `path` or any of its children are
1959 executed. Only iterators that are part of the same query block as `path`
1960 are considered.
1961
1962 If a table is read that doesn't have a map, specifically the temporary
1963 tables made as part of materialization within the same query block,
1964 RAND_TABLE_BIT will be set as a convention and none of that access path's
1965 children will be included in the map. In this case, the caller will need to
1966 manually go in and find said access path, to ask it for its TABLE object.
1967
1968 If include_pruned_tables = true, tables that are hidden under a ZERO_ROWS
1969 access path (ie., pruned away due to impossible join conditions) will be
1970 included in the map. This is normally what you want, as those tables need to
1971 be included whenever you store NULL flags and the likes, but if you don't
1972 want them (perhaps to specifically check for conditions referring to pruned
1973 tables), you can set it to false.
1974 */
1975table_map GetUsedTableMap(const AccessPath *path, bool include_pruned_tables);
1976
1977/**
1978 Find the list of all tables used by this root, stopping at materializations.
1979 Used for knowing which tables to sort.
1980 */
1982
1983/**
1984 For each access path in the (sub)tree rooted at “path”, expand any use of
1985 “filter_predicates” into newly-inserted FILTER access paths, using the given
1986 predicate list. This is used after finding an optimal set of access paths,
1987 to normalize the tree so that the remaining consumers do not need to worry
1988 about filter_predicates and cost_before_filter.
1989
1990 “join” is the join that “path” is part of.
1991 */
1992void ExpandFilterAccessPaths(THD *thd, const JoinHypergraph &graph,
1993 AccessPath *path, const JOIN *join);
1994
1995/**
1996 Extracts the Item expression from the given “filter_predicates” corresponding
1997 to the given “mask”.
1998 */
2001 int num_filter_predicates);
2002
2003/// Like ExpandFilterAccessPaths(), but expands only the single access path
2004/// at “path”.
2005void ExpandSingleFilterAccessPath(THD *thd, const JoinHypergraph &graph,
2006 AccessPath *path, const JOIN *join);
2007
2008/**
2009 Clear all the bits representing filter predicates in a bitset, and keep only
2010 the bits representing applied sargable join conditions.
2011
2012 See AccessPath::filter_predicates and
2013 AccessPath::applied_sargable_join_predicates() for details about how filter
2014 predicates and applied sargable join predicates are stored in different
2015 partitions of the same bitset.
2016
2017 @param predicates A bitset representing both filter predicates and applied
2018 sargable join predicates.
2019 @param num_filter_predicates The number of filter predicates.
2020 @param mem_root The root on which to allocate memory, if needed.
2021
2022 @return A copy of "predicates" with only the bits for applied sargable join
2023 predicates set.
2024 */
2026 int num_filter_predicates,
2028
2029/// Returns the tables that are part of a hash join.
2031
2032/**
2033 Get the conditions to put into the extra conditions of the HashJoinIterator.
2034 This includes the non-equijoin conditions, as well as any equijoin conditions
2035 on columns that are too big to include in the hash table. (The old optimizer
2036 handles equijoin conditions on long columns elsewhere, so the last part only
2037 applies to the hypergraph optimizer.)
2038
2039 @param mem_root The root on which to allocate memory, if needed.
2040 @param using_hypergraph_optimizer True if using the hypergraph optimizer.
2041 @param equijoin_conditions All the equijoin conditions of the join.
2042 @param other_conditions All the non-equijoin conditions of the join.
2043
2044 @return All the conditions to evaluate as "extra conditions" in
2045 HashJoinIterator, or nullptr on OOM.
2046 */
2048 MEM_ROOT *mem_root, bool using_hypergraph_optimizer,
2049 const std::vector<HashJoinCondition> &equijoin_conditions,
2050 const Mem_root_array<Item *> &other_conditions);
2051
2052/**
2053 Update status variables which count how many scans of various types are used
2054 in a query plan.
2055
2056 The following status variables are updated: Select_scan, Select_full_join,
2057 Select_range, Select_full_range_join, Select_range_check. They are also stored
2058 as performance schema statement events with the same names.
2059
2060 In addition, the performance schema statement events NO_INDEX_USED and
2061 NO_GOOD_INDEX_USED are updated, if appropriate.
2062 */
2063void CollectStatusVariables(THD *thd, const JOIN *top_join,
2064 const AccessPath &top_path);
2065
2066#endif // SQL_JOIN_OPTIMIZER_ACCESS_PATH_H
constexpr double kUnknownCost
To indicate that a cost estimate is not yet made.
Definition: access_path.h:206
bool ApplySecondaryEngineNrowsHook(const SecondaryEngineNrowsParameters &params)
Applies the secondary storage engine nrows modification function, if any.
Definition: access_path.cc:110
void ExpandSingleFilterAccessPath(THD *thd, const JoinHypergraph &graph, AccessPath *path, const JOIN *join)
Like ExpandFilterAccessPaths(), but expands only the single access path at “path”.
Definition: access_path.cc:1723
AccessPath * NewStreamingAccessPath(THD *thd, AccessPath *child, JOIN *join, Temp_table_param *temp_table_param, TABLE *table, int ref_slice)
Definition: access_path.cc:117
AccessPath * NewInvalidatorAccessPath(THD *thd, AccessPath *child, const char *name)
Definition: access_path.h:1871
AccessPath * NewRemoveDuplicatesAccessPath(THD *thd, AccessPath *child, std::span< Item * > group_items)
Definition: access_path.h:1837
AccessPath * NewRefAccessPath(THD *thd, TABLE *table, Index_lookup *ref, bool use_order, bool reverse, bool count_examined_rows)
Definition: access_path.h:1430
AccessPath * NewDeleteRowsAccessPath(THD *thd, AccessPath *child, table_map delete_tables, table_map immediate_tables)
Definition: access_path.cc:170
void CopyBasicProperties(const AccessPath &from, AccessPath *to)
Definition: access_path.h:1380
AccessPath * NewFullTextSearchAccessPath(THD *thd, TABLE *table, Index_lookup *ref, Item_func_match *ft_func, bool use_order, bool use_limit, bool count_examined_rows)
Definition: access_path.h:1479
double AddRowCount(double c1, double c2)
Add row counts c1 and c2, but handle kUnknownRowCount correctly.
Definition: access_path.h:1779
AccessPath * NewUpdateRowsAccessPath(THD *thd, AccessPath *child, table_map update_tables, table_map immediate_tables)
Definition: access_path.cc:187
table_map GetHashJoinTables(AccessPath *path)
Returns the tables that are part of a hash join.
Definition: access_path.cc:1883
AccessPath * NewDynamicIndexRangeScanAccessPath(THD *thd, TABLE *table, QEP_TAB *qep_tab, bool count_examined_rows)
Definition: access_path.h:1533
AccessPath * NewMaterializeAccessPath(THD *thd, Mem_root_array< MaterializePathParameters::Operand > operands, Mem_root_array< const AccessPath * > *invalidators, TABLE *table, AccessPath *table_path, Common_table_expr *cte, Query_expression *unit, int ref_slice, bool rematerialize, ha_rows limit_rows, bool reject_multiple_rows, MaterializePathParameters::DedupType dedup_reason=MaterializePathParameters::NO_DEDUP)
Definition: access_path.h:1703
AccessPath * NewZeroRowsAggregatedAccessPath(THD *thd, const char *cause)
Definition: access_path.h:1672
AccessPath * NewAlternativeAccessPath(THD *thd, AccessPath *child, AccessPath *table_scan_path, Index_lookup *used_ref)
Definition: access_path.h:1860
AccessPath * NewMRRAccessPath(THD *thd, TABLE *table, Index_lookup *ref, int mrr_flags)
Definition: access_path.h:1510
table_map GetUsedTableMap(const AccessPath *path, bool include_pruned_tables)
Returns a map of all tables read when path or any of its children are executed.
Definition: access_path.cc:429
Item * ConditionFromFilterPredicates(const Mem_root_array< Predicate > &predicates, OverflowBitset mask, int num_filter_predicates)
Extracts the Item expression from the given “filter_predicates” corresponding to the given “mask”.
Definition: access_path.cc:1712
AccessPath * NewAppendAccessPath(THD *thd, Mem_root_array< AppendPathParameters > *children)
Definition: access_path.h:1792
AccessPath * NewNestedLoopSemiJoinWithDuplicateRemovalAccessPath(THD *thd, AccessPath *outer, AccessPath *inner, const TABLE *table, KEY *key, size_t key_len)
Definition: access_path.h:1563
std::string_view AccessPathTypeName(AccessPath::Type type)
Return the name of an AccessPath::Type enumerator.
Definition: access_path.cc:330
void CollectStatusVariables(THD *thd, const JOIN *top_join, const AccessPath &top_path)
Update status variables which count how many scans of various types are used in a query plan.
Definition: access_path.cc:1897
MutableOverflowBitset ClearFilterPredicates(OverflowBitset predicates, int num_filter_predicates, MEM_ROOT *mem_root)
Clear all the bits representing filter predicates in a bitset, and keep only the bits representing ap...
Definition: access_path.cc:1874
AccessPath * NewTemptableAggregateAccessPath(THD *thd, AccessPath *subquery_path, JOIN *join, Temp_table_param *temp_table_param, TABLE *table, AccessPath *table_path, int ref_slice)
Definition: access_path.h:1604
AccessPath * NewRemoveDuplicatesOnIndexAccessPath(THD *thd, AccessPath *child, TABLE *table, KEY *key, unsigned loosescan_key_len)
Definition: access_path.h:1847
AccessPath * NewTableValueConstructorAccessPath(const THD *thd, const JOIN *join)
Definition: access_path.cc:224
AccessPath * NewFilterAccessPath(THD *thd, AccessPath *child, Item *condition)
Definition: access_path.h:1578
constexpr double kUnknownRowCount
To indicate that a row estimate is not yet made.
Definition: access_path.h:201
void ExpandFilterAccessPaths(THD *thd, const JoinHypergraph &graph, AccessPath *path, const JOIN *join)
For each access path in the (sub)tree rooted at “path”, expand any use of “filter_predicates” into ne...
Definition: access_path.cc:1865
AccessPath * NewSortAccessPath(THD *thd, AccessPath *child, Filesort *filesort, ORDER *order, bool count_examined_rows)
Definition: access_path.cc:135
bool IsSecondaryEngineNrowsHookApplicable(AccessPath *path, const JoinHypergraph *graph)
Returns whether SecondaryNrows is applicable given the parameters.
Definition: access_path.cc:101
AccessPath * NewMaterializedTableFunctionAccessPath(THD *thd, TABLE *table, Table_function *table_function, AccessPath *table_path)
Definition: access_path.h:1543
const Mem_root_array< Item * > * GetExtraHashJoinConditions(MEM_ROOT *mem_root, bool using_hypergraph_optimizer, const std::vector< HashJoinCondition > &equijoin_conditions, const Mem_root_array< Item * > &other_conditions)
Get the conditions to put into the extra conditions of the HashJoinIterator.
Mem_root_array< TABLE * > CollectTables(THD *thd, AccessPath *root_path)
Find the list of all tables used by this root, stopping at materializations.
Definition: access_path.cc:460
AccessPath * NewTableScanAccessPath(THD *thd, TABLE *table, bool count_examined_rows)
Definition: access_path.h:1397
AccessPath * NewSampleScanAccessPath(THD *thd, TABLE *table, double sampling_percentage, bool count_examined_rows)
Definition: access_path.h:1406
AccessPath * NewFakeSingleRowAccessPath(THD *thd, bool count_examined_rows, const TABLE *table=nullptr)
Definition: access_path.h:1639
AccessPath * NewAggregateAccessPath(THD *thd, AccessPath *child, olap_type olap)
Definition: access_path.h:1594
double AddCost(double c1, double c2)
Add path costs c1 and c2, but handle kUnknownCost correctly.
Definition: access_path.h:1767
AccessPath * NewMaterializeInformationSchemaTableAccessPath(THD *thd, AccessPath *table_path, Table_ref *table_list, Item *condition)
Definition: access_path.h:1756
void FindTablesToGetRowidFor(AccessPath *path)
Modifies "path" and the paths below it so that they provide row IDs for all tables.
Definition: access_path.cc:1548
TABLE * GetBasicTable(const AccessPath *path)
Return the TABLE* referred from 'path' if it is a basic access path, else a nullptr is returned.
Definition: access_path.cc:273
AccessPath * NewRefOrNullAccessPath(THD *thd, TABLE *table, Index_lookup *ref, bool use_order, bool count_examined_rows)
Definition: access_path.h:1443
AccessPath * NewLimitOffsetAccessPath(THD *thd, AccessPath *child, ha_rows limit, ha_rows offset, bool count_all_rows, bool reject_multiple_rows, ha_rows *send_records_override)
Definition: access_path.h:1619
AccessPath * NewEQRefAccessPath(THD *thd, TABLE *table, Index_lookup *ref, bool count_examined_rows)
Definition: access_path.h:1455
AccessPath * NewWindowAccessPath(THD *thd, AccessPath *child, Window *window, Temp_table_param *temp_table_param, int ref_slice, bool needs_buffering)
Definition: access_path.h:1810
double FirstRowCost(double init_cost, double total_cost, double output_rows)
Calculate the cost of reading the first row from an access path, given estimates for init cost,...
Definition: access_path.h:210
AccessPath * NewFollowTailAccessPath(THD *thd, TABLE *table, bool count_examined_rows)
Definition: access_path.h:1524
AccessPath * NewConstTableAccessPath(THD *thd, TABLE *table, Index_lookup *ref, bool count_examined_rows)
Definition: access_path.h:1495
unique_ptr_destroy_only< RowIterator > CreateIteratorFromAccessPath(THD *thd, MEM_ROOT *mem_root, AccessPath *path, JOIN *join, bool eligible_for_batch_mode)
Definition: access_path.cc:696
AccessPath * NewWeedoutAccessPath(THD *thd, AccessPath *child, SJ_TMP_TABLE *weedout_table)
Definition: access_path.h:1826
AccessPath * NewPushedJoinRefAccessPath(THD *thd, TABLE *table, Index_lookup *ref, bool use_order, bool is_unique, bool count_examined_rows)
Definition: access_path.h:1465
AccessPath * NewZeroRowsAccessPath(THD *thd, AccessPath *child, const char *cause)
Definition: access_path.h:1653
AccessPath * NewUnqualifiedCountAccessPath(THD *thd)
Definition: access_path.h:1554
AccessPath * NewIndexScanAccessPath(THD *thd, TABLE *table, int idx, bool use_order, bool reverse, bool count_examined_rows)
Definition: access_path.h:1417
Mem_root_array< MaterializePathParameters::Operand > SingleMaterializeQueryBlock(THD *thd, AccessPath *path, int select_number, JOIN *join, bool copy_items, Temp_table_param *temp_table_param)
Definition: access_path.h:1688
After parsing, a Common Table Expression is accessed through a Table_ref.
Definition: table.h:4611
API for getting cost estimates for server operations that are not directly related to a table object.
Definition: opt_costmodel.h:54
Sorting related info.
Definition: filesort.h:52
A class that represents a join condition in a hash join.
Definition: item_cmpfunc.h:92
Definition: item_func.h:3618
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:935
Definition: sql_optimizer.h:133
Definition: key.h:113
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:432
Definition: overflow_bitset.h:179
Definition: overflow_bitset.h:81
Definition: sql_executor.h:256
Definition: range_optimizer.h:69
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:662
A context for reading through a single table using a chosen access method: index read,...
Definition: row_iterator.h:82
Definition: sql_executor.h:95
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
MEM_ROOT * mem_root
Definition: sql_lexer_thd.h:40
Class representing a table function.
Definition: table_function.h:53
Definition: table.h:2958
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
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
void EstimateLimitOffsetCost(AccessPath *path)
Estimate the costs and row count for a WINDOW AccessPath.
Definition: cost_model.cc:1696
bool filesort(THD *thd, Filesort *filesort, RowIterator *source_iterator, table_map tables_to_get_rowid_for, ha_rows num_rows_estimate, Filesort_info *fs_info, Sort_result *sort_result, ha_rows *found_rows)
Sort a table.
Definition: filesort.cc:367
void SetCostOnTableAccessPath(const Cost_model_server &cost_model, const POSITION *pos, bool is_after_filter, AccessPath *path)
Definition: sql_executor.cc:2012
std::bitset< kMaxSupportedFDs > FunctionalDependencySet
Definition: interesting_orders_defs.h:63
JoinType
Definition: join_type.h:28
unsigned char byte
Blob class.
Definition: common.h:151
static mi_bit_type mask[]
Definition: mi_packrec.cc:141
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:480
This file includes constants used by all storage engines.
my_off_t ha_rows
Definition: my_base.h:1229
#define HA_POS_ERROR
Definition: my_base.h:1231
uint64_t table_map
Definition: my_table_map.h:30
static char * path
Definition: mysqldump.cc:153
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
uint64_t NodeMap
Since our graphs can never have more than 61 tables, node sets and edge lists are implemented using 6...
Definition: node_map.h:40
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
RangeReverse< Range > reverse(Range &x)
Iterate over a range in reverse.
Definition: utilities.h:132
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
int delete_tables(PFS_engine_table_share_proxy **, unsigned int) noexcept
Definition: pfs_plugin_table_v1_all_empty.cc:39
olap_type
Definition: olap.h:31
OverflowBitset is a fixed-size (once allocated) bitmap that is optimized for the common case of few e...
required string key
Definition: replication_asynchronous_connection_failover.proto:60
required string type
Definition: replication_group_member_actions.proto:34
case opt name
Definition: sslopt-case.h:29
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:243
auto & weedout()
Definition: access_path.h:875
auto & filter()
Definition: access_path.h:795
bool count_all_rows
Definition: access_path.h:1268
AccessPath * bka_path
Definition: access_path.h:1034
struct AccessPath::@67::@97 filter
auto & ref_or_null()
Definition: access_path.h:603
auto & materialized_table_function()
Definition: access_path.h:715
AccessPath * cpk_child
Definition: access_path.h:1095
auto & rowid_union()
Definition: access_path.h:683
hypergraph::NodeMap parameter_tables
If nonzero, a bitmap of other tables whose joined-in rows must already be loaded when rows from this ...
Definition: access_path.h:547
const auto & bka_join() const
Definition: access_path.h:775
struct AccessPath::@67::@93 hash_join
TABLE * temp_table
Definition: access_path.h:1308
OverflowBitset equijoin_predicates
Definition: access_path.h:1208
double rescan_cost() const
Return the cost of scanning the given path for the second time (or later) in the given query block.
Definition: access_path.h:445
auto & materialize()
Definition: access_path.h:843
const auto & temptable_aggregate() const
Definition: access_path.h:823
OverflowBitset & subsumed_sargable_join_predicates()
Similar to applied_sargable_join_predicates, bitmap of sargable join predicates that have been applie...
Definition: access_path.h:519
auto & index_scan()
Definition: access_path.h:579
struct AccessPath::@67::@85 group_index_skip_scan
struct AccessPath::@67::@79 follow_tail
const auto & delete_rows() const
Definition: access_path.h:919
struct AccessPath::@67::@92 zero_rows_aggregated
struct AccessPath::@67::@89 table_value_constructor
const auto & filter() const
Definition: access_path.h:799
struct AccessPath::@67::@84 index_skip_scan
struct AccessPath::@67::@77 const_table
const auto & index_distance_scan() const
Definition: access_path.h:591
auto & delete_rows()
Definition: access_path.h:915
bool reuse_handler
Definition: access_path.h:1072
KEY_PART * used_key_part
Definition: access_path.h:1046
double m_init_cost
Expected cost to initialize this access path; ie., cost to read k out of N rows would be init_cost + ...
Definition: access_path.h:954
olap_type olap
Definition: access_path.h:1254
struct AccessPath::@67::@73 ref_or_null
OverflowBitset & applied_sargable_join_predicates()
Bitmap of sargable join predicates that have already been applied in this access path by means of an ...
Definition: access_path.h:494
Item * condition
Definition: access_path.h:1226
const auto & index_merge() const
Definition: access_path.h:671
const auto & update_rows() const
Definition: access_path.h:927
double subquery_rows
The number of materialized rows (as opposed to the number of rows fetched by table_path).
Definition: access_path.h:1295
enum AccessPath::Type type
auto & alternative()
Definition: access_path.h:899
auto & pushed_join_ref()
Definition: access_path.h:619
void set_cost(double val)
Definition: access_path.h:415
AccessPath * outer
Definition: access_path.h:1182
std::span< Item * > ItemSpan
Definition: access_path.h:1319
auto & index_skip_scan()
Definition: access_path.h:691
bool rewrite_semi_to_inner
Definition: access_path.h:1186
const auto & zero_rows_aggregated() const
Definition: access_path.h:759
auto & group_index_skip_scan()
Definition: access_path.h:699
struct AccessPath::@67::@107 weedout
const auto & eq_ref() const
Definition: access_path.h:615
bool use_order
Definition: access_path.h:990
bool pfs_batch_mode
Definition: access_path.h:1200
auto & temptable_aggregate()
Definition: access_path.h:819
GroupIndexSkipScanParameters * param
Definition: access_path.h:1139
auto & rowid_intersection()
Definition: access_path.h:675
double init_cost() const
Definition: access_path.h:404
bool materialize_subqueries
Definition: access_path.h:1236
AccessPath * child
Definition: access_path.h:1170
bool allow_spill_to_disk
Definition: access_path.h:1184
struct AccessPath::@67::@82 rowid_intersection
struct AccessPath::@67::@83 rowid_union
Index_lookup * used_ref
Definition: access_path.h:1350
auto & mrr()
Definition: access_path.h:643
std::byte m_group_items[sizeof(ItemSpan)]
Definition: access_path.h:1337
auto & sample_scan()
Definition: access_path.h:571
const auto & index_scan() const
Definition: access_path.h:583
const auto & fake_single_row() const
Definition: access_path.h:743
struct AccessPath::@67::@102 stream
bool reject_multiple_rows
Definition: access_path.h:1269
struct AccessPath::@67::@81 index_merge
bool allow_clustered_primary_key_scan
Definition: access_path.h:1087
const char * name
Definition: access_path.h:1354
bool use_limit
Definition: access_path.h:1024
Window * window
Definition: access_path.h:1307
table_map tables_to_get_rowid_for
Definition: access_path.h:1187
auto & materialize_information_schema_table()
Definition: access_path.h:851
auto & bka_join()
Definition: access_path.h:771
struct AccessPath::@67::@96 nested_loop_semijoin_with_duplicate_removal
const auto & follow_tail() const
Definition: access_path.h:655
SJ_TMP_TABLE * weedout_table
Definition: access_path.h:1315
bool has_group_skip_scan
Whether this access path contains a GROUP_INDEX_SKIP_SCAN.
Definition: access_path.h:339
Index_lookup * ref
Definition: access_path.h:1001
struct AccessPath::@67::@101 limit_offset
const auto & window() const
Definition: access_path.h:871
void set_init_once_cost(double val)
Definition: access_path.h:427
const auto & materialized_table_function() const
Definition: access_path.h:719
auto & unqualified_count()
Definition: access_path.h:723
bool keep_current_rowid
Definition: access_path.h:1036
bool using_extended_key_parts
Definition: access_path.h:1082
auto & nested_loop_join()
Definition: access_path.h:779
const auto & full_text_search() const
Definition: access_path.h:631
struct AccessPath::@67::@87 materialized_table_function
bool can_be_used_for_ror
Definition: access_path.h:1062
float rec_per_key
Definition: access_path.h:1193
Safety safe_for_rowid
Whether it is safe to get row IDs (for sorting) from this access path.
Definition: access_path.h:330
JOIN * join
Definition: access_path.h:1258
unsigned index
Definition: access_path.h:1058
unsigned mrr_buf_size
Definition: access_path.h:1054
auto & remove_duplicates()
Definition: access_path.h:883
RowIterator * iterator
If an iterator has been instantiated for this access path, points to the iterator.
Definition: access_path.h:400
const auto & stream() const
Definition: access_path.h:839
struct AccessPath::@67::@71 index_distance_scan
const auto & remove_duplicates() const
Definition: access_path.h:887
auto & window()
Definition: access_path.h:867
bool need_rows_in_rowid_order
Definition: access_path.h:1066
Table_ref * table_list
Definition: access_path.h:1299
const auto & unqualified_count() const
Definition: access_path.h:727
void * secondary_engine_data
Auxiliary data used by a secondary storage engine while processing the access path during optimizatio...
Definition: access_path.h:556
struct AccessPath::@67::@68 table_scan
struct AccessPath::@67::@110 alternative
void set_init_cost(double val)
Definition: access_path.h:421
void set_num_output_rows(double val)
Definition: access_path.h:934
bool is_covering
Definition: access_path.h:1115
const auto & mrr() const
Definition: access_path.h:647
void set_cost_before_filter(double val)
Definition: access_path.h:433
bool remove_duplicates
Definition: access_path.h:1248
table_map tables_to_update
Definition: access_path.h:1364
const auto & table_value_constructor() const
Definition: access_path.h:735
KEY * key
Definition: access_path.h:1220
bool HasConsistentCostsAndRows(const JoinHypergraph &graph) const
Return true if costs and row counts are consistent.
Definition: access_path.cc:1975
auto & table_value_constructor()
Definition: access_path.h:731
auto & stream()
Definition: access_path.h:835
union AccessPath::@67 u
size_t key_len
Definition: access_path.h:1221
const OverflowBitset & subsumed_sargable_join_predicates() const
Definition: access_path.h:522
const auto & zero_rows() const
Definition: access_path.h:751
const auto & append() const
Definition: access_path.h:863
ha_rows offset
Definition: access_path.h:1267
int idx
Definition: access_path.h:989
auto & hash_join()
Definition: access_path.h:763
auto & cache_invalidator()
Definition: access_path.h:907
struct AccessPath::@67::@90 fake_single_row
bool force_sort_rowids
Definition: access_path.h:1250
unsigned num_used_key_parts
Definition: access_path.h:1059
unsigned num_ranges
Definition: access_path.h:1051
ORDER * order
Definition: access_path.h:1246
auto & sort()
Definition: access_path.h:803
struct AccessPath::@67::@80 index_range_scan
auto & fake_single_row()
Definition: access_path.h:739
ha_rows limit
Definition: access_path.h:1247
auto & follow_tail()
Definition: access_path.h:651
double m_num_output_rows
Expected number of output rows.
Definition: access_path.h:942
const auto & sample_scan() const
Definition: access_path.h:575
const JoinPredicate * join_predicate
Definition: access_path.h:1183
const auto & const_table() const
Definition: access_path.h:639
const auto & dynamic_index_range_scan() const
Definition: access_path.h:711
const auto & table_scan() const
Definition: access_path.h:567
struct AccessPath::@67::@70 index_scan
unsigned mrr_flags
Definition: access_path.h:1053
int ref_slice
Definition: access_path.h:1262
struct AccessPath::@67::@112 delete_rows
OverflowBitset filter_predicates
Bitmap of WHERE predicates that we are including on this access path, referring to the “predicates” a...
Definition: access_path.h:478
bool can_be_used_for_imerge
Definition: access_path.h:1069
bool forced_by_hint
Definition: access_path.h:1086
auto & limit_offset()
Definition: access_path.h:827
AccessPath * inner
Definition: access_path.h:1182
QUICK_RANGE * range
Definition: access_path.h:996
bool provide_rowid
Definition: access_path.h:1279
const auto & index_range_scan() const
Definition: access_path.h:663
struct AccessPath::@67::@99 aggregate
struct AccessPath::@67::@75 pushed_join_ref
const auto & ref() const
Definition: access_path.h:599
struct AccessPath::@67::@91 zero_rows
bool forced_by_dbug
Whether this access path is forced preferred over all others by means of a SET DEBUG force_subplan_0x...
Definition: access_path.h:344
Item_func_match * ft_func
Definition: access_path.h:1025
ha_rows * send_records_override
Definition: access_path.h:1272
auto & table_scan()
Definition: access_path.h:563
const auto & hash_join() const
Definition: access_path.h:767
QEP_TAB * qep_tab
Definition: access_path.h:1143
Table_function * table_function
Definition: access_path.h:1147
struct AccessPath::@67::@109 remove_duplicates_on_index
auto & zero_rows_aggregated()
Definition: access_path.h:755
const auto & sort() const
Definition: access_path.h:807
bool unwrap_rollup
Definition: access_path.h:1249
struct AccessPath::@67::@74 eq_ref
struct AccessPath::@67::@94 bka_join
struct AccessPath::@67::@78 mrr
Type
Definition: access_path.h:244
@ FOLLOW_TAIL
Definition: access_path.h:259
@ FILTER
Definition: access_path.h:283
@ PUSHED_JOIN_REF
Definition: access_path.h:255
@ ZERO_ROWS_AGGREGATED
Definition: access_path.h:272
@ UPDATE_ROWS
Definition: access_path.h:301
@ AGGREGATE
Definition: access_path.h:285
@ BKA_JOIN
Definition: access_path.h:279
@ ZERO_ROWS
Definition: access_path.h:271
@ CONST_TABLE
Definition: access_path.h:257
@ GROUP_INDEX_SKIP_SCAN
Definition: access_path.h:265
@ SAMPLE_SCAN
Definition: access_path.h:249
@ INDEX_RANGE_SCAN
Definition: access_path.h:260
@ UNQUALIFIED_COUNT
Definition: access_path.h:274
@ EQ_REF
Definition: access_path.h:254
@ FAKE_SINGLE_ROW
Definition: access_path.h:270
@ MATERIALIZE_INFORMATION_SCHEMA_TABLE
Definition: access_path.h:290
@ WINDOW
Definition: access_path.h:292
@ REF_OR_NULL
Definition: access_path.h:253
@ MATERIALIZE
Definition: access_path.h:289
@ NESTED_LOOP_SEMIJOIN_WITH_DUPLICATE_REMOVAL
Definition: access_path.h:278
@ ROWID_UNION
Definition: access_path.h:263
@ INDEX_SKIP_SCAN
Definition: access_path.h:264
@ MRR
Definition: access_path.h:258
@ CACHE_INVALIDATOR
Definition: access_path.h:297
@ INDEX_SCAN
Definition: access_path.h:250
@ TABLE_VALUE_CONSTRUCTOR
Definition: access_path.h:269
@ WEEDOUT
Definition: access_path.h:293
@ MATERIALIZED_TABLE_FUNCTION
Definition: access_path.h:273
@ REMOVE_DUPLICATES_ON_INDEX
Definition: access_path.h:295
@ TABLE_SCAN
Definition: access_path.h:248
@ REF
Definition: access_path.h:252
@ TEMPTABLE_AGGREGATE
Definition: access_path.h:286
@ LIMIT_OFFSET
Definition: access_path.h:287
@ APPEND
Definition: access_path.h:291
@ NESTED_LOOP_JOIN
Definition: access_path.h:277
@ INDEX_MERGE
Definition: access_path.h:261
@ FULL_TEXT_SEARCH
Definition: access_path.h:256
@ ALTERNATIVE
Definition: access_path.h:296
@ STREAM
Definition: access_path.h:288
@ REMOVE_DUPLICATES
Definition: access_path.h:294
@ ROWID_INTERSECTION
Definition: access_path.h:262
@ DYNAMIC_INDEX_RANGE_SCAN
Definition: access_path.h:266
@ DELETE_ROWS
Definition: access_path.h:300
@ SORT
Definition: access_path.h:284
@ INDEX_DISTANCE_SCAN
Definition: access_path.h:251
@ HASH_JOIN
Definition: access_path.h:280
bool retrieve_full_rows
Definition: access_path.h:1098
double m_init_once_cost
Of init_cost, how much of the initialization needs only to be done once per query block.
Definition: access_path.h:966
struct AccessPath::@67::@86 dynamic_index_range_scan
const auto & rowid_union() const
Definition: access_path.h:687
const TABLE * table
Definition: access_path.h:1160
const auto & index_skip_scan() const
Definition: access_path.h:695
auto & dynamic_index_range_scan()
Definition: access_path.h:707
const auto & pushed_join_ref() const
Definition: access_path.h:623
struct AccessPath::@67::@111 cache_invalidator
auto & remove_duplicates_on_index()
Definition: access_path.h:891
table_map immediate_tables
Definition: access_path.h:1359
double m_cost_before_filter
If no filter, identical to cost.
Definition: access_path.h:970
double cost() const
Definition: access_path.h:402
struct AccessPath::@67::@88 unqualified_count
int mrr_flags
Definition: access_path.h:1035
auto & full_text_search()
Definition: access_path.h:627
const auto & materialize() const
Definition: access_path.h:847
int ordering_state
Which ordering the rows produced by this path follow, if any (see interesting_orders....
Definition: access_path.h:394
auto & eq_ref()
Definition: access_path.h:611
JoinType join_type
Definition: access_path.h:1191
const auto & limit_offset() const
Definition: access_path.h:831
MaterializePathParameters * param
Definition: access_path.h:1290
const char * cause
Definition: access_path.h:1173
auto & update_rows()
Definition: access_path.h:923
auto & index_merge()
Definition: access_path.h:667
auto & aggregate()
Definition: access_path.h:811
struct AccessPath::@67::@104 materialize_information_schema_table
double m_cost
Expected cost to read all of this access path once.
Definition: access_path.h:945
const auto & group_index_skip_scan() const
Definition: access_path.h:703
auto & zero_rows()
Definition: access_path.h:747
AccessPath * subquery_path
Definition: access_path.h:1257
Mem_root_array< AppendPathParameters > * children
Definition: access_path.h:1303
const auto & nested_loop_join() const
Definition: access_path.h:783
bool already_expanded_predicates
Definition: access_path.h:1201
const auto & remove_duplicates_on_index() const
Definition: access_path.h:895
Temp_table_param * temp_table_param
Definition: access_path.h:1259
auto & nested_loop_semijoin_with_duplicate_removal()
Definition: access_path.h:787
bool reverse
Definition: access_path.h:991
AccessPath * table_scan_path
Definition: access_path.h:1346
struct AccessPath::@67::@113 update_rows
struct AccessPath::@67::@98 sort
enum tablesample_type sampling_type
Definition: access_path.h:985
const auto & materialize_information_schema_table() const
Definition: access_path.h:855
double subquery_cost
The total cost of executing the queries that we materialize.
Definition: access_path.h:1292
bool geometry
Definition: access_path.h:1075
bool count_examined_rows
Whether this access path counts as one that scans a base table, and thus should be counted towards ex...
Definition: access_path.h:336
unsigned loosescan_key_len
Definition: access_path.h:1343
auto & index_distance_scan()
Definition: access_path.h:587
auto & ref()
Definition: access_path.h:595
struct AccessPath::@67::@100 temptable_aggregate
double first_row_cost() const
The cost of reading the first row.
Definition: access_path.h:407
table_map tables_to_delete_from
Definition: access_path.h:1358
struct AccessPath::@67::@69 sample_scan
double init_once_cost() const
Definition: access_path.h:411
IndexSkipScanParameters * param
Definition: access_path.h:1130
const OverflowBitset & applied_sargable_join_predicates() const
Definition: access_path.h:497
Mem_root_array< AccessPath * > * children
Definition: access_path.h:1088
OverflowBitset delayed_predicates
Bitmap of WHERE predicates that touch tables we have joined in, but that we could not apply yet (for ...
Definition: access_path.h:511
AccessPath * table_path
Definition: access_path.h:1148
const auto & aggregate() const
Definition: access_path.h:815
TABLE * table
Definition: access_path.h:980
auto & append()
Definition: access_path.h:859
double cost_before_filter() const
Definition: access_path.h:413
const auto & weedout() const
Definition: access_path.h:879
const auto & cache_invalidator() const
Definition: access_path.h:911
double sampling_percentage
Definition: access_path.h:984
bool needs_buffering
Definition: access_path.h:1311
int8_t immediate_update_delete_table
For UPDATE and DELETE statements: The node index of a table which can be updated or deleted from imme...
Definition: access_path.h:388
QUICK_RANGE ** ranges
Definition: access_path.h:1050
bool is_unique
Definition: access_path.h:1018
const auto & alternative() const
Definition: access_path.h:903
Safety
A general enum to describe the safety of a given operation.
Definition: access_path.h:311
@ SAFE_IF_SCANNED_ONCE
The given operation is safe if this access path is scanned once, but not if it's scanned multiple tim...
Definition: access_path.h:320
@ UNSAFE
The given operation is unsafe on this access path, no matter how many or few times it's scanned.
Definition: access_path.h:326
@ SAFE
The given operation is always safe on this access path.
Definition: access_path.h:313
struct AccessPath::@67::@103 materialize
auto & const_table()
Definition: access_path.h:635
unsigned mrr_length_per_rec
Definition: access_path.h:1192
struct AccessPath::@67::@76 full_text_search
const auto & rowid_intersection() const
Definition: access_path.h:679
Mem_root_array< Item_values_column * > * output_refs
Definition: access_path.h:1154
auto & index_range_scan()
Definition: access_path.h:659
double num_output_rows() const
Definition: access_path.h:932
double num_output_rows_before_filter
If no filter, identical to num_output_rows.
Definition: access_path.h:451
size_t signature
Signature used to uniquely identify the access path.
Definition: access_path.h:560
const auto & ref_or_null() const
Definition: access_path.h:607
struct AccessPath::@67::@95 nested_loop_join
Filesort * filesort
Definition: access_path.h:1240
struct AccessPath::@67::@105 append
bool store_rowids
Definition: access_path.h:1185
const auto & nested_loop_semijoin_with_duplicate_removal() const
Definition: access_path.h:791
Definition: access_path.h:195
JOIN * join
Definition: access_path.h:197
AccessPath * path
Definition: access_path.h:196
Definition: group_index_skip_scan_plan.h:45
Logically a part of AccessPath::index_skip_scan(), but is too large, so split out into its own struct...
Definition: index_skip_scan_plan.h:73
Structure used for index-based lookups.
Definition: sql_opt_exec_shared.h:67
A struct containing a join hypergraph of a single query block, encapsulating the constraints given by...
Definition: make_join_hypergraph.h:99
A specification that two specific relational expressions (e.g., two tables, or a table and a join bet...
Definition: access_path.h:80
FunctionalDependencySet functional_dependencies
Definition: access_path.h:102
Mem_root_array< int > functional_dependencies_idx
Definition: access_path.h:107
RelationalExpression * expr
Definition: access_path.h:81
double selectivity
Definition: access_path.h:82
int ordering_idx_needed_for_semijoin_rewrite
Definition: access_path.h:125
size_t estimated_hash_join_key_width
Definition: access_path.h:91
std::span< Item * > semijoin_group
Definition: access_path.h:130
size_t estimated_bytes_per_row
Definition: access_path.h:86
Definition: range_optimizer.h:55
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: materialize_path_parameters.h:42
AccessPath * subquery_path
Definition: materialize_path_parameters.h:43
int select_number
Definition: materialize_path_parameters.h:44
JOIN * join
Definition: materialize_path_parameters.h:45
bool copy_items
Definition: materialize_path_parameters.h:47
Temp_table_param * temp_table_param
Definition: materialize_path_parameters.h:48
bool disable_deduplication_by_hash_field
Definition: materialize_path_parameters.h:46
Definition: materialize_path_parameters.h:40
bool rematerialize
True if rematerializing on every Init() call (e.g., because we have a dependency on a value from outs...
Definition: materialize_path_parameters.h:80
DedupType deduplication_reason
Definition: materialize_path_parameters.h:111
Mem_root_array< Operand > m_operands
Definition: materialize_path_parameters.h:58
Common_table_expr * cte
If materializing a CTE, points to it (see m_cte), otherwise nullptr.
Definition: materialize_path_parameters.h:65
DedupType
The context for which deduplication is being used.
Definition: materialize_path_parameters.h:106
@ NO_DEDUP
Definition: materialize_path_parameters.h:109
bool reject_multiple_rows
True if this is the top level iterator for a materialized derived table transformed from a scalar sub...
Definition: materialize_path_parameters.h:99
ha_rows limit_rows
Used for when pushing LIMIT down to MaterializeIterator; this is more efficient than having a LimitOf...
Definition: materialize_path_parameters.h:92
TABLE * table
Handle to table to materialize into.
Definition: materialize_path_parameters.h:62
int ref_slice
Definition: materialize_path_parameters.h:74
Query_expression * unit
The query expression we are materializing.
Definition: materialize_path_parameters.h:68
Mem_root_array< const AccessPath * > * invalidators
Definition: materialize_path_parameters.h:59
Definition: table.h:298
A position of table within a join order.
Definition: sql_select.h:355
A filter of some sort that is not a join condition (those are stored in JoinPredicate objects).
Definition: access_path.h:138
hypergraph::NodeMap total_eligibility_set
Definition: access_path.h:151
bool was_join_condition
Definition: access_path.h:164
Mem_root_array< int > functional_dependencies_idx
Definition: access_path.h:187
bool possibly_null_complemented_later
Definition: access_path.h:175
FunctionalDependencySet functional_dependencies
Definition: access_path.h:186
int source_multiple_equality_idx
Definition: access_path.h:183
hypergraph::NodeMap used_nodes
Definition: access_path.h:142
Item * condition
Definition: access_path.h:139
double selectivity
Definition: access_path.h:153
Mem_root_array< ContainedSubquery > contained_subqueries
Definition: access_path.h:192
Represents an expression tree in the relational algebra of joins.
Definition: relational_expression.h:155
Type for signature generation and for retrieving nrows estimate from secondary engine for current Acc...
Definition: handler.h:2486
Definition: table.h:1456
tablesample_type
Definition: tablesample.h:27