Skip to content

Commit e125e36

Browse files
michaelpqsamimseih
andcommitted
Rename CachedPlanType to PlannedStmtOrigin for PlannedStmt
Commit 719dcf3 introduced a field called CachedPlanType in PlannedStmt to allow extensions to determine whether a cached plan is generic or custom. After discussion, the concepts that we want to track are a bit wider than initially anticipated, as it is closer to knowing from which "source" or "origin" a PlannedStmt has been generated or retrieved. Custom and generic cached plans are a subset of that. Based on the state of HEAD, we have been able to define two more origins: - "standard", for the case where PlannedStmt is generated in standard_planner(), the most common case. - "internal", for the fake PlannedStmt generated internally by some query patterns. This could be tuned in the future depending on what is needed. This looks like a good starting point, at least. The default value is called "UNKNOWN", provided as fallback value. This value is not used in the core code, the idea is to let extensions building their own PlannedStmts know about this new field. Author: Michael Paquier <michael@paquier.xyz> Co-authored-by: Sami Imseih <samimseih@gmail.com> Discussion: https://postgr.es/m/aILaHupXbIGgF2wJ@paquier.xyz
1 parent ee92469 commit e125e36

File tree

9 files changed

+20
-19
lines changed

9 files changed

+20
-19
lines changed

src/backend/commands/foreigncmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ ImportForeignSchema(ImportForeignSchemaStmt *stmt)
15881588
pstmt->utilityStmt = (Node *) cstmt;
15891589
pstmt->stmt_location = rs->stmt_location;
15901590
pstmt->stmt_len = rs->stmt_len;
1591-
pstmt->cached_plan_type = PLAN_CACHE_NONE;
1591+
pstmt->planOrigin = PLAN_STMT_INTERNAL;
15921592

