MySQL 8.0.29
Source Code Documentation
explain_access_path.h File Reference
#include <string>
#include <vector>

Go to the source code of this file.

Functions

std::string PrintQueryPlan (int level, AccessPath *path, JOIN *join, bool is_root_of_join, std::vector< std::string > *tokens_for_force_subplan=nullptr)
 Print out an access path and all of its children (if any) in a tree. More...
 
std::string GetForceSubplanToken (AccessPath *path, JOIN *join)
 Generate a digest based on the subplan that the given access path represents. More...
 

Function Documentation

◆ GetForceSubplanToken()

std::string GetForceSubplanToken ( AccessPath path,
JOIN join 
)

Generate a digest based on the subplan that the given access path represents.

This can be used by developers to force a given subplan, to investigate e.g. whether a given choice is actually faster in practice, force-apply a plan from the old join optimizer (or at least the types of subplans that are ever considered; e.g. aggregation through temporary tables are not) into the hypergraph join optimizer (to see how it's costed), or whether a given plan is even generated. If DEBUG contains force_subplan_0x<token>, subplans with the given token are unconditionally preferred over all others.

The token returned is “0x<digest>”, where <digest> is the first 64 bits of the SHA-256 sum of this string:

desc1,desc2,...,[child1_desc:]0xchild1,[child2_desc:]0xchild2,<more children>

where desc1, desc2, etc. are the description lines given by EXPLAIN, and 0xchild1 is the token for children. The normal way to generate such tokens is to use SET DEBUG='+d,subplan_tokens' and look at the EXPLAIN FORMAT=tree, but in a pinch, you can also write them by hand and use sha256sum or a similar tool.

Only the hypergraph join optimizer honors token preferences, but EXPLAIN FORMAT=tree shows computed tokens for both optimizers.

◆ PrintQueryPlan()

std::string PrintQueryPlan ( int  level,
AccessPath path,
JOIN join,
bool  is_root_of_join,
std::vector< std::string > *  tokens_for_force_subplan = nullptr 
)

Print out an access path and all of its children (if any) in a tree.

"level" is the current indenting level, as this is called recursively. "join" should be set to the JOIN that "path" is part of (or nullptr if it is not, e.g. if it's part of executing a UNION).