MySQL 9.1.0
Source Code Documentation
walk_access_paths.h File Reference
#include <type_traits>
#include "sql/join_optimizer/access_path.h"
#include "sql/range_optimizer/range_optimizer.h"

Go to the source code of this file.

Enumerations

enum class  WalkAccessPathPolicy { STOP_AT_MATERIALIZATION , ENTIRE_QUERY_BLOCK , ENTIRE_TREE }
 

Functions

template<class AccessPathPtr , class Func , class JoinPtr >
requires std::is_convertible_v<AccessPathPtr, const AccessPath *> && std::is_convertible_v<JoinPtr, const JOIN *> && std::is_invocable_r_v<bool, Func, AccessPathPtr, JoinPtr>
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_query_blocks parameter), calling func() for each one with pre- or post-order traversal. More...
 
template<class AccessPathPtr , class Func , class JoinPtr >
requires std::is_convertible_v<AccessPathPtr, const AccessPath *> && std::is_convertible_v<JoinPtr, const JOIN *> && std::is_invocable_v<Func, AccessPathPtr, JoinPtr>
void ForEachChild (AccessPathPtr path, JoinPtr join, WalkAccessPathPolicy cross_query_blocks, Func &&func)
 Call a function on every immediate child of the given access path. More...
 
template<class Func >
void WalkTablesUnderAccessPath (AccessPath *root_path, Func &&func, bool include_pruned_tables)
 A wrapper around WalkAccessPaths() that collects all tables under “root_path” and calls the given functor, stopping at materializations. More...
 

Enumeration Type Documentation

◆ WalkAccessPathPolicy

enum class WalkAccessPathPolicy
strong
Enumerator
STOP_AT_MATERIALIZATION 
ENTIRE_QUERY_BLOCK 
ENTIRE_TREE 

Function Documentation

◆ ForEachChild()

template<class AccessPathPtr , class Func , class JoinPtr >
requires std::is_convertible_v<AccessPathPtr, const AccessPath *> && std::is_convertible_v<JoinPtr, const JOIN *> && std::is_invocable_v<Func, AccessPathPtr, JoinPtr>
void ForEachChild ( AccessPathPtr  path,
JoinPtr  join,
WalkAccessPathPolicy  cross_query_blocks,
Func &&  func 
)

Call a function on every immediate child of the given access path.

Parameters
pathThe access path whose children to visit.
joinThe JOIN object for the current query block. Can be nullptr if cross_query_blocks is not ENTIRE_QUERY_BLOCK.
cross_query_blocksTells whether to stop traversal at materialization or query block boundaries.
funcThe function to call. It takes two arguments: a pointer to an access path (the child) and a pointer to the JOIN object for which the access path was created.

◆ WalkAccessPaths()

template<class AccessPathPtr , class Func , class JoinPtr >
requires std::is_convertible_v<AccessPathPtr, const AccessPath *> && std::is_convertible_v<JoinPtr, const JOIN *> && std::is_invocable_r_v<bool, Func, AccessPathPtr, JoinPtr>
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_query_blocks parameter), calling func() for each one with pre- or post-order traversal.

If func() returns true, the traversal does not descend into the children of the current path. For post-order traversal, the children have already been traversed when func() is called, so it is too late to skip them, and the return value of func() is effectively ignored.

The join parameter signifies what query block path is part of, since that is not implicit from the path itself. The function will track this as it changes throughout the tree (in MATERIALIZE or STREAM access paths), and will give the correct value to the func() callback. It is only used by WalkAccessPaths() itself if the policy is ENTIRE_QUERY_BLOCK; if not, it is only used for the func() callback, and you can set it to nullptr if you wish. func() must have signature func(AccessPath *, const JOIN *), or it could be JOIN * if a non-const JOIN is given in.

◆ WalkTablesUnderAccessPath()

template<class Func >
void WalkTablesUnderAccessPath ( AccessPath root_path,
Func &&  func,
bool  include_pruned_tables 
)

A wrapper around WalkAccessPaths() that collects all tables under “root_path” and calls the given functor, stopping at materializations.

This is typically used to know which tables to sort or the like.

func() must have signature func(TABLE *), and return true upon error.