PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pgpa_walker.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pgpa_walker.h
4 * Main entrypoints for analyzing a plan to generate an advice string
5 *
6 * Copyright (c) 2016-2026, PostgreSQL Global Development Group
7 *
8 * contrib/pg_plan_advice/pgpa_walker.h
9 *
10 *-------------------------------------------------------------------------
11 */
12#ifndef PGPA_WALKER_H
13#define PGPA_WALKER_H
14
15#include "pgpa_ast.h"
16#include "pgpa_join.h"
17#include "pgpa_scan.h"
18
19/*
20 * We use the term "query feature" to refer to plan nodes that are interesting
21 * in the following way: to generate advice, we'll need to know the set of
22 * same-subquery, non-join RTIs occurring at or below that plan node, without
23 * admixture of parent and child RTIs.
24 *
25 * For example, Gather nodes, designated by PGPAQF_GATHER, and Gather Merge
26 * nodes, designated by PGPAQF_GATHER_MERGE, are query features, because we'll
27 * want to admit some kind of advice that describes the portion of the plan
28 * tree that appears beneath those nodes.
29 *
30 * Each semijoin can be implemented either by directly performing a semijoin,
31 * or by making one side unique and then performing a normal join. Either way,
32 * we use a query feature to notice what decision was made, so that we can
33 * describe it by enumerating the RTIs on that side of the join.
34 *
35 * To elaborate on the "no admixture of parent and child RTIs" rule, in all of
36 * these cases, if the entirety of an inheritance hierarchy appears beneath
37 * the query feature, we only want to name the parent table. But it's also
38 * possible to have cases where we must name child tables. This is particularly
39 * likely to happen when partitionwise join is in use, but could happen for
40 * Gather or Gather Merge even without that, if one of those appears below
41 * an Append or MergeAppend node for a single table.
42 */
43typedef enum pgpa_qf_type
44{
49 /* update NUM_PGPA_QF_TYPES if you add anything here */
51
52#define NUM_PGPA_QF_TYPES ((int) PGPAQF_SEMIJOIN_UNIQUE + 1)
53
54/*
55 * For each query feature, we keep track of the feature type and the set of
56 * relids that we found underneath the relevant plan node. See the comments
57 * on pgpa_qf_type, above, for additional details.
58 */
65
66/*
67 * Context object for plan tree walk.
68 *
69 * pstmt is the PlannedStmt we're studying.
70 *
71 * scans is an array of lists of pgpa_scan objects. The array is indexed by
72 * the scan's pgpa_scan_strategy.
73 *
74 * no_gather_scans is the set of scan RTIs that do not appear beneath any
75 * Gather or Gather Merge node.
76 *
77 * toplevel_unrolled_joins is a list of all pgpa_unrolled_join objects that
78 * are not a child of some other pgpa_unrolled_join.
79 *
80 * join_strategy is an array of lists of Bitmapset objects. Each Bitmapset
81 * is the set of relids that appears on the inner side of some join (excluding
82 * RTIs from partition children and subqueries). The array is indexed by
83 * pgpa_join_strategy.
84 *
85 * query_features is an array lists of pgpa_query_feature objects, indexed
86 * by pgpa_qf_type.
87 *
88 * future_query_features is only used during the plan tree walk and should
89 * be empty when the tree walk concludes. It is a list of pgpa_query_feature
90 * objects for Plan nodes that the plan tree walk has not yet encountered;
91 * when encountered, they will be moved to the list of active query features
92 * that is propagated via the call stack.
93 */
105
107 PlannedStmt *pstmt,
108 List *proots);
109
112 Plan *plan);
113
117extern Bitmapset *pgpa_filter_out_join_relids(Bitmapset *relids, List *rtable);
118
122 pgpa_advice_target *target);
123
124#endif
unsigned int Index
Definition c.h:698
#define plan(x)
Definition pg_regress.c:164
pgpa_advice_tag_type
Definition pgpa_ast.h:81
#define NUM_PGPA_JOIN_STRATEGY
Definition pgpa_join.h:38
#define NUM_PGPA_SCAN_STRATEGY
Definition pgpa_scan.h:68
Bitmapset * pgpa_filter_out_join_relids(Bitmapset *relids, List *rtable)
pgpa_qf_type
Definition pgpa_walker.h:44
@ PGPAQF_GATHER
Definition pgpa_walker.h:45
@ PGPAQF_GATHER_MERGE
Definition pgpa_walker.h:46
@ PGPAQF_SEMIJOIN_UNIQUE
Definition pgpa_walker.h:48
@ PGPAQF_SEMIJOIN_NON_UNIQUE
Definition pgpa_walker.h:47
void pgpa_plan_walker(pgpa_plan_walker_context *walker, PlannedStmt *pstmt, List *proots)
Definition pgpa_walker.c:76
Bitmapset * pgpa_relids(Plan *plan)
ElidedNode * pgpa_last_elided_node(PlannedStmt *pstmt, Plan *plan)
bool pgpa_walker_would_advise(pgpa_plan_walker_context *walker, pgpa_identifier *rt_identifiers, pgpa_advice_tag_type tag, pgpa_advice_target *target)
#define NUM_PGPA_QF_TYPES
Definition pgpa_walker.h:52
void pgpa_add_future_feature(pgpa_plan_walker_context *walker, pgpa_qf_type type, Plan *plan)
Index pgpa_scanrelid(Plan *plan)
static int fb(int x)
Definition pg_list.h:54
List * scans[NUM_PGPA_SCAN_STRATEGY]
Definition pgpa_walker.h:97
List * query_features[NUM_PGPA_QF_TYPES]
Bitmapset * no_gather_scans
Definition pgpa_walker.h:98
List * join_strategies[NUM_PGPA_JOIN_STRATEGY]
pgpa_qf_type type
Definition pgpa_walker.h:61
Bitmapset * relids
Definition pgpa_walker.h:63
const char * type