/**
Access paths are a query planning structure that correspond 1:1 to iterators,
in that an access path contains pretty much exactly the information
needed to instantiate given iterator, plus some information that is only
needed during planning, such as costs. (The new join optimizer will extend
this somewhat in the future. Some iterators also need the query block,
ie., JOIN object, they are part of, but that is implicitly available when
constructing the tree.)
AccessPath objects build on a variant, ie., they can hold an access path of
any type (table scan, filter, hash join, sort, etc.), although only one at the
same time. Currently, they contain 32 bytes of base information that is common
to any access path (type identifier, costs, etc.), and then up to 40 bytes
that is type-specific (e.g. for a table scan, the TABLE object). It would be
nice if we could squeeze it down to 64 and fit a cache line exactly, but it
does not seem to be easy without fairly large contortions.
We could have solved this by inheritance, but the fixed-size design makes it
possible to replace an access path when a better one is found, without
introducing a new allocation, which will be important when using them as a
planning structure.
*/
struct AccessPath {
// Most of the members are declared with initializers, but bit fields cannot
// be declared with initializers until C++20, so we need to define a
// constructor to initialize those fields.
// TODO(khatlen): When we move to C++20, add initializers to the bit fields
// too, and use the default constructor generated by the compiler.
AccessPath()
: count_examined_rows(false)
#ifndef NDEBUG
,
forced_by_dbug(false)
#endif
{
}
enum Type : uint8_t {
// Basic access paths (those with no children, at least nominally).
TABLE_SCAN,
INDEX_SCAN,
REF,
REF_OR_NULL,
EQ_REF,
PUSHED_JOIN_REF,
FULL_TEXT_SEARCH,
CONST_TABLE,
MRR,
FOLLOW_TAIL,
INDEX_RANGE_SCAN,
INDEX_MERGE,
ROWID_INTERSECTION,
ROWID_UNION,
INDEX_SKIP_SCAN,
GROUP_INDEX_SKIP_SCAN,
DYNAMIC_INDEX_RANGE_SCAN,
// Basic access paths that don' t correspond to a specific table.
TABLE_VALUE_CONSTRUCTOR,
FAKE_SINGLE_ROW,
ZERO_ROWS,
ZERO_ROWS_AGGREGATED,
MATERIALIZED_TABLE_FUNCTION,
UNQUALIFIED_COUNT,
// Joins.
NESTED_LOOP_JOIN,
NESTED_LOOP_SEMIJOIN_WITH_DUPLICATE_REMOVAL,
BKA_JOIN,
HASH_JOIN,
// Composite access paths.
FILTER,
SORT,
AGGREGATE,
TEMPTABLE_AGGREGATE,
LIMIT_OFFSET,
STREAM,
MATERIALIZE,
MATERIALIZE_INFORMATION_SCHEMA_TABLE,
APPEND,
WINDOW,
WEEDOUT,
REMOVE_DUPLICATES,
REMOVE_DUPLICATES_ON_INDEX,
ALTERNATIVE,
CACHE_INVALIDATOR,
// Access paths that modify tables.
DELETE_ROWS,
} type;
/// A general enum to describe the safety of a given operation.
/// Currently we only use this to describe row IDs, but it can easily
/// be reused for safety of updating a table we' re reading from
/// (the Halloween problem), or just generally unreproducible results
/// (e.g. a TABLESAMPLE changing due to external factors).
///
/// Less safe values have higher numerical values.
enum Safety : uint8_t {
/// The given operation is always safe on this access path.
SAFE = 0,
/// The given operation is safe if this access path is scanned once,
/// but not if it' s scanned multiple times (e.g. used on the inner side
/// of a nested-loop join). A typical example of this is a derived table
/// or CTE that is rematerialized on each scan, so that references to
/// the old values (such as row IDs) are no longer valid.
SAFE_IF_SCANNED_ONCE = 1,
/// The given operation is unsafe on this access path, no matter how many
/// or few times it' s scanned. Often, it may help to materialize it
/// (assuming the materialization itself doesn' t use the operation
/// in question).
UNSAFE = 2
};
/// Whether it is safe to get row IDs (for sorting) from this access path.
Safety safe_for_rowid = SAFE;
/// Whether this access path counts as one that scans a base table,
/// and thus should be counted towards examined_rows. It can sometimes
/// seem a bit arbitrary which iterators count towards examined_rows
/// and which ones do not, so the only canonical reference is the tests.
bool count_examined_rows : 1;
#ifndef NDEBUG
/// Whether this access path is forced preferred over all others by means
/// of a SET DEBUG force_subplan_0x... statement.
bool forced_by_dbug : 1;
#endif
/// For UPDATE and DELETE statements: The node index of a table which can be
/// updated or deleted from immediately as the rows are read from the
/// iterator, if this path is only read from once. -1 if there is no such
/// table in this path.
///
/// Note that this is an index into CostingReceiver' s array of nodes, and is
/// not necessarily equal to the table number within the query block given by
/// TABLE_LIST::tableno().
///
/// The table, if any, is currently always the outermost table in the path.
///
/// It is possible to have plans where it would be safe to operate
/// " immediately" on more than one table. For example, if we do a merge join,
/// it is safe to perform immediate deletes on tables on the inner side of the
/// join, since both sides are read only once. (However, we currently do not
/// support merge joins.)
///
/// Another possibility is when the outer table of a nested loop join is
/// guaranteed to return at most one row (typically, a unique index lookup
/// aka. eq_ref). Then it' s safe to delete immediately from both sides of the
/// nested loop join. But we don' t to this yet.
///
/// Hash joins read both sides exactly once, However, with hash joins, the
/// scans on the inner tables are not positioned on the correct row when the
/// result of the join is returned, so the immediate delete logic will need to
/// be changed to reposition the underlying scans before doing the immediate
/// deletes. While this can be done, it makes the benefit of immediate deletes
/// less obvious for these tables, and it can also be a loss in some cases,
/// because we lose the deduplication provided by the Unique object used for
/// buffered deletes (the immediate deletes could end up spending time
/// repositioning to already deleted rows). So we currently don' t attempt to
/// do immediate deletes from inner tables of hash joins either.
///
/// The outer table of a hash join can be deleted from immediately if the
/// inner table fits in memory. If the hash join spills to disk, though,
/// neither the rows of the outer table nor the rows of the inner table come
/// out in the order of the underlying scan, so it is not safe in general to
/// perform immediate deletes on the outer table of a hash join.
///
/// If support for immediate operations on multiple tables is added,
/// this member could be changed from a node index to a NodeMap.
int8_t immediate_update_delete_table{-1};
/// Which ordering the rows produced by this path follow, if any
/// (see interesting_orders.h). This is really a LogicalOrderings::StateIndex,
/// but we don' t want to add a dependency on interesting_orders.h from
/// this file, so we use the base type instead of the typedef here.
int ordering_state = 0;
/// If an iterator has been instantiated for this access path, points to the
/// iterator. Used for constructing iterators that need to talk to each other
/// (e.g. for recursive CTEs, or BKA join), and also for locating timing
/// information in EXPLAIN ANALYZE queries.
RowIterator *iterator = nullptr;
/// Expected number of output rows, -1.0 for unknown.
double num_output_rows{-1.0};
/// Expected cost to read all of this access path once; -1.0 for unknown.
double cost{-1.0};
/// Expected cost to initialize this access path; ie., cost to read
/// k out of N rows would be init_cost + (k/N) * (cost - init_cost).
/// Note that EXPLAIN prints out cost of reading the _first_ row
/// because it is easier for the user and also easier to measure in
/// EXPLAIN ANALYZE, but it is easier to do calculations with a pure
/// initialization cost, so that is what we use in this member.
/// -1.0 for unknown.
double init_cost{-1.0};
/// Of init_cost, how much of the initialization needs only to be done
/// once per query block. (This is a cost, not a proportion.)
/// Ie., if the access path can reuse some its initialization work
/// if Init() is called multiple times, this member will be nonzero.
/// A typical example is a materialized table with rematerialize=false;
/// the second time Init() is called, it' s a no-op. Most paths will have
/// init_once_cost = 0.0, ie., repeated scans will cost the same.
/// We do not intend to use this field to model cache effects.
///
/// This is currently not printed in EXPLAIN, only optimizer trace.
double init_once_cost{0.0};
/// Return the cost of scanning the given path for the second time
/// (or later) in the given query block. This is really the interesting
/// metric, not init_once_cost in itself, but since nearly all paths
/// have zero init_once_cost, storing that instead allows us to skip
/// a lot of repeated path-> init_once_cost = path-> init_cost calls
/// in the code.
double rescan_cost() const { return cost - init_once_cost; }
/// If no filter, identical to num_output_rows, cost, respectively.
/// init_cost is always the same (filters have zero initialization cost).
double num_output_rows_before_filter{-1.0}, cost_before_filter{-1.0};
/// Bitmap of WHERE predicates that we are including on this access path,
/// referring to the "predicates" array internal to the join optimizer.
/// Since bit masks are much cheaper to deal with than creating Item
/// objects, and we don' t invent new conditions during join optimization
/// (all of them are known when we begin optimization), we stick to
/// manipulating bit masks during optimization, saying which filters will be
/// applied at this node (a 1-bit means the filter will be applied here; if
/// there are multiple ones, they are ANDed together).
///
/// This is used during join optimization only; before iterators are
/// created, we will add FILTER access paths to represent these instead,
/// removing the dependency on the array. Said FILTER paths are by
/// convention created with materialize_subqueries = false, since the by far
/// most common case is that there are no subqueries in the predicate.
/// In other words, if you wish to represent a filter with
/// materialize_subqueries = true, you will need to make an explicit FILTER
/// node.
///
/// See also nested_loop_join().equijoin_predicates, which is for filters
/// being applied _before_ nested-loop joins, but is otherwise the same idea.
OverflowBitset filter_predicates{0};
/// Bitmap of sargable join predicates that have already been applied
/// in this access path by means of an index lookup (ref access),
/// again referring to "predicates", and thus should not be counted again
/// for selectivity. Note that the filter may need to be applied
/// nevertheless (especially in case of type conversions); see
/// subsumed_sargable_join_predicates.
///
/// Since these refer to the same array as filter_predicates, they will
/// never overlap with filter_predicates, and so we can reuse the same
/// memory using an alias (a union would not be allowed, since OverflowBitset
/// is a class with non-trivial default constructor), even though the meaning
/// is entirely separate. If N = num_where_predictes in the hypergraph, then
/// bits 0..(N-1) belong to filter_predicates, and the rest to
/// applied_sargable_join_predicates.
OverflowBitset & applied_sargable_join_predicates() {
return filter_predicates;
}
const OverflowBitset & applied_sargable_join_predicates() const {
return filter_predicates;
}
/// Bitmap of WHERE predicates that touch tables we have joined in,
/// but that we could not apply yet (for instance because they reference
/// other tables, or because because we could not push them down into
/// the nullable side of outer joins). Used during planning only
/// (see filter_predicates).
OverflowBitset delayed_predicates{0};
/// Similar to applied_sargable_join_predicates, bitmap of sargable
/// join predicates that have been applied and will subsume the join
/// predicate entirely, ie., not only should the selectivity not be
/// double-counted, but the predicate itself is redundant and need not
/// be applied as a filter. (It is an error to have a bit set here but not
/// in applied_sargable_join_predicates.)
OverflowBitset & subsumed_sargable_join_predicates() {
return delayed_predicates;
}
const OverflowBitset & subsumed_sargable_join_predicates() const {
return delayed_predicates;
}
/// If nonzero, a bitmap of other tables whose joined-in rows must already be
/// loaded when rows from this access path are evaluated; that is, this
/// access path must be put on the inner side of a nested-loop join (or
/// multiple such joins) where the outer side includes all of the given
/// tables.
///
/// The most obvious case for this is dependent tables in LATERAL, but a more
/// common case is when we have pushed join conditions referring to those
/// tables; e.g., if this access path represents t1 and we have a condition
/// t1.x=t2.x that is pushed down into an index lookup (ref access), t2 will
/// be set in this bitmap. We can still join in other tables, deferring t2,
/// but the bit(s) will then propagate, and we cannot be on the right side of
/// a hash join until parameter_tables is zero again. (Also see
/// DisallowParameterizedJoinPath() for when we disallow such deferring,
/// as an optimization.)
///
/// As a special case, we allow setting RAND_TABLE_BIT, even though it
/// is normally part of a table_map, not a NodeMap. In this case, it specifies
/// that the access path is entirely noncachable, because it depends on
/// something nondeterministic or an outer reference, and thus can never be on
/// the right side of a hash join, ever.
hypergraph::NodeMap parameter_tables{0};
/// Auxiliary data used by a secondary storage engine while processing the
/// access path during optimization and execution. The secondary storage
/// engine is free to store any useful information in this member, for example
/// extra statistics or cost estimates. The data pointed to is fully owned by
/// the secondary storage engine, and it is the responsibility of the
/// secondary engine to manage the memory and make sure it is properly
/// destroyed.
void *secondary_engine_data{nullptr};
// Accessors for the union below.
auto & table_scan() {
assert(type == TABLE_SCAN);
return u.table_scan;
}
const auto & table_scan() const {
assert(type == TABLE_SCAN);
return u.table_scan;
}
auto & index_scan() {
assert(type == INDEX_SCAN);
return u.index_scan;
}
const auto & index_scan() const {
assert(type == INDEX_SCAN);
return u.index_scan;
}
auto & ref() {
assert(type == REF);
return u.ref;
}
const auto & ref() const {
assert(type == REF);
return u.ref;
}
auto & ref_or_null() {
assert(type == REF_OR_NULL);
return u.ref_or_null;
}
const auto & ref_or_null() const {
assert(type == REF_OR_NULL);
return u.ref_or_null;
}
auto & eq_ref() {
assert(type == EQ_REF);
return u.eq_ref;
}
const auto & eq_ref() const {
assert(type == EQ_REF);
return u.eq_ref;
}
auto & pushed_join_ref() {
assert(type == PUSHED_JOIN_REF);
return u.pushed_join_ref;
}
const auto & pushed_join_ref() const {
assert(type == PUSHED_JOIN_REF);
return u.pushed_join_ref;
}
auto & full_text_search() {
assert(type == FULL_TEXT_SEARCH);
return u.full_text_search;
}
const auto & full_text_search() const {
assert(type == FULL_TEXT_SEARCH);
return u.full_text_search;
}
auto & const_table() {
assert(type == CONST_TABLE);
return u.const_table;
}
const auto & const_table() const {
assert(type == CONST_TABLE);
return u.const_table;
}
auto & mrr() {
assert(type == MRR);
return u.mrr;
}
const auto & mrr() const {
assert(type == MRR);
return u.mrr;
}
auto & follow_tail() {
assert(type == FOLLOW_TAIL);
return u.follow_tail;
}
const auto & follow_tail() const {
assert(type == FOLLOW_TAIL);
return u.follow_tail;
}
auto & index_range_scan() {
assert(type == INDEX_RANGE_SCAN);
return u.index_range_scan;
}
const auto & index_range_scan() const {
assert(type == INDEX_RANGE_SCAN);
return u.index_range_scan;
}
auto & index_merge() {
assert(type == INDEX_MERGE);
return u.index_merge;
}
const auto & index_merge() const {
assert(type == INDEX_MERGE);
return u.index_merge;
}
auto & rowid_intersection() {
assert(type == ROWID_INTERSECTION);
return u.rowid_intersection;
}
const auto & rowid_intersection() const {
assert(type == ROWID_INTERSECTION);
return u.rowid_intersection;
}
auto & rowid_union() {
assert(type == ROWID_UNION);
return u.rowid_union;
}
const auto & rowid_union() const {
assert(type == ROWID_UNION);
return u.rowid_union;
}
auto & index_skip_scan() {
assert(type == INDEX_SKIP_SCAN);
return u.index_skip_scan;
}
const auto & index_skip_scan() const {
assert(type == INDEX_SKIP_SCAN);
return u.index_skip_scan;
}
auto & group_index_skip_scan() {
assert(type == GROUP_INDEX_SKIP_SCAN);
return u.group_index_skip_scan;
}
const auto & group_index_skip_scan() const {
assert(type == GROUP_INDEX_SKIP_SCAN);
return u.group_index_skip_scan;
}
auto & dynamic_index_range_scan() {
assert(type == DYNAMIC_INDEX_RANGE_SCAN);
return u.dynamic_index_range_scan;
}
const auto & dynamic_index_range_scan() const {
assert(type == DYNAMIC_INDEX_RANGE_SCAN);
return u.dynamic_index_range_scan;
}
auto & materialized_table_function() {
assert(type == MATERIALIZED_TABLE_FUNCTION);
return u.materialized_table_function;
}
const auto & materialized_table_function() const {
assert(type == MATERIALIZED_TABLE_FUNCTION);
return u.materialized_table_function;
}
auto & unqualified_count() {
assert(type == UNQUALIFIED_COUNT);
return u.unqualified_count;
}
const auto & unqualified_count() const {
assert(type == UNQUALIFIED_COUNT);
return u.unqualified_count;
}
auto & table_value_constructor() {
assert(type == TABLE_VALUE_CONSTRUCTOR);
return u.table_value_constructor;
}
const auto & table_value_constructor() const {
assert(type == TABLE_VALUE_CONSTRUCTOR);
return u.table_value_constructor;
}
auto & fake_single_row() {
assert(type == FAKE_SINGLE_ROW);
return u.fake_single_row;
}
const auto & fake_single_row() const {
assert(type == FAKE_SINGLE_ROW);
return u.fake_single_row;
}
auto & zero_rows() {
assert(type == ZERO_ROWS);
return u.zero_rows;
}
const auto & zero_rows() const {
assert(type == ZERO_ROWS);
return u.zero_rows;
}
auto & zero_rows_aggregated() {
assert(type == ZERO_ROWS_AGGREGATED);
return u.zero_rows_aggregated;
}
const auto & zero_rows_aggregated() const {
assert(type == ZERO_ROWS_AGGREGATED);
return u.zero_rows_aggregated;
}
auto & hash_join() {
assert(type == HASH_JOIN);
return u.hash_join;
}
const auto & hash_join() const {
assert(type == HASH_JOIN);
return u.hash_join;
}
auto & bka_join() {
assert(type == BKA_JOIN);
return u.bka_join;
}
const auto & bka_join() const {
assert(type == BKA_JOIN);
return u.bka_join;
}
auto & nested_loop_join() {
assert(type == NESTED_LOOP_JOIN);
return u.nested_loop_join;
}
const auto & nested_loop_join() const {
assert(type == NESTED_LOOP_JOIN);
return u.nested_loop_join;
}
auto & nested_loop_semijoin_with_duplicate_removal() {
assert(type == NESTED_LOOP_SEMIJOIN_WITH_DUPLICATE_REMOVAL);
return u.nested_loop_semijoin_with_duplicate_removal;
}
const auto & nested_loop_semijoin_with_duplicate_removal() const {
assert(type == NESTED_LOOP_SEMIJOIN_WITH_DUPLICATE_REMOVAL);
return u.nested_loop_semijoin_with_duplicate_removal;
}
auto & filter() {
assert(type == FILTER);
return u.filter;
}
const auto & filter() const {
assert(type == FILTER);
return u.filter;
}
auto & sort() {
assert(type == SORT);
return u.sort;
}
const auto & sort() const {
assert(type == SORT);
return u.sort;
}
auto & aggregate() {
assert(type == AGGREGATE);
return u.aggregate;
}
const auto & aggregate() const {
assert(type == AGGREGATE);
return u.aggregate;
}
auto & temptable_aggregate() {
assert(type == TEMPTABLE_AGGREGATE);
return u.temptable_aggregate;
}
const auto & temptable_aggregate() const {
assert(type == TEMPTABLE_AGGREGATE);
return u.temptable_aggregate;
}
auto & limit_offset() {
assert(type == LIMIT_OFFSET);
return u.limit_offset;
}
const auto & limit_offset() const {
assert(type == LIMIT_OFFSET);
return u.limit_offset;
}
auto & stream() {
assert(type == STREAM);
return u.stream;
}
const auto & stream() const {
assert(type == STREAM);
return u.stream;
}
auto & materialize() {
assert(type == MATERIALIZE);
return u.materialize;
}
const auto & materialize() const {
assert(type == MATERIALIZE);
return u.materialize;
}
auto & materialize_information_schema_table() {
assert(type == MATERIALIZE_INFORMATION_SCHEMA_TABLE);
return u.materialize_information_schema_table;
}
const auto & materialize_information_schema_table() const {
assert(type == MATERIALIZE_INFORMATION_SCHEMA_TABLE);
return u.materialize_information_schema_table;
}
auto & append() {
assert(type == APPEND);
return u.append;
}
const auto & append() const {
assert(type == APPEND);
return u.append;
}
auto & window() {
assert(type == WINDOW);
return u.window;
}
const auto & window() const {
assert(type == WINDOW);
return u.window;
}
auto & weedout() {
assert(type == WEEDOUT);
return u.weedout;
}
const auto & weedout() const {
assert(type == WEEDOUT);
return u.weedout;
}
auto & remove_duplicates() {
assert(type == REMOVE_DUPLICATES);
return u.remove_duplicates;
}
const auto & remove_duplicates() const {
assert(type == REMOVE_DUPLICATES);
return u.remove_duplicates;
}
auto & remove_duplicates_on_index() {
assert(type == REMOVE_DUPLICATES_ON_INDEX);
return u.remove_duplicates_on_index;
}
const auto & remove_duplicates_on_index() const {
assert(type == REMOVE_DUPLICATES_ON_INDEX);
return u.remove_duplicates_on_index;
}
auto & alternative() {
assert(type == ALTERNATIVE);
return u.alternative;
}
const auto & alternative() const {
assert(type == ALTERNATIVE);
return u.alternative;
}
auto & cache_invalidator() {
assert(type == CACHE_INVALIDATOR);
return u.cache_invalidator;
}
const auto & cache_invalidator() const {
assert(type == CACHE_INVALIDATOR);
return u.cache_invalidator;
}
auto & delete_rows() {
assert(type == DELETE_ROWS);
return u.delete_rows;
}
const auto & delete_rows() const {
assert(type == DELETE_ROWS);
return u.delete_rows;
}
private:
// We' d prefer if this could be an std::variant, but we don' t have C++17 yet.
// It is private to force all access to be through the type-checking
// accessors.
//
// For information about the meaning of each value, see the corresponding
// row iterator constructors.
union {
struct {
TABLE *table;
} table_scan;
struct {
TABLE *table;
int idx;
bool use_order;
bool reverse;
} index_scan;
struct {
TABLE *table;
TABLE_REF *ref;
bool use_order;
bool reverse;
} ref;
struct {
TABLE *table;
TABLE_REF *ref;
bool use_order;
} ref_or_null;
struct {
TABLE *table;
TABLE_REF *ref;
bool use_order;
} eq_ref;
struct {
TABLE *table;
TABLE_REF *ref;
bool use_order;
bool is_unique;
} pushed_join_ref;
struct {
TABLE *table;
TABLE_REF *ref;
bool use_order;
bool use_limit;
Item_func_match *ft_func;
} full_text_search;
struct {
TABLE *table;
TABLE_REF *ref;
} const_table;
struct {
TABLE *table;
TABLE_REF *ref;
AccessPath *bka_path;
int mrr_flags;
bool keep_current_rowid;
} mrr;
struct {
TABLE *table;
} follow_tail;
struct {
// The key part(s) we are scanning on. Note that this may be an array.
// You can get the table we are working on by looking into
// used_key_parts[0].field-> table (it is not stored directly, to avoid
// going over the AccessPath size limits).
KEY_PART *used_key_part;
// The actual ranges we are scanning over (originally derived from "key").
// Not a Bounds_checked_array, to save 4 bytes on the length.
QUICK_RANGE **ranges;
unsigned num_ranges;
unsigned mrr_flags;
unsigned mrr_buf_size;
// Which index (in the TABLE) we are scanning over, and how many of its
// key parts we are using.
unsigned index;
unsigned num_used_key_parts;
// If true, the scan can return rows in rowid order.
bool can_be_used_for_ror : 1;
// If true, the scan _should_ return rows in rowid order.
// Should only be set if can_be_used_for_ror == true.
bool need_rows_in_rowid_order : 1;
// If true, this plan can be used for index merge scan.
bool can_be_used_for_imerge : 1;
// See row intersection for more details.
bool reuse_handler : 1;
// Whether we are scanning over a geometry key part.
bool geometry : 1;
// Whether we need a reverse scan. Only supported if geometry == false.
bool reverse : 1;
// For a reverse scan, if we are using extended key parts. It is needed,
// to set correct flags when retrieving records.
bool using_extended_key_parts : 1;
} index_range_scan;
struct {
TABLE *table;
bool forced_by_hint;
bool allow_clustered_primary_key_scan;
Mem_root_array< AccessPath *> *children;
} index_merge;
struct {
TABLE *table;
Mem_root_array< AccessPath *> *children;
// Clustered primary key scan, if any.
AccessPath *cpk_child;
bool forced_by_hint;
bool retrieve_full_rows;
bool need_rows_in_rowid_order;
// If true, the first child scan should reuse table-> file instead of
// creating its own. This is true if the intersection is the topmost
// range scan, but _not_ if it' s below a union. (The reasons for this
// are unknown.) It can also be negated by logic involving
// retrieve_full_rows and is_covering, again for unknown reasons.
//
// This is not only for performance; multi-table delete has a hidden
// dependency on this behavior when running against certain types of
// tables (e.g. MyISAM), as it assumes table-> file is correctly positioned
// when deleting (and not all table types can transfer the position of one
// handler to another by using position()).
bool reuse_handler;
// true if no row retrieval phase is necessary.
bool is_covering;
} rowid_intersection;
struct {
TABLE *table;
Mem_root_array< AccessPath *> *children;
bool forced_by_hint;
} rowid_union;
struct {
TABLE *table;
unsigned index;
unsigned num_used_key_parts;
bool forced_by_hint;
// Large, and has nontrivial destructors, so split out into
// its own allocation.
IndexSkipScanParameters *param;
} index_skip_scan;
struct {
TABLE *table;
unsigned index;
unsigned num_used_key_parts;
bool forced_by_hint;
// Large, so split out into its own allocation.
GroupIndexSkipScanParameters *param;
} group_index_skip_scan;
struct {
TABLE *table;
QEP_TAB *qep_tab; // Used only for buffering.
} dynamic_index_range_scan;
struct {
TABLE *table;
Table_function *table_function;
AccessPath *table_path;
} materialized_table_function;
struct {
} unqualified_count;
struct {
// No members (implicit from the JOIN).
} table_value_constructor;
struct {
// No members.
} fake_single_row;
struct {
// The child is optional. It is only used for keeping track of which
// tables are pruned away by this path, and it is only needed when this
// path is on the inner side of an outer join. See ZeroRowsIterator for
// details. The child of a ZERO_ROWS access path will not be visited by
// WalkAccessPaths(). It will be visited by WalkTablesUnderAccessPath()
// only if called with include_pruned_tables = true. No iterator is
// created for the child, and the child is not shown by EXPLAIN.
AccessPath *child;
// Used for EXPLAIN only.
// TODO(sgunders): make an enum.
const char *cause;
} zero_rows;
struct {
// Used for EXPLAIN only.
// TODO(sgunders): make an enum.
const char *cause;
} zero_rows_aggregated;
struct {
AccessPath *outer, *inner;
const JoinPredicate *join_predicate;
bool allow_spill_to_disk;
bool store_rowids; // Whether we are below a weedout or not.
bool rewrite_semi_to_inner;
table_map tables_to_get_rowid_for;
} hash_join;
struct {
AccessPath *outer, *inner;
JoinType join_type;
unsigned mrr_length_per_rec;
float rec_per_key;
bool store_rowids; // Whether we are below a weedout or not.
table_map tables_to_get_rowid_for;
} bka_join;
struct {
AccessPath *outer, *inner;
JoinType join_type; // Somewhat redundant wrt. join_predicate.
bool pfs_batch_mode;
bool already_expanded_predicates;
const JoinPredicate *join_predicate;
// Equijoin filters to apply before the join, if any.
// Indexes into join_predicate-> expr-> equijoin_conditions.
// Non-equijoin conditions are always applied.
// If already_expanded_predicates is true, do not re-expand.
OverflowBitset equijoin_predicates;
// NOTE: Due to the nontrivial constructor on equijoin_predicates,
// this struct needs an initializer, or the union would not be
// default-constructible. If we need more than one union member
// with such an initializer, we would probably need to change
// equijoin_predicates into a uint64_t type-punned to an OverflowBitset.
} nested_loop_join = {nullptr, nullptr, JoinType::INNER, false, false,
nullptr, {}};
struct {
AccessPath *outer, *inner;
const TABLE *table;
KEY *key;
size_t key_len;
} nested_loop_semijoin_with_duplicate_removal;
struct {
AccessPath *child;
Item *condition;
// This parameter, unlike nearly all others, is not passed to the the
// actual iterator. Instead, if true, it signifies that when creating
// the iterator, all materializable subqueries in "condition" should be
// materialized (with any in2exists condition removed first). In the
// very rare case that there are two or more such subqueries, this is
// an all-or-nothing decision, for simplicity.
//
// See FinalizeMaterializedSubqueries().
bool materialize_subqueries;
} filter;
struct {
AccessPath *child;
Filesort *filesort;
table_map tables_to_get_rowid_for;
// If filesort is nullptr: A new filesort will be created at the
// end of optimization, using this order and flags. Otherwise: Ignored.
ORDER *order;
bool remove_duplicates;
bool unwrap_rollup;
bool use_limit;
bool force_sort_rowids;
} sort;
struct {
AccessPath *child;
bool rollup;
} aggregate;
struct {
AccessPath *subquery_path;
Temp_table_param *temp_table_param;
TABLE *table;
AccessPath *table_path;
int ref_slice;
} temptable_aggregate;
struct {
AccessPath *child;
ha_rows limit;
ha_rows offset;
bool count_all_rows;
bool reject_multiple_rows;
// Only used when the LIMIT is on a UNION with SQL_CALC_FOUND_ROWS.
// See Query_expression::send_records.
ha_rows *send_records_override;
} limit_offset;
struct {
AccessPath *child;
JOIN *join;
Temp_table_param *temp_table_param;
TABLE *table;
bool provide_rowid;
int ref_slice;
} stream;
struct {
// NOTE: The only legal access paths within table_path are
// TABLE_SCAN, REF, REF_OR_NULL, EQ_REF, ALTERNATIVE and
// CONST_TABLE (the latter is somewhat nonsensical).
AccessPath *table_path;
// Large, and has nontrivial destructors, so split out
// into its own allocation.
MaterializePathParameters *param;
} materialize;
struct {
AccessPath *table_path;
TABLE_LIST *table_list;
Item *condition;
} materialize_information_schema_table;
struct {
Mem_root_array< AppendPathParameters> *children;
} append;
struct {
AccessPath *child;
Window *window;
TABLE *temp_table;
Temp_table_param *temp_table_param;
int ref_slice;
bool needs_buffering;
} window;
struct {
AccessPath *child;
SJ_TMP_TABLE *weedout_table;
table_map tables_to_get_rowid_for;
} weedout;
struct {
AccessPath *child;
Item **group_items;
int group_items_size;
} remove_duplicates;
struct {
AccessPath *child;
TABLE *table;
KEY *key;
unsigned loosescan_key_len;
} remove_duplicates_on_index;
struct {
AccessPath *table_scan_path;
// For the ref.
AccessPath *child;
TABLE_REF *used_ref;
} alternative;
struct {
AccessPath *child;
const char *name;
} cache_invalidator;
struct {
AccessPath *child;
table_map tables_to_delete_from;
table_map immediate_tables;
} delete_rows;
} u;
};
本文链接地址:【MySQL源码】AccessPath类解析,英雄不问来路,转载请注明出处,谢谢。
有话想说:那就赶紧去给我留言吧。
文章评论