1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-18 04:29:09 +03:00

Rename CachedPlanType to PlannedStmtOrigin for PlannedStmt

Commit 719dcf3c42 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
This commit is contained in:
Michael Paquier
2025-07-31 10:06:34 +09:00
parent ee924698d5
commit e125e36002
9 changed files with 20 additions and 19 deletions

View File

@@ -1588,7 +1588,7 @@ ImportForeignSchema(ImportForeignSchemaStmt *stmt)
pstmt->utilityStmt = (Node *) cstmt;
pstmt->stmt_location = rs->stmt_location;
pstmt->stmt_len = rs->stmt_len;
pstmt->cached_plan_type = PLAN_CACHE_NONE;
pstmt->planOrigin = PLAN_STMT_INTERNAL;
/* Execute statement */
ProcessUtility(pstmt, cmd, false,

View File

@@ -215,7 +215,7 @@ CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString,
wrapper->utilityStmt = stmt;
wrapper->stmt_location = stmt_location;
wrapper->stmt_len = stmt_len;
wrapper->cached_plan_type = PLAN_CACHE_NONE;
wrapper->planOrigin = PLAN_STMT_INTERNAL;
/* do this step */
ProcessUtility(wrapper,

View File

@@ -189,7 +189,7 @@ ExecSerializePlan(Plan *plan, EState *estate)
pstmt->permInfos = estate->es_rteperminfos;
pstmt->resultRelations = NIL;
pstmt->appendRelations = NIL;
pstmt->cached_plan_type = PLAN_CACHE_NONE;
pstmt->planOrigin = PLAN_STMT_INTERNAL;
/*
* Transfer only parallel-safe subplans, leaving a NULL "hole" in the list

View File

@@ -558,6 +558,7 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
result->commandType = parse->commandType;
result->queryId = parse->queryId;
result->planOrigin = PLAN_STMT_STANDARD;
result->hasReturning = (parse->returningList != NIL);
result->hasModifyingCTE = parse->hasModifyingCTE;
result->canSetTag = parse->canSetTag;
@@ -582,7 +583,6 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
result->utilityStmt = parse->utilityStmt;
result->stmt_location = parse->stmt_location;
result->stmt_len = parse->stmt_len;
result->cached_plan_type = PLAN_CACHE_NONE;
result->jitFlags = PGJIT_NONE;
if (jit_enabled && jit_above_cost >= 0 &&

View File

@@ -988,7 +988,7 @@ pg_plan_queries(List *querytrees, const char *query_string, int cursorOptions,
stmt->stmt_location = query->stmt_location;
stmt->stmt_len = query->stmt_len;
stmt->queryId = query->queryId;
stmt->cached_plan_type = PLAN_CACHE_NONE;
stmt->planOrigin = PLAN_STMT_INTERNAL;
}
else
{

View File

@@ -1234,7 +1234,7 @@ ProcessUtilitySlow(ParseState *pstate,
wrapper->utilityStmt = stmt;
wrapper->stmt_location = pstmt->stmt_location;
wrapper->stmt_len = pstmt->stmt_len;
wrapper->cached_plan_type = PLAN_CACHE_NONE;
wrapper->planOrigin = PLAN_STMT_INTERNAL;
ProcessUtility(wrapper,
queryString,
@@ -1965,7 +1965,7 @@ ProcessUtilityForAlterTable(Node *stmt, AlterTableUtilityContext *context)
wrapper->utilityStmt = stmt;
wrapper->stmt_location = context->pstmt->stmt_location;
wrapper->stmt_len = context->pstmt->stmt_len;
wrapper->cached_plan_type = PLAN_CACHE_NONE;
wrapper->planOrigin = PLAN_STMT_INTERNAL;
ProcessUtility(wrapper,
context->queryString,

View File

@@ -1390,7 +1390,7 @@ GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams,
{
PlannedStmt *pstmt = (PlannedStmt *) lfirst(lc);
pstmt->cached_plan_type = customplan ? PLAN_CACHE_CUSTOM : PLAN_CACHE_GENERIC;
pstmt->planOrigin = customplan ? PLAN_STMT_CACHE_CUSTOM : PLAN_STMT_CACHE_GENERIC;
}
return plan;

View File

@@ -29,18 +29,19 @@
*/
/* ----------------
* CachedPlanType
* PlannedStmtOrigin
*
* CachedPlanType identifies whether a PlannedStmt is a cached plan, and if
* so, whether it is generic or custom.
* PlannedStmtOrigin identifies from where a PlannedStmt comes from.
* ----------------
*/
typedef enum CachedPlanType
typedef enum PlannedStmtOrigin
{
PLAN_CACHE_NONE = 0, /* Not a cached plan */
PLAN_CACHE_GENERIC, /* Generic cached plan */
PLAN_CACHE_CUSTOM, /* Custom cached plan */
} CachedPlanType;
PLAN_STMT_UNKNOWN = 0, /* plan origin is not yet known */
PLAN_STMT_INTERNAL, /* generated internally by a query */
PLAN_STMT_STANDARD, /* standard planned statement */
PLAN_STMT_CACHE_GENERIC, /* Generic cached plan */
PLAN_STMT_CACHE_CUSTOM, /* Custom cached plan */
} PlannedStmtOrigin;
/* ----------------
* PlannedStmt node
@@ -72,8 +73,8 @@ typedef struct PlannedStmt
/* plan identifier (can be set by plugins) */
int64 planId;
/* type of cached plan */
CachedPlanType cached_plan_type;
/* origin of plan */
PlannedStmtOrigin planOrigin;
/* is it insert|update|delete|merge RETURNING? */
bool hasReturning;

View File

@@ -391,7 +391,6 @@ CachedFunctionHashEntry
CachedFunctionHashKey
CachedPlan
CachedPlanSource
CachedPlanType
CallContext
CallStmt
CancelRequestPacket
@@ -2276,6 +2275,7 @@ PlanInvalItem
PlanRowMark
PlanState
PlannedStmt
PlannedStmtOrigin
PlannerGlobal
PlannerInfo
PlannerParamItem