Skip to content

Commit

Permalink
Store the total number of plans in PlannedStmt.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yrashk committed Jul 16, 2024
1 parent 0a8ca12 commit 336fb9c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/backend/optimizer/plan/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
result->relationOids = glob->relationOids;
result->invalItems = glob->invalItems;
result->paramExecTypes = glob->paramExecTypes;
result->total_plans = glob->lastPlanNodeId + 1;
/* utilityStmt should be null, but we might as well copy it */
result->utilityStmt = parse->utilityStmt;
result->stmt_location = parse->stmt_location;
Expand Down
2 changes: 2 additions & 0 deletions src/include/nodes/plannodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ typedef struct PlannedStmt
/* statement location in source string (copied from Query) */
ParseLoc stmt_location; /* start location, or -1 if unknown */
ParseLoc stmt_len; /* length in bytes; 0 means "rest of string" */

int total_plans; /* indicates the number of plan nodes in the statement */
} PlannedStmt;

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

0 comments on commit 336fb9c

Please sign in to comment.