]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Rename CachedPlanType to PlannedStmtOrigin for PlannedStmt
authorMichael Paquier <michael@paquier.xyz>
Thu, 31 Jul 2025 01:06:34 +0000 (10:06 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 31 Jul 2025 01:06:34 +0000 (10:06 +0900)
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

src/backend/commands/foreigncmds.c
src/backend/commands/schemacmds.c
src/backend/executor/execParallel.c
src/backend/optimizer/plan/planner.c
src/backend/tcop/postgres.c
src/backend/tcop/utility.c
src/backend/utils/cache/plancache.c
src/include/nodes/plannodes.h
src/tools/pgindent/typedefs.list

index fcd5fcd8915e3ddf489c62b02f34f5702b722ed9..77f8461f42eee8ee5c46021f67f3916d31d9e1de 100644 (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,
index c00f1a11384f10a207dc6ffc8fc9816e909c9e8a..0f03d9743d203d5231013661cb74b1cf0580991c 100644 (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,
index fc76f22fb8238dc275a176424bd36a3f67cf9572..f098a5557cf07fb51d3c39865d5de25ccf6519a9 100644 (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
index a77b2147e9592851cde1f44f99af059011adcd53..d59d6e4c6a021b7f16f1030ae3f6fe5961b2f8da 100644 (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 &&
index a297606cdd7fafb08ea5f8d49aeeece2f646ffb6..0cecd4649020ff1c8e28aac387d9dedcc5bfe421 100644 (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
                {
index babc34d0cbe1d8801333838698c106b5be943076..4f4191b0ea6b474248bd31a67c51fd64b329ea7a 100644 (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,
index f4d2b9458a5eada131237721ee333f26f6fe8e33..0c506d320b137a74097b906ebb6eca2ce3ef2f10 100644 (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;
index 6d8e1e99db3bd4ddf3b52ca5e7c515ea722dfb6a..29d7732d6a03198909f26ec8afb752e29ebc0bb2 100644 (file)
  */
 
 /* ----------------
- *             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;
index 3daba26b23723754481bca28d093f7b2b16d0f2d..e6f2e93b2d6faca0eb68ada2eb130bcd0deb4bd1 100644 (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