From bd5e3e9cb10858f4d18ea487d8bc98344afd8a5c Mon Sep 17 00:00:00 2001 From: Melanie Plageman Date: Wed, 3 Dec 2025 15:07:24 -0500 Subject: [PATCH v32 13/16] Track which relations are modified by a query Save the relids in a bitmap in the estate. A later commit will pass this information down to scan nodes to control whether or not the scan allows setting the visibility map while on-access pruning. We don't want to set the visibility map if the query is just going to modify the page immediately after. Reviewed-by: Chao Li --- src/backend/executor/execMain.c | 4 ++++ src/backend/executor/execUtils.c | 2 ++ src/include/nodes/execnodes.h | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index ca14cdabdd0..6a0283985c3 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -916,6 +916,10 @@ InitPlan(QueryDesc *queryDesc, int eflags) break; } + /* If it has a rowmark, the relation may be modified */ + estate->es_modified_relids = bms_add_member(estate->es_modified_relids, + rc->rti); + /* Check that relation is a legal target for marking */ if (relation) CheckValidRowMarkRel(relation, rc->markType); diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index cc3c5de71eb..dcb2ef2275c 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -893,6 +893,8 @@ ExecInitResultRelation(EState *estate, ResultRelInfo *resultRelInfo, estate->es_result_relations = (ResultRelInfo **) palloc0(estate->es_range_table_size * sizeof(ResultRelInfo *)); estate->es_result_relations[rti - 1] = resultRelInfo; + estate->es_modified_relids = bms_add_member(estate->es_modified_relids, + rti); /* * Saving in the list allows to avoid needlessly traversing the whole diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index 02265456978..29e2e2da7ea 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -676,6 +676,12 @@ typedef struct EState * ExecDoInitialPruning() */ const char *es_sourceText; /* Source text from QueryDesc */ + /* + * RT indexes of relations modified by the query through a + * UPDATE/DELETE/INSERT/MERGE or targeted by a SELECT FOR UPDATE. + */ + Bitmapset *es_modified_relids; + JunkFilter *es_junkFilter; /* top-level junk filter, if any */ /* If query can insert/delete tuples, the command ID to mark them with */ -- 2.43.0