Skip to content

Commit 336fb9c

Browse files
committed
Store the total number of plans in PlannedStmt.
Extensions that use planner/executor hooks can't precisely pre-allocate memory for data structures mirroring the plan as the number of plan nodes is unknown. This information is effectively collected in the standard planner in the node id counter but was thrown out at the end. This change preserves this information.
1 parent 0a8ca12 commit 336fb9c

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/backend/optimizer/plan/planner.c

+1
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
555555
result->relationOids = glob->relationOids;
556556
result->invalItems = glob->invalItems;
557557
result->paramExecTypes = glob->paramExecTypes;
558+
result->total_plans = glob->lastPlanNodeId + 1;
558559
/* utilityStmt should be null, but we might as well copy it */
559560
result->utilityStmt = parse->utilityStmt;
560561
result->stmt_location = parse->stmt_location;

src/include/nodes/plannodes.h

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ typedef struct PlannedStmt
9797
/* statement location in source string (copied from Query) */
9898
ParseLoc stmt_location; /* start location, or -1 if unknown */
9999
ParseLoc stmt_len; /* length in bytes; 0 means "rest of string" */
100+
101+
int total_plans; /* indicates the number of plan nodes in the statement */
100102
} PlannedStmt;
101103

102104
/* macro for fetching the Plan associated with a SubPlan node */

0 commit comments

Comments
 (0)