MySQL 8.0.29
Source Code Documentation
explain_access_path.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 2022, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef SQL_JOIN_OPTIMIZER_EXPLAIN_ACCESS_PATH_H
24#define SQL_JOIN_OPTIMIZER_EXPLAIN_ACCESS_PATH_H
25
26#include <string>
27#include <vector>
28
29struct AccessPath;
30class JOIN;
31
32/**
33 Print out an access path and all of its children (if any) in a tree.
34 "level" is the current indenting level, as this is called recursively.
35 "join" should be set to the JOIN that "path" is part of (or nullptr
36 if it is not, e.g. if it's part of executing a UNION).
37 */
38std::string PrintQueryPlan(
39 int level, AccessPath *path, JOIN *join, bool is_root_of_join,
40 std::vector<std::string> *tokens_for_force_subplan = nullptr);
41
42/**
43 Generate a digest based on the subplan that the given access path
44 represents. This can be used by developers to force a given subplan,
45 to investigate e.g. whether a given choice is actually faster in practice,
46 force-apply a plan from the old join optimizer (or at least the types of
47 subplans that are ever considered; e.g. aggregation through temporary
48 tables are not) into the hypergraph join optimizer (to see how it's costed),
49 or whether a given plan is even generated. If DEBUG contains
50 force_subplan_0x<token>, subplans with the given token are unconditionally
51 preferred over all others.
52
53 The token returned is “0x@<digest@>”, where @<digest@> is the first 64 bits
54 of the SHA-256 sum of this string:
55
56 desc1,desc2,...,[child1_desc:]0xchild1,[child2_desc:]0xchild2,@<more
57 children@>
58
59 where desc1, desc2, etc. are the description lines given by EXPLAIN,
60 and 0xchild1 is the token for children. The normal way to generate such
61 tokens is to use SET DEBUG='+d,subplan_tokens' and look at the EXPLAIN
62 FORMAT=tree, but in a pinch, you can also write them by hand and use
63 sha256sum or a similar tool.
64
65 Only the hypergraph join optimizer honors token preferences, but EXPLAIN
66 FORMAT=tree shows computed tokens for both optimizers.
67 */
69
70#endif // SQL_JOIN_OPTIMIZER_EXPLAIN_ACCESS_PATH_H
Definition: sql_optimizer.h:125
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.
std::string GetForceSubplanToken(AccessPath *path, JOIN *join)
Generate a digest based on the subplan that the given access path represents.
Definition: explain_access_path.cc:1178
static char * path
Definition: mysqldump.cc:130
std::string join(Container cont, const std::string &delim)
join elements of an container into a string separated by a delimiter.
Definition: string.h:150
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:188