Invent QSRC_DUMMY for when we create a mostly-dummy planner state.
authorRobert Haas <rhaas@postgresql.org>
Wed, 30 Jul 2025 16:17:56 +0000 (12:17 -0400)
committerRobert Haas <rhaas@postgresql.org>
Thu, 31 Jul 2025 15:53:31 +0000 (11:53 -0400)
Peviously, plan_cluster_use_sort() and plan_create_index_workers()
did nothing to make the dummy Query object that they generate look
any different from a user-supplied query. This is inconvenient for
exensions that use both get_relation_info_hook and planner_hook, as
there's no easy way to figure out whether a call to get_relation_info
is associated with the most recent planner invocation, or whether
it's the result of an intervening call to one of these functions.
This makes it easy to tell the difference.

src/backend/optimizer/plan/planner.c
src/include/nodes/parsenodes.h

index 89bfce9602f22778553fe03b8289a3e645d54b01..542c4db88cb9aa59e5dc5301e19c5954c8e6ec40 100644 (file)
@@ -6787,6 +6787,7 @@ plan_cluster_use_sort(Oid tableOid, Oid indexOid)
        /* Set up mostly-dummy planner state */
        query = makeNode(Query);
        query->commandType = CMD_SELECT;
+       query->querySource = QSRC_DUMMY;
 
        glob = makeNode(PlannerGlobal);
 
@@ -6911,6 +6912,7 @@ plan_create_index_workers(Oid tableOid, Oid indexOid)
        /* Set up largely-dummy planner state */
        query = makeNode(Query);
        query->commandType = CMD_SELECT;
+       query->querySource = QSRC_DUMMY;
 
        glob = makeNode(PlannerGlobal);
 
index 86a236bd58b1abde2f7c053295777fac68ace651..c1cc3bd9b72dc0348d7fbb13e3ad97e2d432b06c 100644 (file)
@@ -38,6 +38,7 @@ typedef enum QuerySource
        QSRC_INSTEAD_RULE,                      /* added by unconditional INSTEAD rule */
        QSRC_QUAL_INSTEAD_RULE,         /* added by conditional INSTEAD rule */
        QSRC_NON_INSTEAD_RULE,          /* added by non-INSTEAD rule */
+       QSRC_DUMMY                                      /* internally-generated dummy query */
 } QuerySource;
 
 /* Sort ordering options for ORDER BY and CREATE INDEX */