diff options
Diffstat (limited to 'src/backend/executor')
-rw-r--r-- | src/backend/executor/execIndexing.c | 5 | ||||
-rw-r--r-- | src/backend/executor/execReplication.c | 30 |
2 files changed, 32 insertions, 3 deletions
diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c index e3fe9b78bb5..bdf862b2406 100644 --- a/src/backend/executor/execIndexing.c +++ b/src/backend/executor/execIndexing.c @@ -214,9 +214,8 @@ ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative) ii = BuildIndexInfo(indexDesc); /* - * If the indexes are to be used for speculative insertion or conflict - * detection in logical replication, add extra information required by - * unique index entries. + * If the indexes are to be used for speculative insertion, add extra + * information required by unique index entries. */ if (speculative && ii->ii_Unique && !indexDesc->rd_index->indisexclusion) BuildSpeculativeIndexInfo(indexDesc, ii); diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c index ede89ea3cf9..53ddd25c42d 100644 --- a/src/backend/executor/execReplication.c +++ b/src/backend/executor/execReplication.c @@ -432,6 +432,30 @@ retry: } /* + * Build additional index information necessary for conflict detection. + */ +static void +BuildConflictIndexInfo(ResultRelInfo *resultRelInfo, Oid conflictindex) +{ + for (int i = 0; i < resultRelInfo->ri_NumIndices; i++) + { + Relation indexRelation = resultRelInfo->ri_IndexRelationDescs[i]; + IndexInfo *indexRelationInfo = resultRelInfo->ri_IndexRelationInfo[i]; + + if (conflictindex != RelationGetRelid(indexRelation)) + continue; + + /* + * This Assert will fail if BuildSpeculativeIndexInfo() is called + * twice for the given index. + */ + Assert(indexRelationInfo->ii_UniqueOps == NULL); + + BuildSpeculativeIndexInfo(indexRelation, indexRelationInfo); + } +} + +/* * Find the tuple that violates the passed unique index (conflictindex). * * If the conflicting tuple is found return true, otherwise false. @@ -452,6 +476,12 @@ FindConflictTuple(ResultRelInfo *resultRelInfo, EState *estate, *conflictslot = NULL; + /* + * Build additional information required to check constraints violations. + * See check_exclusion_or_unique_constraint(). + */ + BuildConflictIndexInfo(resultRelInfo, conflictindex); + retry: if (ExecCheckIndexConstraints(resultRelInfo, slot, estate, &conflictTid, &slot->tts_tid, |