23#ifndef SQL_JOIN_OPTIMIZER_WALK_ACCESS_PATHS_H
24#define SQL_JOIN_OPTIMIZER_WALK_ACCESS_PATHS_H
61template <
class AccessPathPtr,
class Func,
class JoinPtr>
64 bool post_order_traversal =
false) {
66 std::is_convertible<AccessPathPtr, const AccessPath *>::value,
67 "The “path” argument must be AccessPath * or const AccessPath *.");
69 std::is_convertible<JoinPtr, const JOIN *>::value,
70 "The “join” argument must be JOIN * or const JOIN * (or nullptr).");
73 assert(
join !=
nullptr);
75 if (!post_order_traversal) {
106 std::forward<Func &&>(func), post_order_traversal);
108 std::forward<Func &&>(func), post_order_traversal);
112 join, cross_query_blocks, std::forward<Func &&>(func),
113 post_order_traversal);
115 join, cross_query_blocks, std::forward<Func &&>(func),
116 post_order_traversal);
120 std::forward<Func &&>(func), post_order_traversal);
122 std::forward<Func &&>(func), post_order_traversal);
126 std::forward<Func &&>(func), post_order_traversal);
128 std::forward<Func &&>(func), post_order_traversal);
132 std::forward<Func &&>(func), post_order_traversal);
136 std::forward<Func &&>(func), post_order_traversal);
140 std::forward<Func &&>(func), post_order_traversal);
144 cross_query_blocks, std::forward<Func &&>(func),
145 post_order_traversal);
147 cross_query_blocks, std::forward<Func &&>(func),
148 post_order_traversal);
152 std::forward<Func &&>(func), post_order_traversal);
159 cross_query_blocks, std::forward<Func &&>(func),
160 post_order_traversal);
165 std::forward<Func &&>(func), post_order_traversal);
167 path->materialize().param->m_operands) {
170 operand.join ==
join)) {
172 cross_query_blocks, std::forward<Func &&>(func),
173 post_order_traversal);
179 join, cross_query_blocks, std::forward<Func &&>(func),
180 post_order_traversal);
186 std::forward<Func &&>(func), post_order_traversal);
192 std::forward<Func &&>(func), post_order_traversal);
196 std::forward<Func &&>(func), post_order_traversal);
200 std::forward<Func &&>(func), post_order_traversal);
204 cross_query_blocks, std::forward<Func &&>(func),
205 post_order_traversal);
209 std::forward<Func &&>(func), post_order_traversal);
213 std::forward<Func &&>(func), post_order_traversal);
218 std::forward<Func &&>(func), post_order_traversal);
224 std::forward<Func &&>(func), post_order_traversal);
230 std::forward<Func &&>(func), post_order_traversal);
235 std::forward<Func &&>(func), post_order_traversal);
239 std::forward<Func &&>(func), post_order_traversal);
242 if (post_order_traversal) {
260 bool include_pruned_tables) {
265 switch (
path->type) {
266 case AccessPath::TABLE_SCAN:
267 return func(path->table_scan().table);
268 case AccessPath::INDEX_SCAN:
269 return func(path->index_scan().table);
270 case AccessPath::REF:
271 return func(path->ref().table);
272 case AccessPath::REF_OR_NULL:
273 return func(path->ref_or_null().table);
274 case AccessPath::EQ_REF:
275 return func(path->eq_ref().table);
276 case AccessPath::PUSHED_JOIN_REF:
277 return func(path->pushed_join_ref().table);
278 case AccessPath::FULL_TEXT_SEARCH:
279 return func(path->full_text_search().table);
280 case AccessPath::CONST_TABLE:
281 return func(path->const_table().table);
282 case AccessPath::MRR:
283 return func(path->mrr().table);
284 case AccessPath::FOLLOW_TAIL:
285 return func(path->follow_tail().table);
286 case AccessPath::INDEX_RANGE_SCAN:
287 return func(path->index_range_scan().used_key_part[0].field->table);
288 case AccessPath::INDEX_SKIP_SCAN:
289 return func(path->index_skip_scan().table);
290 case AccessPath::GROUP_INDEX_SKIP_SCAN:
291 return func(path->group_index_skip_scan().table);
292 case AccessPath::DYNAMIC_INDEX_RANGE_SCAN:
293 return func(path->dynamic_index_range_scan().table);
294 case AccessPath::STREAM:
295 return func(path->stream().table);
296 case AccessPath::MATERIALIZE:
297 return func(path->materialize().param->table);
298 case AccessPath::MATERIALIZED_TABLE_FUNCTION:
299 return func(path->materialized_table_function().table);
300 case AccessPath::ALTERNATIVE:
302 path->alternative().table_scan_path->table_scan().table);
303 case AccessPath::UNQUALIFIED_COUNT:
308 case AccessPath::ZERO_ROWS:
309 if (include_pruned_tables && path->zero_rows().child != nullptr) {
310 WalkTablesUnderAccessPath(path->zero_rows().child, func,
311 include_pruned_tables);
315 return func(
path->window().temp_table);
Definition: sql_optimizer.h:132
static char * path
Definition: mysqldump.cc:148
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: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:41
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:62
WalkAccessPathPolicy
Definition: walk_access_paths.h:31
@ 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:259