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
*/
43
typedef
enum
pgpa_qf_type
44
{
45
PGPAQF_GATHER
,
46
PGPAQF_GATHER_MERGE
,
47
PGPAQF_SEMIJOIN_NON_UNIQUE
,
48
PGPAQF_SEMIJOIN_UNIQUE
49
/* update NUM_PGPA_QF_TYPES if you add anything here */
50
}
pgpa_qf_type
;
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
*/
59
typedef
struct
pgpa_query_feature
60
{
61
pgpa_qf_type
type
;
62
Plan
*
plan
;
63
Bitmapset
*
relids
;
64
}
pgpa_query_feature
;
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
*/
94
typedef
struct
pgpa_plan_walker_context
95
{
96
PlannedStmt
*
pstmt
;
97
List
*
scans
[
NUM_PGPA_SCAN_STRATEGY
];
98
Bitmapset
*
no_gather_scans
;
99
List
*
toplevel_unrolled_joins
;
100
List
*
join_strategies
[
NUM_PGPA_JOIN_STRATEGY
];
101
List
*
query_features
[
NUM_PGPA_QF_TYPES
];
102
List
*
future_query_features
;
103
List
*
do_not_scan_identifiers
;
104
}
pgpa_plan_walker_context
;
105
106
extern
void
pgpa_plan_walker
(
pgpa_plan_walker_context
*
walker
,
107
PlannedStmt
*pstmt,
108
List
*proots);
109
110
extern
void
pgpa_add_future_feature
(
pgpa_plan_walker_context
*
walker
,
111
pgpa_qf_type
type
,
112
Plan
*
plan
);
113
114
extern
ElidedNode
*
pgpa_last_elided_node
(
PlannedStmt
*pstmt,
Plan
*
plan
);
115
extern
Bitmapset
*
pgpa_relids
(
Plan
*
plan
);
116
extern
Index
pgpa_scanrelid
(
Plan
*
plan
);
117
extern
Bitmapset
*
pgpa_filter_out_join_relids
(
Bitmapset
*relids,
List
*rtable);
118
119
extern
bool
pgpa_walker_would_advise
(
pgpa_plan_walker_context
*
walker
,
120
pgpa_identifier
*
rt_identifiers
,
121
pgpa_advice_tag_type
tag,
122
pgpa_advice_target
*target);
123
124
#endif
Index
unsigned int Index
Definition
c.h:698
plan
#define plan(x)
Definition
pg_regress.c:164
pgpa_ast.h
pgpa_advice_tag_type
pgpa_advice_tag_type
Definition
pgpa_ast.h:81
pgpa_join.h
NUM_PGPA_JOIN_STRATEGY
#define NUM_PGPA_JOIN_STRATEGY
Definition
pgpa_join.h:38
pgpa_scan.h
NUM_PGPA_SCAN_STRATEGY
#define NUM_PGPA_SCAN_STRATEGY
Definition
pgpa_scan.h:68
pgpa_filter_out_join_relids
Bitmapset * pgpa_filter_out_join_relids(Bitmapset *relids, List *rtable)
Definition
pgpa_walker.c:616
pgpa_qf_type
pgpa_qf_type
Definition
pgpa_walker.h:44
PGPAQF_GATHER
@ PGPAQF_GATHER
Definition
pgpa_walker.h:45
PGPAQF_GATHER_MERGE
@ PGPAQF_GATHER_MERGE
Definition
pgpa_walker.h:46
PGPAQF_SEMIJOIN_UNIQUE
@ PGPAQF_SEMIJOIN_UNIQUE
Definition
pgpa_walker.h:48
PGPAQF_SEMIJOIN_NON_UNIQUE
@ PGPAQF_SEMIJOIN_NON_UNIQUE
Definition
pgpa_walker.h:47
pgpa_plan_walker
void pgpa_plan_walker(pgpa_plan_walker_context *walker, PlannedStmt *pstmt, List *proots)
Definition
pgpa_walker.c:76
pgpa_relids
Bitmapset * pgpa_relids(Plan *plan)
Definition
pgpa_walker.c:566
pgpa_last_elided_node
ElidedNode * pgpa_last_elided_node(PlannedStmt *pstmt, Plan *plan)
Definition
pgpa_walker.c:549
pgpa_walker_would_advise
bool pgpa_walker_would_advise(pgpa_plan_walker_context *walker, pgpa_identifier *rt_identifiers, pgpa_advice_tag_type tag, pgpa_advice_target *target)
Definition
pgpa_walker.c:703
NUM_PGPA_QF_TYPES
#define NUM_PGPA_QF_TYPES
Definition
pgpa_walker.h:52
pgpa_add_future_feature
void pgpa_add_future_feature(pgpa_plan_walker_context *walker, pgpa_qf_type type, Plan *plan)
Definition
pgpa_walker.c:533
pgpa_scanrelid
Index pgpa_scanrelid(Plan *plan)
Definition
pgpa_walker.c:586
fb
static int fb(int x)
Definition
preproc-init.c:92
Bitmapset
Definition
bitmapset.h:50
ElidedNode
Definition
plannodes.h:1869
List
Definition
pg_list.h:54
Plan
Definition
plannodes.h:192
PlannedStmt
Definition
plannodes.h:60
pgpa_advice_target
Definition
pgpa_ast.h:48
pgpa_identifier
Definition
pgpa_identifier.h:20
pgpa_plan_walker_context
Definition
pgpa_walker.h:95
pgpa_plan_walker_context::scans
List * scans[NUM_PGPA_SCAN_STRATEGY]
Definition
pgpa_walker.h:97
pgpa_plan_walker_context::pstmt
PlannedStmt * pstmt
Definition
pgpa_walker.h:96
pgpa_plan_walker_context::query_features
List * query_features[NUM_PGPA_QF_TYPES]
Definition
pgpa_walker.h:101
pgpa_plan_walker_context::future_query_features
List * future_query_features
Definition
pgpa_walker.h:102
pgpa_plan_walker_context::no_gather_scans
Bitmapset * no_gather_scans
Definition
pgpa_walker.h:98
pgpa_plan_walker_context::do_not_scan_identifiers
List * do_not_scan_identifiers
Definition
pgpa_walker.h:103
pgpa_plan_walker_context::join_strategies
List * join_strategies[NUM_PGPA_JOIN_STRATEGY]
Definition
pgpa_walker.h:100
pgpa_plan_walker_context::toplevel_unrolled_joins
List * toplevel_unrolled_joins
Definition
pgpa_walker.h:99
pgpa_query_feature
Definition
pgpa_walker.h:60
pgpa_query_feature::type
pgpa_qf_type type
Definition
pgpa_walker.h:61
pgpa_query_feature::plan
Plan * plan
Definition
pgpa_walker.h:62
pgpa_query_feature::relids
Bitmapset * relids
Definition
pgpa_walker.h:63
type
const char * type
Definition
wait_event_funcs.c:28
contrib
pg_plan_advice
pgpa_walker.h
Generated on Fri Apr 3 2026 04:13:09 for PostgreSQL Source Code by
1.9.8