Avoid incorrectly indicating exclusion constraint wait
authorStephen Frost <[email protected]>
Tue, 15 Mar 2016 22:04:48 +0000 (18:04 -0400)
committerStephen Frost <[email protected]>
Tue, 15 Mar 2016 22:04:48 +0000 (18:04 -0400)
INSERT ... ON CONFLICT's precheck may have to wait on the outcome of
another insertion, which may or may not itself be a speculative
insertion.  This wait is not necessarily associated with an exclusion
constraint, but was always reported that way in log messages if the wait
happened to involve a tuple that had no speculative token.

Initially discovered through use of ON CONFLICT DO NOTHING, where
spurious references to exclusion constraints in log messages were more
likely.

Patch by Peter Geoghegan.
Reviewed by Julien Rouhaud.

Back-patch to 9.5 where INSERT ... ON CONFLICT was added.

src/backend/executor/execIndexing.c

index 72993297079df96f91e3e6266b3c4b81d7383bf8..1b549811e670749281c81ffcbf32f9c9ce497b44 100644 (file)
@@ -725,6 +725,7 @@ retry:
    {
        TransactionId xwait;
        ItemPointerData ctid_wait;
+       XLTW_Oper       reason_wait;
        Datum       existing_values[INDEX_MAX_KEYS];
        bool        existing_isnull[INDEX_MAX_KEYS];
        char       *error_new;
@@ -783,13 +784,14 @@ retry:
              TransactionIdPrecedes(GetCurrentTransactionId(), xwait))))
        {
            ctid_wait = tup->t_data->t_ctid;
+           reason_wait = indexInfo->ii_ExclusionOps ?
+               XLTW_RecheckExclusionConstr : XLTW_InsertIndex;
            index_endscan(index_scan);
            if (DirtySnapshot.speculativeToken)
                SpeculativeInsertionWait(DirtySnapshot.xmin,
                                         DirtySnapshot.speculativeToken);
            else
-               XactLockTableWait(xwait, heap, &ctid_wait,
-                                 XLTW_RecheckExclusionConstr);
+               XactLockTableWait(xwait, heap, &ctid_wait, reason_wait);
            goto retry;
        }