From da8d2f225d0fc42bdecad87f55a7e86518c068cc Mon Sep 17 00:00:00 2001 From: Melanie Plageman Date: Wed, 3 Dec 2025 15:07:24 -0500 Subject: [PATCH v31 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 797d8b1ca1c..9df7df17e96 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 fdc65c2b42b..28a06dcd244 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 3968429f991..13b42b5e6d1 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