mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
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
This commit is contained in:
@ -781,11 +781,9 @@ FindUsableIndexForReplicaIdentityFull(Relation localrel, AttrMap *attrmap)
|
|||||||
{
|
{
|
||||||
bool isUsableIdx;
|
bool isUsableIdx;
|
||||||
Relation idxRel;
|
Relation idxRel;
|
||||||
IndexInfo *idxInfo;
|
|
||||||
|
|
||||||
idxRel = index_open(idxoid, AccessShareLock);
|
idxRel = index_open(idxoid, AccessShareLock);
|
||||||
idxInfo = BuildIndexInfo(idxRel);
|
isUsableIdx = IsIndexUsableForReplicaIdentityFull(idxRel, attrmap);
|
||||||
isUsableIdx = IsIndexUsableForReplicaIdentityFull(idxInfo, attrmap);
|
|
||||||
index_close(idxRel, AccessShareLock);
|
index_close(idxRel, AccessShareLock);
|
||||||
|
|
||||||
/* Return the first eligible index found */
|
/* Return the first eligible index found */
|
||||||
@ -832,22 +830,22 @@ FindUsableIndexForReplicaIdentityFull(Relation localrel, AttrMap *attrmap)
|
|||||||
* to sequential execution, which might not be a good idea in some cases.
|
* to sequential execution, which might not be a good idea in some cases.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
IsIndexUsableForReplicaIdentityFull(IndexInfo *indexInfo, AttrMap *attrmap)
|
IsIndexUsableForReplicaIdentityFull(Relation idxrel, AttrMap *attrmap)
|
||||||
{
|
{
|
||||||
AttrNumber keycol;
|
AttrNumber keycol;
|
||||||
|
|
||||||
/* Ensure that the index access method has a valid equal strategy */
|
/* 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;
|
return false;
|
||||||
|
|
||||||
/* The index must not be a partial index */
|
/* 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;
|
return false;
|
||||||
|
|
||||||
Assert(indexInfo->ii_NumIndexAttrs >= 1);
|
Assert(idxrel->rd_index->indnatts >= 1);
|
||||||
|
|
||||||
/* The leftmost index field must not be an expression */
|
/* The leftmost index field must not be an expression */
|
||||||
keycol = indexInfo->ii_IndexAttrNumbers[0];
|
keycol = idxrel->rd_index->indkey.values[0];
|
||||||
if (!AttributeNumberIsValid(keycol))
|
if (!AttributeNumberIsValid(keycol))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -865,7 +863,7 @@ IsIndexUsableForReplicaIdentityFull(IndexInfo *indexInfo, AttrMap *attrmap)
|
|||||||
IndexAmRoutine *amroutine;
|
IndexAmRoutine *amroutine;
|
||||||
|
|
||||||
/* The given index access method must implement amgettuple. */
|
/* 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);
|
Assert(amroutine->amgettuple != NULL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -2931,7 +2931,7 @@ FindReplTupleInLocalRel(ApplyExecutionData *edata, Relation localrel,
|
|||||||
/* Index must be PK, RI, or usable for REPLICA IDENTITY FULL tables */
|
/* Index must be PK, RI, or usable for REPLICA IDENTITY FULL tables */
|
||||||
Assert(GetRelationIdentityOrPK(localrel) == localidxoid ||
|
Assert(GetRelationIdentityOrPK(localrel) == localidxoid ||
|
||||||
(remoterel->replident == REPLICA_IDENTITY_FULL &&
|
(remoterel->replident == REPLICA_IDENTITY_FULL &&
|
||||||
IsIndexUsableForReplicaIdentityFull(BuildIndexInfo(idxrel),
|
IsIndexUsableForReplicaIdentityFull(idxrel,
|
||||||
edata->targetRel->attrmap)));
|
edata->targetRel->attrmap)));
|
||||||
index_close(idxrel, AccessShareLock);
|
index_close(idxrel, AccessShareLock);
|
||||||
#endif
|
#endif
|
||||||
|
@ -48,7 +48,7 @@ extern LogicalRepRelMapEntry *logicalrep_partition_open(LogicalRepRelMapEntry *r
|
|||||||
Relation partrel, AttrMap *map);
|
Relation partrel, AttrMap *map);
|
||||||
extern void logicalrep_rel_close(LogicalRepRelMapEntry *rel,
|
extern void logicalrep_rel_close(LogicalRepRelMapEntry *rel,
|
||||||
LOCKMODE lockmode);
|
LOCKMODE lockmode);
|
||||||
extern bool IsIndexUsableForReplicaIdentityFull(IndexInfo *indexInfo, AttrMap *attrmap);
|
extern bool IsIndexUsableForReplicaIdentityFull(Relation idxrel, AttrMap *attrmap);
|
||||||
extern Oid GetRelationIdentityOrPK(Relation rel);
|
extern Oid GetRelationIdentityOrPK(Relation rel);
|
||||||
|
|
||||||
#endif /* LOGICALRELATION_H */
|
#endif /* LOGICALRELATION_H */
|
||||||
|
Reference in New Issue
Block a user