24#ifndef SQL_JOIN_OPTIMIZER_WALK_ACCESS_PATHS_H 
   25#define SQL_JOIN_OPTIMIZER_WALK_ACCESS_PATHS_H 
   63template <
class AccessPathPtr, 
class Func, 
class JoinPtr>
 
   64  requires std::is_convertible_v<AccessPathPtr, const AccessPath *> &&
 
   65           std::is_convertible_v<JoinPtr, const JOIN *> &&
 
   66           std::is_invocable_r_v<bool, Func, AccessPathPtr, JoinPtr>
 
   69                     bool post_order_traversal = 
false) {
 
   71    assert(
join != 
nullptr);
 
   74  if (!post_order_traversal) {
 
   82               [&](
auto &&subpath, 
auto &&subjoin) {
 
   84                                 post_order_traversal);
 
   87  if (post_order_traversal) {
 
  108template <
class AccessPathPtr, 
class Func, 
class JoinPtr>
 
  109  requires std::is_convertible_v<AccessPathPtr, const AccessPath *> &&
 
  110           std::is_convertible_v<JoinPtr, const JOIN *> &&
 
  111           std::is_invocable_v<Func, AccessPathPtr, JoinPtr>
 
  115    assert(
join != 
nullptr);
 
  118  switch (
path->type) {
 
  144      func(
path->nested_loop_join().outer, 
join);
 
  145      func(
path->nested_loop_join().inner, 
join);
 
  148      func(
path->nested_loop_semijoin_with_duplicate_removal().outer, 
join);
 
  149      func(
path->nested_loop_semijoin_with_duplicate_removal().inner, 
join);
 
  156      func(
path->hash_join().inner, 
join);
 
  157      func(
path->hash_join().outer, 
join);
 
  166      func(
path->aggregate().child, 
join);
 
  171           path->temptable_aggregate().join == 
join)) {
 
  172        func(
path->temptable_aggregate().subquery_path, 
join);
 
  174      func(
path->temptable_aggregate().table_path, 
join);
 
  177      func(
path->limit_offset().child, 
join);
 
  183        func(
path->stream().child, 
path->stream().join);
 
  187      func(
path->materialize().table_path, 
join);
 
  189           path->materialize().param->m_operands) {
 
  192             operand.join == 
join)) {
 
  193          func(operand.subquery_path, operand.join);
 
  198      func(
path->materialize_information_schema_table().table_path, 
join);
 
  203          func(child.path, child.join);
 
  214      func(
path->remove_duplicates().child, 
join);
 
  217      func(
path->remove_duplicates_on_index().child, 
join);
 
  220      func(
path->alternative().child, 
join);
 
  223      func(
path->cache_invalidator().child, 
join);
 
  241      func(
path->delete_rows().child, 
join);
 
  244      func(
path->update_rows().child, 
join);
 
  257  requires std::is_invocable_r_v<bool, Func, TABLE *>
 
  259                               bool include_pruned_tables) {
 
  264        switch (
path->type) {
 
  265          case AccessPath::TABLE_SCAN:
 
  266            return func(path->table_scan().table);
 
  267          case AccessPath::SAMPLE_SCAN:
 
  270          case AccessPath::INDEX_SCAN:
 
  271            return func(path->index_scan().table);
 
  272          case AccessPath::INDEX_DISTANCE_SCAN:
 
  273            return func(path->index_distance_scan().table);
 
  274          case AccessPath::REF:
 
  275            return func(path->ref().table);
 
  276          case AccessPath::REF_OR_NULL:
 
  277            return func(path->ref_or_null().table);
 
  278          case AccessPath::EQ_REF:
 
  279            return func(path->eq_ref().table);
 
  280          case AccessPath::PUSHED_JOIN_REF:
 
  281            return func(path->pushed_join_ref().table);
 
  282          case AccessPath::FULL_TEXT_SEARCH:
 
  283            return func(path->full_text_search().table);
 
  284          case AccessPath::CONST_TABLE:
 
  285            return func(path->const_table().table);
 
  286          case AccessPath::MRR:
 
  287            return func(path->mrr().table);
 
  288          case AccessPath::FOLLOW_TAIL:
 
  289            return func(path->follow_tail().table);
 
  290          case AccessPath::INDEX_RANGE_SCAN:
 
  291            return func(path->index_range_scan().used_key_part[0].field->table);
 
  292          case AccessPath::INDEX_SKIP_SCAN:
 
  293            return func(path->index_skip_scan().table);
 
  294          case AccessPath::GROUP_INDEX_SKIP_SCAN:
 
  295            return func(path->group_index_skip_scan().table);
 
  296          case AccessPath::DYNAMIC_INDEX_RANGE_SCAN:
 
  297            return func(path->dynamic_index_range_scan().table);
 
  298          case AccessPath::STREAM:
 
  299            return func(path->stream().table);
 
  300          case AccessPath::MATERIALIZED_TABLE_FUNCTION:
 
  301            return func(path->materialized_table_function().table);
 
  302          case AccessPath::ALTERNATIVE:
 
  304                path->alternative().table_scan_path->table_scan().table);
 
  305          case AccessPath::UNQUALIFIED_COUNT:
 
  310          case AccessPath::ZERO_ROWS:
 
  311            if (include_pruned_tables && path->zero_rows().child != nullptr) {
 
  312              WalkTablesUnderAccessPath(path->zero_rows().child, func,
 
  313                                        include_pruned_tables);
 
  317            return func(
path->window().temp_table);
 
Definition: sql_optimizer.h:133
 
static char * path
Definition: mysqldump.cc:150
 
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
 
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:238
 
@ FOLLOW_TAIL
Definition: access_path.h:254
 
@ FILTER
Definition: access_path.h:278
 
@ PUSHED_JOIN_REF
Definition: access_path.h:250
 
@ ZERO_ROWS_AGGREGATED
Definition: access_path.h:267
 
@ UPDATE_ROWS
Definition: access_path.h:296
 
@ AGGREGATE
Definition: access_path.h:280
 
@ BKA_JOIN
Definition: access_path.h:274
 
@ ZERO_ROWS
Definition: access_path.h:266
 
@ CONST_TABLE
Definition: access_path.h:252
 
@ GROUP_INDEX_SKIP_SCAN
Definition: access_path.h:260
 
@ SAMPLE_SCAN
Definition: access_path.h:244
 
@ INDEX_RANGE_SCAN
Definition: access_path.h:255
 
@ UNQUALIFIED_COUNT
Definition: access_path.h:269
 
@ EQ_REF
Definition: access_path.h:249
 
@ FAKE_SINGLE_ROW
Definition: access_path.h:265
 
@ MATERIALIZE_INFORMATION_SCHEMA_TABLE
Definition: access_path.h:285
 
@ WINDOW
Definition: access_path.h:287
 
@ REF_OR_NULL
Definition: access_path.h:248
 
@ MATERIALIZE
Definition: access_path.h:284
 
@ NESTED_LOOP_SEMIJOIN_WITH_DUPLICATE_REMOVAL
Definition: access_path.h:273
 
@ ROWID_UNION
Definition: access_path.h:258
 
@ INDEX_SKIP_SCAN
Definition: access_path.h:259
 
@ MRR
Definition: access_path.h:253
 
@ CACHE_INVALIDATOR
Definition: access_path.h:292
 
@ INDEX_SCAN
Definition: access_path.h:245
 
@ TABLE_VALUE_CONSTRUCTOR
Definition: access_path.h:264
 
@ WEEDOUT
Definition: access_path.h:288
 
@ MATERIALIZED_TABLE_FUNCTION
Definition: access_path.h:268
 
@ REMOVE_DUPLICATES_ON_INDEX
Definition: access_path.h:290
 
@ TABLE_SCAN
Definition: access_path.h:243
 
@ REF
Definition: access_path.h:247
 
@ TEMPTABLE_AGGREGATE
Definition: access_path.h:281
 
@ LIMIT_OFFSET
Definition: access_path.h:282
 
@ APPEND
Definition: access_path.h:286
 
@ NESTED_LOOP_JOIN
Definition: access_path.h:272
 
@ INDEX_MERGE
Definition: access_path.h:256
 
@ FULL_TEXT_SEARCH
Definition: access_path.h:251
 
@ ALTERNATIVE
Definition: access_path.h:291
 
@ STREAM
Definition: access_path.h:283
 
@ REMOVE_DUPLICATES
Definition: access_path.h:289
 
@ ROWID_INTERSECTION
Definition: access_path.h:257
 
@ DYNAMIC_INDEX_RANGE_SCAN
Definition: access_path.h:261
 
@ DELETE_ROWS
Definition: access_path.h:295
 
@ SORT
Definition: access_path.h:279
 
@ INDEX_DISTANCE_SCAN
Definition: access_path.h:246
 
@ HASH_JOIN
Definition: access_path.h:275
 
Definition: access_path.h:190
 
Definition: materialize_path_parameters.h:42
 
void ForEachChild(AccessPathPtr path, JoinPtr join, WalkAccessPathPolicy cross_query_blocks, Func &&func)
Call a function on every immediate child of the given access path.
Definition: walk_access_paths.h:112
 
void WalkTablesUnderAccessPath(const AccessPath *root_path, Func &&func, bool include_pruned_tables)
A wrapper around WalkAccessPaths() that collects all tables under “root_path” and calls the given fun...
Definition: walk_access_paths.h:258
 
void WalkAccessPaths(AccessPathPtr path, JoinPtr join, WalkAccessPathPolicy cross_query_blocks, Func &&func, bool post_order_traversal=false)
Traverse every access path below path (possibly limited to the current query block with the cross_que...
Definition: walk_access_paths.h:67
 
WalkAccessPathPolicy
Definition: walk_access_paths.h:32
 
@ STOP_AT_MATERIALIZATION