| From: | Andres Freund <andres(at)anarazel(dot)de> |
|---|---|
| To: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: SSI: ON CONFLICT DO SELECT takes no predicate lock on the returned row |
| Date: | 2026-08-19 13:49:17 |
| Message-ID: | 2wibipztrxlegh5afz3zdqafqmupfybztqt7gxuy55wlkx3fy4@7kgcccedlxmo |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On 2026-08-19 12:33:01 +0100, Zsolt Parragi wrote:
> While testing the new INSERT...ON CONFLICT DO SELECT feature I found a
> possible serialization violation: the row returned back by DO SELECT
> is not covered by any SIREAD lock, so a concurrent transaction can
> modify it.
Good catch.
> @@ -3337,6 +3338,27 @@ ExecOnConflictSelect(ModifyTableContext *context,
> return false;
> }
>
> + /*
> + * At SERIALIZABLE, record an SIREAD lock on the tuple. Returning the
> + * existing row (or filtering it out with the WHERE clause) is a read for
> + * SSI purposes, but neither the arbiter index probe (dirty snapshot) nor
> + * the fetch above (SnapshotAny) takes predicate locks, and the SELECT
> + * path writes nothing that would trigger conflict-in detection.
> + */
> + if (IsolationIsSerializable())
> + {
> + Datum xminDatum;
> + TransactionId xmin;
> + bool isnull;
> +
> + xminDatum = slot_getsysattr(existing, MinTransactionIdAttributeNumber, &isnull);
> + Assert(!isnull);
> + xmin = DatumGetTransactionId(xminDatum);
> +
> + PredicateLockTID(relation, conflictTid, context->estate->es_snapshot,
> + xmin);
> + }
> +
I don't think this is quite right though. The details of how heapam uses SI
locks is heapam specific and should live in the heapam code. I also think you
actually need to acquire the predicate lock before ExecOnConflictLockRow()?
Greetings,
Andres Freund
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Anthonin Bonnefoy | 2026-08-19 14:15:40 | Re: Function scan FDW pushdown |
| Previous Message | cca5507 | 2026-08-19 13:40:34 | timeout value overflow in wait for lsn |