24#ifndef SQL_JOIN_OPTIMIZER_WALK_ACCESS_PATHS_H
25#define SQL_JOIN_OPTIMIZER_WALK_ACCESS_PATHS_H
63template <
class AccessPathPtr,
class Func,
class JoinPtr>
66 bool post_order_traversal =
false) {
68 std::is_convertible<AccessPathPtr, const AccessPath *>::value,
69 "The “path” argument must be AccessPath * or const AccessPath *.");
71 std::is_convertible<JoinPtr, const JOIN *>::value,
72 "The “join” argument must be JOIN * or const JOIN * (or nullptr).");
75 assert(
join !=
nullptr);
77 if (!post_order_traversal) {
110 std::forward<Func &&>(func), post_order_traversal);
112 std::forward<Func &&>(func), post_order_traversal);
116 join, cross_query_blocks, std::forward<Func &&>(func),
117 post_order_traversal);
119 join, cross_query_blocks, std::forward<Func &&>(func),
120 post_order_traversal);
124 std::forward<Func &&>(func), post_order_traversal);
126 std::forward<Func &&>(func), post_order_traversal);
130 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 std::forward<Func &&>(func), post_order_traversal);
149 path->temptable_aggregate().join ==
join)) {
151 cross_query_blocks, std::forward<Func &&>(func),
152 post_order_traversal);
155 cross_query_blocks, std::forward<Func &&>(func),
156 post_order_traversal);
160 std::forward<Func &&>(func), post_order_traversal);
167 cross_query_blocks, std::forward<Func &&>(func),
168 post_order_traversal);
173 std::forward<Func &&>(func), post_order_traversal);
175 path->materialize().param->m_operands) {
178 operand.join ==
join)) {
180 cross_query_blocks, std::forward<Func &&>(func),
181 post_order_traversal);
187 join, cross_query_blocks, std::forward<Func &&>(func),
188 post_order_traversal);
194 std::forward<Func &&>(func), post_order_traversal);
200 std::forward<Func &&>(func), post_order_traversal);
204 std::forward<Func &&>(func), post_order_traversal);
208 std::forward<Func &&>(func), post_order_traversal);
212 cross_query_blocks, std::forward<Func &&>(func),
213 post_order_traversal);
217 std::forward<Func &&>(func), post_order_traversal);
221 std::forward<Func &&>(func), post_order_traversal);
226 std::forward<Func &&>(func), post_order_traversal);
232 std::forward<Func &&>(func), post_order_traversal);
238 std::forward<Func &&>(func), post_order_traversal);
243 std::forward<Func &&>(func), post_order_traversal);
247 std::forward<Func &&>(func), post_order_traversal);
250 if (post_order_traversal) {
268 bool include_pruned_tables) {
273 switch (
path->type) {
274 case AccessPath::TABLE_SCAN:
275 return func(path->table_scan().table);
276 case AccessPath::SAMPLE_SCAN:
279 case AccessPath::INDEX_SCAN:
280 return func(path->index_scan().table);
281 case AccessPath::INDEX_DISTANCE_SCAN:
282 return func(path->index_distance_scan().table);
283 case AccessPath::REF:
284 return func(path->ref().table);
285 case AccessPath::REF_OR_NULL:
286 return func(path->ref_or_null().table);
287 case AccessPath::EQ_REF:
288 return func(path->eq_ref().table);
289 case AccessPath::PUSHED_JOIN_REF:
290 return func(path->pushed_join_ref().table);
291 case AccessPath::FULL_TEXT_SEARCH:
292 return func(path->full_text_search().table);
293 case AccessPath::CONST_TABLE:
294 return func(path->const_table().table);
295 case AccessPath::MRR:
296 return func(path->mrr().table);
297 case AccessPath::FOLLOW_TAIL:
298 return func(path->follow_tail().table);
299 case AccessPath::INDEX_RANGE_SCAN:
300 return func(path->index_range_scan().used_key_part[0].field->table);
301 case AccessPath::INDEX_SKIP_SCAN:
302 return func(path->index_skip_scan().table);
303 case AccessPath::GROUP_INDEX_SKIP_SCAN:
304 return func(path->group_index_skip_scan().table);
305 case AccessPath::DYNAMIC_INDEX_RANGE_SCAN:
306 return func(path->dynamic_index_range_scan().table);
307 case AccessPath::STREAM:
308 return func(path->stream().table);
309 case AccessPath::MATERIALIZED_TABLE_FUNCTION:
310 return func(path->materialized_table_function().table);
311 case AccessPath::ALTERNATIVE:
313 path->alternative().table_scan_path->table_scan().table);
314 case AccessPath::UNQUALIFIED_COUNT:
319 case AccessPath::ZERO_ROWS:
320 if (include_pruned_tables && path->zero_rows().child != nullptr) {
321 WalkTablesUnderAccessPath(path->zero_rows().child, func,
322 include_pruned_tables);
326 return func(
path->window().temp_table);
Definition: sql_optimizer.h:133
static char * path
Definition: mysqldump.cc:149
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:213
@ FOLLOW_TAIL
Definition: access_path.h:244
@ FILTER
Definition: access_path.h:268
@ PUSHED_JOIN_REF
Definition: access_path.h:240
@ ZERO_ROWS_AGGREGATED
Definition: access_path.h:257
@ UPDATE_ROWS
Definition: access_path.h:286
@ AGGREGATE
Definition: access_path.h:270
@ BKA_JOIN
Definition: access_path.h:264
@ ZERO_ROWS
Definition: access_path.h:256
@ CONST_TABLE
Definition: access_path.h:242
@ GROUP_INDEX_SKIP_SCAN
Definition: access_path.h:250
@ SAMPLE_SCAN
Definition: access_path.h:234
@ INDEX_RANGE_SCAN
Definition: access_path.h:245
@ UNQUALIFIED_COUNT
Definition: access_path.h:259
@ EQ_REF
Definition: access_path.h:239
@ FAKE_SINGLE_ROW
Definition: access_path.h:255
@ MATERIALIZE_INFORMATION_SCHEMA_TABLE
Definition: access_path.h:275
@ WINDOW
Definition: access_path.h:277
@ REF_OR_NULL
Definition: access_path.h:238
@ MATERIALIZE
Definition: access_path.h:274
@ NESTED_LOOP_SEMIJOIN_WITH_DUPLICATE_REMOVAL
Definition: access_path.h:263
@ ROWID_UNION
Definition: access_path.h:248
@ INDEX_SKIP_SCAN
Definition: access_path.h:249
@ MRR
Definition: access_path.h:243
@ CACHE_INVALIDATOR
Definition: access_path.h:282
@ INDEX_SCAN
Definition: access_path.h:235
@ TABLE_VALUE_CONSTRUCTOR
Definition: access_path.h:254
@ WEEDOUT
Definition: access_path.h:278
@ MATERIALIZED_TABLE_FUNCTION
Definition: access_path.h:258
@ REMOVE_DUPLICATES_ON_INDEX
Definition: access_path.h:280
@ TABLE_SCAN
Definition: access_path.h:233
@ REF
Definition: access_path.h:237
@ TEMPTABLE_AGGREGATE
Definition: access_path.h:271
@ LIMIT_OFFSET
Definition: access_path.h:272
@ APPEND
Definition: access_path.h:276
@ NESTED_LOOP_JOIN
Definition: access_path.h:262
@ INDEX_MERGE
Definition: access_path.h:246
@ FULL_TEXT_SEARCH
Definition: access_path.h:241
@ ALTERNATIVE
Definition: access_path.h:281
@ STREAM
Definition: access_path.h:273
@ REMOVE_DUPLICATES
Definition: access_path.h:279
@ ROWID_INTERSECTION
Definition: access_path.h:247
@ DYNAMIC_INDEX_RANGE_SCAN
Definition: access_path.h:251
@ DELETE_ROWS
Definition: access_path.h:285
@ SORT
Definition: access_path.h:269
@ INDEX_DISTANCE_SCAN
Definition: access_path.h:236
@ HASH_JOIN
Definition: access_path.h:265
Definition: access_path.h:178
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:64
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:267