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) {
109 std::forward<Func &&>(func), post_order_traversal);
111 std::forward<Func &&>(func), post_order_traversal);
115 join, cross_query_blocks, std::forward<Func &&>(func),
116 post_order_traversal);
118 join, cross_query_blocks, std::forward<Func &&>(func),
119 post_order_traversal);
123 std::forward<Func &&>(func), post_order_traversal);
125 std::forward<Func &&>(func), post_order_traversal);
129 std::forward<Func &&>(func), post_order_traversal);
131 std::forward<Func &&>(func), post_order_traversal);
135 std::forward<Func &&>(func), post_order_traversal);
139 std::forward<Func &&>(func), post_order_traversal);
143 std::forward<Func &&>(func), post_order_traversal);
147 cross_query_blocks, std::forward<Func &&>(func),
148 post_order_traversal);
150 cross_query_blocks, std::forward<Func &&>(func),
151 post_order_traversal);
155 std::forward<Func &&>(func), post_order_traversal);
162 cross_query_blocks, std::forward<Func &&>(func),
163 post_order_traversal);
168 std::forward<Func &&>(func), post_order_traversal);
170 path->materialize().param->m_operands) {
173 operand.join ==
join)) {
175 cross_query_blocks, std::forward<Func &&>(func),
176 post_order_traversal);
182 join, cross_query_blocks, std::forward<Func &&>(func),
183 post_order_traversal);
189 std::forward<Func &&>(func), post_order_traversal);
195 std::forward<Func &&>(func), post_order_traversal);
199 std::forward<Func &&>(func), post_order_traversal);
203 std::forward<Func &&>(func), post_order_traversal);
207 cross_query_blocks, std::forward<Func &&>(func),
208 post_order_traversal);
212 std::forward<Func &&>(func), post_order_traversal);
216 std::forward<Func &&>(func), post_order_traversal);
221 std::forward<Func &&>(func), post_order_traversal);
227 std::forward<Func &&>(func), post_order_traversal);
233 std::forward<Func &&>(func), post_order_traversal);
238 std::forward<Func &&>(func), post_order_traversal);
242 std::forward<Func &&>(func), post_order_traversal);
245 if (post_order_traversal) {
263 bool include_pruned_tables) {
268 switch (
path->type) {
269 case AccessPath::TABLE_SCAN:
270 return func(path->table_scan().table);
271 case AccessPath::SAMPLE_SCAN:
274 case AccessPath::INDEX_SCAN:
275 return func(path->index_scan().table);
276 case AccessPath::INDEX_DISTANCE_SCAN:
277 return func(path->index_distance_scan().table);
278 case AccessPath::REF:
279 return func(path->ref().table);
280 case AccessPath::REF_OR_NULL:
281 return func(path->ref_or_null().table);
282 case AccessPath::EQ_REF:
283 return func(path->eq_ref().table);
284 case AccessPath::PUSHED_JOIN_REF:
285 return func(path->pushed_join_ref().table);
286 case AccessPath::FULL_TEXT_SEARCH:
287 return func(path->full_text_search().table);
288 case AccessPath::CONST_TABLE:
289 return func(path->const_table().table);
290 case AccessPath::MRR:
291 return func(path->mrr().table);
292 case AccessPath::FOLLOW_TAIL:
293 return func(path->follow_tail().table);
294 case AccessPath::INDEX_RANGE_SCAN:
295 return func(path->index_range_scan().used_key_part[0].field->table);
296 case AccessPath::INDEX_SKIP_SCAN:
297 return func(path->index_skip_scan().table);
298 case AccessPath::GROUP_INDEX_SKIP_SCAN:
299 return func(path->group_index_skip_scan().table);
300 case AccessPath::DYNAMIC_INDEX_RANGE_SCAN:
301 return func(path->dynamic_index_range_scan().table);
302 case AccessPath::STREAM:
303 return func(path->stream().table);
304 case AccessPath::MATERIALIZED_TABLE_FUNCTION:
305 return func(path->materialized_table_function().table);
306 case AccessPath::ALTERNATIVE:
308 path->alternative().table_scan_path->table_scan().table);
309 case AccessPath::UNQUALIFIED_COUNT:
314 case AccessPath::ZERO_ROWS:
315 if (include_pruned_tables && path->zero_rows().child != nullptr) {
316 WalkTablesUnderAccessPath(path->zero_rows().child, func,
317 include_pruned_tables);
321 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: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:262