Match table_complete_speculative() code to comment - Mailing list pgsql-hackers

From Ashwin Agrawal
Subject Match table_complete_speculative() code to comment
Date
Msg-id CALfoeitk7-TACwYv3hCw45FNPjkA86RfXg4iQ5kAOPhR+F1Y4w@mail.gmail.com
Whole thread Raw
Responses Re: Match table_complete_speculative() code to comment
List pgsql-hackers
Comment for table_complete_speculative() says

/*
 * Complete "speculative insertion" started in the same transaction.
If
 * succeeded is true, the tuple is fully inserted, if false, it's
removed.
 */
static inline void
table_complete_speculative(Relation rel, TupleTableSlot *slot,
                           uint32 specToken, bool succeeded)
{
    rel->rd_tableam->tuple_complete_speculative(rel, slot, specToken,
                                                succeeded);
}

but code really refers to succeeded as failure. Since that argument is
passed as specConflict, means conflict happened and hence the tuple
should be removed. It would be better to fix the code to match the
comment as in AM layer its better to deal with succeeded to finish the
insertion and not other way round.

diff --git a/src/backend/access/heap/heapam_handler.c
b/src/backend/access/heap/heapam_handler.c
index 4d179881f27..241639cfc20 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -282,7 +282,7 @@ heapam_tuple_complete_speculative(Relation
relation, TupleTableSlot *slot,
        HeapTuple       tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree);

        /* adjust the tuple's state accordingly */
-       if (!succeeded)
+       if (succeeded)
                heap_finish_speculative(relation, &slot->tts_tid);
        else
                heap_abort_speculative(relation, &slot->tts_tid);
diff --git a/src/backend/executor/nodeModifyTable.c
b/src/backend/executor/nodeModifyTable.c
index 444c0c05746..d545bbce8a2 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -556,7 +556,7 @@ ExecInsert(ModifyTableState *mtstate,

                        /* adjust the tuple's state accordingly */
                        table_complete_speculative(resultRelationDesc, slot,
-
    specToken, specConflict);
+
    specToken, !specConflict);

                        /*
                         * Wake up anyone waiting for our decision.
They will re-check

- Ashwin and Melanie



pgsql-hackers by date:

Previous
From: Alexander Korotkov
Date:
Subject: Re: doc: improve PG 12 to_timestamp()/to_date() wording
Next
From: Andreas Joseph Krogh
Date:
Subject: Sv: Re: ERROR: failed to add item to the index page