From 7859c3ee10dbe81606241478ef085aeb7d45a95d Mon Sep 17 00:00:00 2001 From: amitlan Date: Mon, 13 Mar 2023 15:59:38 +0900 Subject: [PATCH v38 3/3] Track opened range table relations in a List in EState This makes ExecCloseRangeTableRelations faster when there are many relations in the range table but only a few are opened during execution, such as when run-time pruning kicks in on an Append containing 1000s of partition subplans. --- src/backend/executor/execMain.c | 9 +++++---- src/backend/executor/execUtils.c | 2 ++ src/include/nodes/execnodes.h | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 0366be9fd6..94f8324cff 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -1630,12 +1630,13 @@ ExecCloseResultRelations(EState *estate) void ExecCloseRangeTableRelations(EState *estate) { - int i; + ListCell *lc; - for (i = 0; i < estate->es_range_table_size; i++) + foreach(lc, estate->es_opened_relations) { - if (estate->es_relations[i]) - table_close(estate->es_relations[i], NoLock); + Relation rel = lfirst(lc); + + table_close(rel, NoLock); } } diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index a485e7dfc5..f7053072d9 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -829,6 +829,8 @@ ExecGetRangeTableRelation(EState *estate, Index rti) } estate->es_relations[rti - 1] = rel; + estate->es_opened_relations = lappend(estate->es_opened_relations, + rel); } return rel; diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index dfa72848c7..984fd2e423 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -619,6 +619,8 @@ typedef struct EState Index es_range_table_size; /* size of the range table arrays */ Relation *es_relations; /* Array of per-range-table-entry Relation * pointers, or NULL if not yet opened */ + List *es_opened_relations; /* List of non-NULL entries in + * es_relations in no specific order */ struct ExecRowMark **es_rowmarks; /* Array of per-range-table-entry * ExecRowMarks, or NULL if none */ List *es_rteperminfos; /* List of RTEPermissionInfo */ -- 2.35.3