24#ifndef SQL_JOIN_OPTIMIZER_WALK_ACCESS_PATHS_H
25#define SQL_JOIN_OPTIMIZER_WALK_ACCESS_PATHS_H
62template <
class AccessPathPtr,
class Func,
class JoinPtr>
65 bool post_order_traversal =
false) {
67 std::is_convertible<AccessPathPtr, const AccessPath *>::value,
68 "The “path” argument must be AccessPath * or const AccessPath *.");
70 std::is_convertible<JoinPtr, const JOIN *>::value,
71 "The “join” argument must be JOIN * or const JOIN * (or nullptr).");
74 assert(
join !=
nullptr);
76 if (!post_order_traversal) {
107 std::forward<Func &&>(func), post_order_traversal);
109 std::forward<Func &&>(func), post_order_traversal);
113 join, cross_query_blocks, std::forward<Func &&>(func),
114 post_order_traversal);
116 join, cross_query_blocks, std::forward<Func &&>(func),
117 post_order_traversal);
121 std::forward<Func &&>(func), post_order_traversal);
123 std::forward<Func &&>(func), post_order_traversal);
127 std::forward<Func &&>(func), post_order_traversal);
129 std::forward<Func &&>(func), post_order_traversal);
133 std::forward<Func &&>(func), post_order_traversal);
137 std::forward<Func &&>(func), post_order_traversal);
141 std::forward<Func &&>(func), post_order_traversal);
145 cross_query_blocks, std::forward<Func &&>(func),
146 post_order_traversal);
148 cross_query_blocks, std::forward<Func &&>(func),
149 post_order_traversal);
153 std::forward<Func &&>(func), post_order_traversal);
160 cross_query_blocks, std::forward<Func &&>(func),
161 post_order_traversal);
166 std::forward<Func &&>(func), post_order_traversal);
168 path->materialize().param->query_blocks) {
171 query_block.join ==
join)) {
173 cross_query_blocks, std::forward<Func &&>(func),
174 post_order_traversal);
180 join, cross_query_blocks, std::forward<Func &&>(func),
181 post_order_traversal);
187 std::forward<Func &&>(func), post_order_traversal);
193 std::forward<Func &&>(func), post_order_traversal);
197 std::forward<Func &&>(func), post_order_traversal);
201 std::forward<Func &&>(func), post_order_traversal);
205 cross_query_blocks, std::forward<Func &&>(func),
206 post_order_traversal);
210 std::forward<Func &&>(func), post_order_traversal);
214 std::forward<Func &&>(func), post_order_traversal);
219 std::forward<Func &&>(func), post_order_traversal);
225 std::forward<Func &&>(func), post_order_traversal);
231 std::forward<Func &&>(func), post_order_traversal);
236 std::forward<Func &&>(func), post_order_traversal);
240 std::forward<Func &&>(func), post_order_traversal);
243 if (post_order_traversal) {
261 bool include_pruned_tables) {
266 switch (
path->type) {
267 case AccessPath::TABLE_SCAN:
268 return func(path->table_scan().table);
269 case AccessPath::INDEX_SCAN:
270 return func(path->index_scan().table);
271 case AccessPath::REF:
272 return func(path->ref().table);
273 case AccessPath::REF_OR_NULL:
274 return func(path->ref_or_null().table);
275 case AccessPath::EQ_REF:
276 return func(path->eq_ref().table);
277 case AccessPath::PUSHED_JOIN_REF:
278 return func(path->pushed_join_ref().table);
279 case AccessPath::FULL_TEXT_SEARCH:
280 return func(path->full_text_search().table);
281 case AccessPath::CONST_TABLE:
282 return func(path->const_table().table);
283 case AccessPath::MRR:
284 return func(path->mrr().table);
285 case AccessPath::FOLLOW_TAIL:
286 return func(path->follow_tail().table);
287 case AccessPath::INDEX_RANGE_SCAN:
288 return func(path->index_range_scan().used_key_part[0].field->table);
289 case AccessPath::INDEX_SKIP_SCAN:
290 return func(path->index_skip_scan().table);
291 case AccessPath::GROUP_INDEX_SKIP_SCAN:
292 return func(path->group_index_skip_scan().table);
293 case AccessPath::DYNAMIC_INDEX_RANGE_SCAN:
294 return func(path->dynamic_index_range_scan().table);
295 case AccessPath::STREAM:
296 return func(path->stream().table);
297 case AccessPath::MATERIALIZE:
298 return func(path->materialize().param->table);
299 case AccessPath::MATERIALIZED_TABLE_FUNCTION:
300 return func(path->materialized_table_function().table);
301 case AccessPath::ALTERNATIVE:
303 path->alternative().table_scan_path->table_scan().table);
304 case AccessPath::UNQUALIFIED_COUNT:
309 case AccessPath::ZERO_ROWS:
310 if (include_pruned_tables && path->zero_rows().child != nullptr) {
311 WalkTablesUnderAccessPath(path->zero_rows().child, func,
312 include_pruned_tables);
316 return func(
path->window().temp_table);
Definition: sql_optimizer.h:133
static char * path
Definition: mysqldump.cc:137
std::string join(Container cont, const std::string &delim)
join elements of an container into a string separated by a delimiter.
Definition: string.h:151
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:193
@ FOLLOW_TAIL
Definition: access_path.h:221
@ FILTER
Definition: access_path.h:245
@ PUSHED_JOIN_REF
Definition: access_path.h:217
@ ZERO_ROWS_AGGREGATED
Definition: access_path.h:234
@ UPDATE_ROWS
Definition: access_path.h:263
@ AGGREGATE
Definition: access_path.h:247
@ BKA_JOIN
Definition: access_path.h:241
@ ZERO_ROWS
Definition: access_path.h:233
@ CONST_TABLE
Definition: access_path.h:219
@ GROUP_INDEX_SKIP_SCAN
Definition: access_path.h:227
@ INDEX_RANGE_SCAN
Definition: access_path.h:222
@ UNQUALIFIED_COUNT
Definition: access_path.h:236
@ EQ_REF
Definition: access_path.h:216
@ FAKE_SINGLE_ROW
Definition: access_path.h:232
@ MATERIALIZE_INFORMATION_SCHEMA_TABLE
Definition: access_path.h:252
@ WINDOW
Definition: access_path.h:254
@ REF_OR_NULL
Definition: access_path.h:215
@ MATERIALIZE
Definition: access_path.h:251
@ NESTED_LOOP_SEMIJOIN_WITH_DUPLICATE_REMOVAL
Definition: access_path.h:240
@ ROWID_UNION
Definition: access_path.h:225
@ INDEX_SKIP_SCAN
Definition: access_path.h:226
@ MRR
Definition: access_path.h:220
@ CACHE_INVALIDATOR
Definition: access_path.h:259
@ INDEX_SCAN
Definition: access_path.h:213
@ TABLE_VALUE_CONSTRUCTOR
Definition: access_path.h:231
@ WEEDOUT
Definition: access_path.h:255
@ MATERIALIZED_TABLE_FUNCTION
Definition: access_path.h:235
@ REMOVE_DUPLICATES_ON_INDEX
Definition: access_path.h:257
@ TABLE_SCAN
Definition: access_path.h:212
@ REF
Definition: access_path.h:214
@ TEMPTABLE_AGGREGATE
Definition: access_path.h:248
@ LIMIT_OFFSET
Definition: access_path.h:249
@ APPEND
Definition: access_path.h:253
@ NESTED_LOOP_JOIN
Definition: access_path.h:239
@ INDEX_MERGE
Definition: access_path.h:223
@ FULL_TEXT_SEARCH
Definition: access_path.h:218
@ ALTERNATIVE
Definition: access_path.h:258
@ STREAM
Definition: access_path.h:250
@ REMOVE_DUPLICATES
Definition: access_path.h:256
@ ROWID_INTERSECTION
Definition: access_path.h:224
@ DYNAMIC_INDEX_RANGE_SCAN
Definition: access_path.h:228
@ DELETE_ROWS
Definition: access_path.h:262
@ SORT
Definition: access_path.h:246
@ HASH_JOIN
Definition: access_path.h:242
Definition: access_path.h:163
Definition: materialize_path_parameters.h:42
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:63
WalkAccessPathPolicy
Definition: walk_access_paths.h:32
@ STOP_AT_MATERIALIZATION
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 fun...
Definition: walk_access_paths.h:260