15931593
/* Execute statement */
15941594
ProcessUtility(pstmt, cmd, false,

src/backend/commands/schemacmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString,
215215
wrapper->utilityStmt = stmt;
216216
wrapper->stmt_location = stmt_location;
217217
wrapper->stmt_len = stmt_len;
218-
wrapper->cached_plan_type = PLAN_CACHE_NONE;
218+
wrapper->planOrigin = PLAN_STMT_INTERNAL;
219219

220220
/* do this step */
221221
ProcessUtility(wrapper,

src/backend/executor/execParallel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ ExecSerializePlan(Plan *plan, EState *estate)
189189
pstmt->permInfos = estate->es_rteperminfos;
190190
pstmt->resultRelations = NIL;
191191
pstmt->appendRelations = NIL;
192-
pstmt->cached_plan_type = PLAN_CACHE_NONE;
192+
pstmt->planOrigin = PLAN_STMT_INTERNAL;
193193

194194
/*
195195
* Transfer only parallel-safe subplans, leaving a NULL "hole" in the list

src/backend/optimizer/plan/planner.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
558558

559559
result->commandType = parse->commandType;
560560
result->queryId = parse->queryId;
561+
result->planOrigin = PLAN_STMT_STANDARD;
561562
result->hasReturning = (parse->returningList != NIL);
562563
result->hasModifyingCTE = parse->hasModifyingCTE;
563564
result->canSetTag = parse->canSetTag;
@@ -582,7 +583,6 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
582583
result->utilityStmt = parse->utilityStmt;
583584
result->stmt_location = parse->stmt_location;
584585
result->stmt_len = parse->stmt_len;
585-
result->cached_plan_type = PLAN_CACHE_NONE;
586586

587587
result->jitFlags = PGJIT_NONE;
588588
if (jit_enabled && jit_above_cost >= 0 &&

src/backend/tcop/postgres.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ pg_plan_queries(List *querytrees, const char *query_string, int cursorOptions,
988988
stmt->stmt_location = query->stmt_location;
989989
stmt->stmt_len = query->stmt_len;
990990
stmt->queryId = query->queryId;
991-
stmt->cached_plan_type = PLAN_CACHE_NONE;
991+
stmt->planOrigin = PLAN_STMT_INTERNAL;
992992
}
993993
else
994994
{

src/backend/tcop/utility.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ ProcessUtilitySlow(ParseState *pstate,
12341234
wrapper->utilityStmt = stmt;
12351235
wrapper->stmt_location = pstmt->stmt_location;
12361236
wrapper->stmt_len = pstmt->stmt_len;
1237-
wrapper->cached_plan_type = PLAN_CACHE_NONE;
1237+
wrapper->planOrigin = PLAN_STMT_INTERNAL;
12381238

12391239
ProcessUtility(wrapper,
12401240
queryString,
@@ -1965,7 +1965,7 @@ ProcessUtilityForAlterTable(Node *stmt, AlterTableUtilityContext *context)
19651965
wrapper->utilityStmt = stmt;
19661966
wrapper->stmt_location = context->pstmt->stmt_location;
19671967
wrapper->stmt_len = context->pstmt->stmt_len;
1968-
wrapper->cached_plan_type = PLAN_CACHE_NONE;
1968+
wrapper->planOrigin = PLAN_STMT_INTERNAL;
19691969

19701970
ProcessUtility(wrapper,
19711971
context->queryString,

src/backend/utils/cache/plancache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams,
13901390
{
13911391
PlannedStmt *pstmt = (PlannedStmt *) lfirst(lc);
13921392

1393-
pstmt->cached_plan_type = customplan ? PLAN_CACHE_CUSTOM : PLAN_CACHE_GENERIC;
1393+
pstmt->planOrigin = customplan ? PLAN_STMT_CACHE_CUSTOM : PLAN_STMT_CACHE_GENERIC;
13941394
}
13951395

13961396
return plan;

src/include/nodes/plannodes.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@
2929
*/
3030

3131
/* ----------------
32-
* CachedPlanType
32+
* PlannedStmtOrigin
3333
*
34-
* CachedPlanType identifies whether a PlannedStmt is a cached plan, and if
35-
* so, whether it is generic or custom.
34+
* PlannedStmtOrigin identifies from where a PlannedStmt comes from.
3635
* ----------------
3736
*/
38-
typedef enum CachedPlanType
37+
typedef enum PlannedStmtOrigin
3938
{
40-
PLAN_CACHE_NONE = 0, /* Not a cached plan */
41-
PLAN_CACHE_GENERIC, /* Generic cached plan */
42-
PLAN_CACHE_CUSTOM, /* Custom cached plan */
43-
} CachedPlanType;
39+
PLAN_STMT_UNKNOWN = 0, /* plan origin is not yet known */
40+
PLAN_STMT_INTERNAL, /* generated internally by a query */
41+
PLAN_STMT_STANDARD, /* standard planned statement */
42+
PLAN_STMT_CACHE_GENERIC, /* Generic cached plan */
43+
PLAN_STMT_CACHE_CUSTOM, /* Custom cached plan */
44+
} PlannedStmtOrigin;
4445

4546
/* ----------------
4647
* PlannedStmt node
@@ -72,8 +73,8 @@ typedef struct PlannedStmt
7273
/* plan identifier (can be set by plugins) */
7374
int64 planId;
7475

75-
/* type of cached plan */
76-
CachedPlanType cached_plan_type;
76+
/* origin of plan */
77+
PlannedStmtOrigin planOrigin;
7778

7879
/* is it insert|update|delete|merge RETURNING? */
7980
bool hasReturning;

src/tools/pgindent/typedefs.list

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ CachedFunctionHashEntry
391391
CachedFunctionHashKey
392392
CachedPlan
393393
CachedPlanSource
394-
CachedPlanType
395394
CallContext
396395
CallStmt
397396
CancelRequestPacket
@@ -2276,6 +2275,7 @@ PlanInvalItem
22762275
PlanRowMark
22772276
PlanState
22782277
PlannedStmt
2278+
PlannedStmtOrigin
22792279
PlannerGlobal
22802280
PlannerInfo
22812281
PlannerParamItem

0 commit comments

Comments
 (0)