Skip to content

Commit 7727049

Browse files
committed
Simplify IsIndexUsableForReplicaIdentityFull()
Take Relation as argument instead of IndexInfo. Building the IndexInfo is an unnecessary intermediate step here. A future patch wants to get some information that is in the relcache but not in IndexInfo, so this will also help there. Discussion: https://www.postgresql.org/message-id/333d3886-b737-45c3-93f4-594c96bb405d@eisentraut.org
1 parent 87ce27d commit 7727049

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

src/backend/replication/logical/relation.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,9 @@ FindUsableIndexForReplicaIdentityFull(Relation localrel, AttrMap *attrmap)
781781
{
782782
bool isUsableIdx;
783783
Relation idxRel;
784-
IndexInfo *idxInfo;
785784

786785
idxRel = index_open(idxoid, AccessShareLock);
787-
idxInfo = BuildIndexInfo(idxRel);
788-
isUsableIdx = IsIndexUsableForReplicaIdentityFull(idxInfo, attrmap);
786+
isUsableIdx = IsIndexUsableForReplicaIdentityFull(idxRel, attrmap);
789787
index_close(idxRel, AccessShareLock);
790788

791789
/* Return the first eligible index found */
@@ -832,22 +830,22 @@ FindUsableIndexForReplicaIdentityFull(Relation localrel, AttrMap *attrmap)
832830
* to sequential execution, which might not be a good idea in some cases.
833831
*/
834832
bool
835-
IsIndexUsableForReplicaIdentityFull(IndexInfo *indexInfo, AttrMap *attrmap)
833+
IsIndexUsableForReplicaIdentityFull(Relation idxrel, AttrMap *attrmap)
836834
{
837835
AttrNumber keycol;
838836

839837
/* Ensure that the index access method has a valid equal strategy */
840-
if (get_equal_strategy_number_for_am(indexInfo->ii_Am) == InvalidStrategy)
838+
if (get_equal_strategy_number_for_am(idxrel->rd_rel->relam) == InvalidStrategy)
841839
return false;
842840

843841
/* The index must not be a partial index */
844-
if (indexInfo->ii_Predicate != NIL)
842+
if (!heap_attisnull(idxrel->rd_indextuple, Anum_pg_index_indpred, NULL))
845843
return false;
846844

847-
Assert(indexInfo->ii_NumIndexAttrs >= 1);
845+
Assert(idxrel->rd_index->indnatts >= 1);
848846

849847
/* The leftmost index field must not be an expression */
850-
keycol = indexInfo->ii_IndexAttrNumbers[0];
848+
keycol = idxrel->rd_index->indkey.values[0];
851849
if (!AttributeNumberIsValid(keycol))
852850
return false;
853851

@@ -865,7 +863,7 @@ IsIndexUsableForReplicaIdentityFull(IndexInfo *indexInfo, AttrMap *attrmap)
865863
IndexAmRoutine *amroutine;
866864

867865
/* The given index access method must implement amgettuple. */
868-
amroutine = GetIndexAmRoutineByAmId(indexInfo->ii_Am, false);
866+
amroutine = GetIndexAmRoutineByAmId(idxrel->rd_rel->relam, false);
869867
Assert(amroutine->amgettuple != NULL);
870868
}
871869
#endif

src/backend/replication/logical/worker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2931,7 +2931,7 @@ FindReplTupleInLocalRel(ApplyExecutionData *edata, Relation localrel,
29312931
/* Index must be PK, RI, or usable for REPLICA IDENTITY FULL tables */
29322932
Assert(GetRelationIdentityOrPK(localrel) == localidxoid ||
29332933
(remoterel->replident == REPLICA_IDENTITY_FULL &&
2934-
IsIndexUsableForReplicaIdentityFull(BuildIndexInfo(idxrel),
2934+
IsIndexUsableForReplicaIdentityFull(idxrel,
29352935
edata->targetRel->attrmap)));
29362936
index_close(idxrel, AccessShareLock);
29372937
#endif

src/include/replication/logicalrelation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extern LogicalRepRelMapEntry *logicalrep_partition_open(LogicalRepRelMapEntry *r
4848
Relation partrel, AttrMap *map);
4949
extern void logicalrep_rel_close(LogicalRepRelMapEntry *rel,
5050
LOCKMODE lockmode);
51-
extern bool IsIndexUsableForReplicaIdentityFull(IndexInfo *indexInfo, AttrMap *attrmap);
51+
extern bool IsIndexUsableForReplicaIdentityFull(Relation idxrel, AttrMap *attrmap);
5252
extern Oid GetRelationIdentityOrPK(Relation rel);
5353

5454
#endif /* LOGICALRELATION_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy