From fdf5a2335cb987953b070dec19e20a3f9caaaa5e Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 26 Nov 2024 11:25:12 +0100 Subject: [PATCH 1/3] Simplify IsIndexUsableForReplicaIdentityFull() Take Relation as argument instead of IndexInfo. Building the IndexInfo is an unnecessary intermediate step here. --- src/backend/replication/logical/relation.c | 16 +++++++--------- src/backend/replication/logical/worker.c | 2 +- src/include/replication/logicalrelation.h | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/backend/replication/logical/relation.c b/src/backend/replication/logical/relation.c index f5a0ef2bd9d..1b426f43fd7 100644 --- a/src/backend/replication/logical/relation.c +++ b/src/backend/replication/logical/relation.c @@ -750,11 +750,9 @@ FindUsableIndexForReplicaIdentityFull(Relation localrel, AttrMap *attrmap) { bool isUsableIdx; Relation idxRel; - IndexInfo *idxInfo; idxRel = index_open(idxoid, AccessShareLock); - idxInfo = BuildIndexInfo(idxRel); - isUsableIdx = IsIndexUsableForReplicaIdentityFull(idxInfo, attrmap); + isUsableIdx = IsIndexUsableForReplicaIdentityFull(idxRel, attrmap); index_close(idxRel, AccessShareLock); /* Return the first eligible index found */ @@ -801,22 +799,22 @@ FindUsableIndexForReplicaIdentityFull(Relation localrel, AttrMap *attrmap) * to sequential execution, which might not be a good idea in some cases. */ bool -IsIndexUsableForReplicaIdentityFull(IndexInfo *indexInfo, AttrMap *attrmap) +IsIndexUsableForReplicaIdentityFull(Relation idxrel, AttrMap *attrmap) { AttrNumber keycol; /* Ensure that the index access method has a valid equal strategy */ - if (get_equal_strategy_number_for_am(indexInfo->ii_Am) == InvalidStrategy) + if (get_equal_strategy_number_for_am(idxrel->rd_rel->relam) == InvalidStrategy) return false; /* The index must not be a partial index */ - if (indexInfo->ii_Predicate != NIL) + if (!heap_attisnull(idxrel->rd_indextuple, Anum_pg_index_indpred, NULL)) return false; - Assert(indexInfo->ii_NumIndexAttrs >= 1); + Assert(idxrel->rd_index->indnatts >= 1); /* The leftmost index field must not be an expression */ - keycol = indexInfo->ii_IndexAttrNumbers[0]; + keycol = idxrel->rd_index->indkey.values[0]; if (!AttributeNumberIsValid(keycol)) return false; @@ -834,7 +832,7 @@ IsIndexUsableForReplicaIdentityFull(IndexInfo *indexInfo, AttrMap *attrmap) IndexAmRoutine *amroutine; /* The given index access method must implement amgettuple. */ - amroutine = GetIndexAmRoutineByAmId(indexInfo->ii_Am, false); + amroutine = GetIndexAmRoutineByAmId(idxrel->rd_rel->relam, false); Assert(amroutine->amgettuple != NULL); } #endif diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index 925dff9cc44..46d3ad566f6 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -2931,7 +2931,7 @@ FindReplTupleInLocalRel(ApplyExecutionData *edata, Relation localrel, /* Index must be PK, RI, or usable for REPLICA IDENTITY FULL tables */ Assert(GetRelationIdentityOrPK(localrel) == localidxoid || (remoterel->replident == REPLICA_IDENTITY_FULL && - IsIndexUsableForReplicaIdentityFull(BuildIndexInfo(idxrel), + IsIndexUsableForReplicaIdentityFull(idxrel, edata->targetRel->attrmap))); index_close(idxrel, AccessShareLock); #endif diff --git a/src/include/replication/logicalrelation.h b/src/include/replication/logicalrelation.h index e687b40a566..33534672ec3 100644 --- a/src/include/replication/logicalrelation.h +++ b/src/include/replication/logicalrelation.h @@ -48,7 +48,7 @@ extern LogicalRepRelMapEntry *logicalrep_partition_open(LogicalRepRelMapEntry *r Relation partrel, AttrMap *map); extern void logicalrep_rel_close(LogicalRepRelMapEntry *rel, LOCKMODE lockmode); -extern bool IsIndexUsableForReplicaIdentityFull(IndexInfo *indexInfo, AttrMap *attrmap); +extern bool IsIndexUsableForReplicaIdentityFull(Relation idxrel, AttrMap *attrmap); extern Oid GetRelationIdentityOrPK(Relation rel); #endif /* LOGICALRELATION_H */ -- 2.47.0