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>
64 requires std::is_convertible_v<AccessPathPtr, const AccessPath *> &&
65 std::is_convertible_v<JoinPtr, const JOIN *> &&
66 std::is_invocable_r_v<bool, Func, AccessPathPtr, JoinPtr>
69 bool post_order_traversal =
false) {
71 assert(
join !=
nullptr);
74 if (!post_order_traversal) {
82 [&](
auto &&subpath,
auto &&subjoin) {
84 post_order_traversal);
87 if (post_order_traversal) {
108template <
class AccessPathPtr,
class Func,
class JoinPtr>
109 requires std::is_convertible_v<AccessPathPtr, const AccessPath *> &&
110 std::is_convertible_v<JoinPtr, const JOIN *> &&
111 std::is_invocable_v<Func, AccessPathPtr, JoinPtr>
115 assert(
join !=
nullptr);
118 switch (
path->type) {
144 func(
path->nested_loop_join().outer,
join);
145 func(
path->nested_loop_join().inner,
join);
148 func(
path->nested_loop_semijoin_with_duplicate_removal().outer,
join);
149 func(
path->nested_loop_semijoin_with_duplicate_removal().inner,
join);
156 func(
path->hash_join().inner,
join);
157 func(
path->hash_join().outer,
join);
166 func(
path->aggregate().child,
join);
171 path->temptable_aggregate().join ==
join)) {
172 func(
path->temptable_aggregate().subquery_path,
join);
174 func(
path->temptable_aggregate().table_path,
join);
177 func(
path->limit_offset().child,
join);
183 func(
path->stream().child,
path->stream().join);
187 func(
path->materialize().table_path,
join);
189 path->materialize().param->m_operands) {
192 operand.join ==
join)) {
193 func(operand.subquery_path, operand.join);
198 func(
path->materialize_information_schema_table().table_path,
join);
203 func(child.path, child.join);
214 func(
path->remove_duplicates().child,
join);
217 func(
path->remove_duplicates_on_index().child,
join);
220 func(
path->alternative().child,
join);
223 func(
path->cache_invalidator().child,
join);
241 func(
path->delete_rows().child,
join);
244 func(
path->update_rows().child,
join);
258 bool include_pruned_tables) {
263 switch (
path->type) {
264 case AccessPath::TABLE_SCAN:
265 return func(path->table_scan().table);
266 case AccessPath::SAMPLE_SCAN:
269 case AccessPath::INDEX_SCAN:
270 return func(path->index_scan().table);
271 case AccessPath::INDEX_DISTANCE_SCAN:
272 return func(path->index_distance_scan().table);
273 case AccessPath::REF:
274 return func(path->ref().table);
275 case AccessPath::REF_OR_NULL:
276 return func(path->ref_or_null().table);
277 case AccessPath::EQ_REF:
278 return func(path->eq_ref().table);
279 case AccessPath::PUSHED_JOIN_REF:
280 return func(path->pushed_join_ref().table);
281 case AccessPath::FULL_TEXT_SEARCH:
282 return func(path->full_text_search().table);
283 case AccessPath::CONST_TABLE:
284 return func(path->const_table().table);
285 case AccessPath::MRR:
286 return func(path->mrr().table);
287 case AccessPath::FOLLOW_TAIL:
288 return func(path->follow_tail().table);
289 case AccessPath::INDEX_RANGE_SCAN:
290 return func(path->index_range_scan().used_key_part[0].field->table);
291 case AccessPath::INDEX_SKIP_SCAN:
292 return func(path->index_skip_scan().table);
293 case AccessPath::GROUP_INDEX_SKIP_SCAN:
294 return func(path->group_index_skip_scan().table);
295 case AccessPath::DYNAMIC_INDEX_RANGE_SCAN:
296 return func(path->dynamic_index_range_scan().table);
297 case AccessPath::STREAM:
298 return func(path->stream().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:149
std::string join(const detail::range auto &rng, std::string_view delim)
join elements of a range into a string separated by a delimiter.
Definition: string.h:74
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:227
@ FOLLOW_TAIL
Definition: access_path.h:243
@ FILTER
Definition: access_path.h:267
@ PUSHED_JOIN_REF
Definition: access_path.h:239
@ ZERO_ROWS_AGGREGATED
Definition: access_path.h:256
@ UPDATE_ROWS
Definition: access_path.h:285
@ AGGREGATE
Definition: access_path.h:269
@ BKA_JOIN
Definition: access_path.h:263
@ ZERO_ROWS
Definition: access_path.h:255
@ CONST_TABLE
Definition: access_path.h:241
@ GROUP_INDEX_SKIP_SCAN
Definition: access_path.h:249
@ SAMPLE_SCAN
Definition: access_path.h:233
@ INDEX_RANGE_SCAN
Definition: access_path.h:244
@ UNQUALIFIED_COUNT
Definition: access_path.h:258
@ EQ_REF
Definition: access_path.h:238
@ FAKE_SINGLE_ROW
Definition: access_path.h:254
@ MATERIALIZE_INFORMATION_SCHEMA_TABLE
Definition: access_path.h:274
@ WINDOW
Definition: access_path.h:276
@ REF_OR_NULL
Definition: access_path.h:237
@ MATERIALIZE
Definition: access_path.h:273
@ NESTED_LOOP_SEMIJOIN_WITH_DUPLICATE_REMOVAL
Definition: access_path.h:262
@ ROWID_UNION
Definition: access_path.h:247
@ INDEX_SKIP_SCAN
Definition: access_path.h:248
@ MRR
Definition: access_path.h:242
@ CACHE_INVALIDATOR
Definition: access_path.h:281
@ INDEX_SCAN
Definition: access_path.h:234
@ TABLE_VALUE_CONSTRUCTOR
Definition: access_path.h:253
@ WEEDOUT
Definition: access_path.h:277
@ MATERIALIZED_TABLE_FUNCTION
Definition: access_path.h:257
@ REMOVE_DUPLICATES_ON_INDEX
Definition: access_path.h:279
@ TABLE_SCAN
Definition: access_path.h:232
@ REF
Definition: access_path.h:236
@ TEMPTABLE_AGGREGATE
Definition: access_path.h:270
@ LIMIT_OFFSET
Definition: access_path.h:271
@ APPEND
Definition: access_path.h:275
@ NESTED_LOOP_JOIN
Definition: access_path.h:261
@ INDEX_MERGE
Definition: access_path.h:245
@ FULL_TEXT_SEARCH
Definition: access_path.h:240
@ ALTERNATIVE
Definition: access_path.h:280
@ STREAM
Definition: access_path.h:272
@ REMOVE_DUPLICATES
Definition: access_path.h:278
@ ROWID_INTERSECTION
Definition: access_path.h:246
@ DYNAMIC_INDEX_RANGE_SCAN
Definition: access_path.h:250
@ DELETE_ROWS
Definition: access_path.h:284
@ SORT
Definition: access_path.h:268
@ INDEX_DISTANCE_SCAN
Definition: access_path.h:235
@ HASH_JOIN
Definition: access_path.h:264
Definition: access_path.h:179
Definition: materialize_path_parameters.h:42
void ForEachChild(AccessPathPtr path, JoinPtr join, WalkAccessPathPolicy cross_query_blocks, Func &&func)
Call a function on every immediate child of the given access path.
Definition: walk_access_paths.h:112
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:67
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:257