Re: Write skew observed under serializable isolation - Mailing list pgsql-hackers

From Andres Freund
Subject Re: Write skew observed under serializable isolation
Date
Msg-id ankqjgeofv5fpug6felquv52rrvqw5n45iybavquvnwgxg6bpz@tdtcubt7frfh
Whole thread
In response to Re: Write skew observed under serializable isolation  (Aleksander Alekseev <aleksander@tigerdata.com>)
Responses Re: Write skew observed under serializable isolation
List pgsql-hackers
Hi,

On 2026-09-21 15:41:54 +0300, Aleksander Alekseev wrote:
> +     * For seqscan, sample and TID range scans in a serializable transaction,
> +     * acquire a predicate lock on the entire relation. This is required not
> +     * only to lock all the matching tuples, but also to conflict with new
> +     * insertions into the table. In an indexscan, we take page locks on the
> +     * index pages covering the range specified in the scan qual, but in a
> +     * heap scan there is nothing more fine-grained to lock. A bitmap scan is
> +     * a different story, there we have already scanned the index and locked
> +     * the index pages covering the predicate. But in that case we still have
> +     * to lock any matching heap tuples. For sample scan we could optimize the
> +     * locking to be at least page-level granularity, but we'd need to add
> +     * per-tuple locking for that.  A TID range scan is like a seqscan in this
> +     * respect: it reads heap blocks directly with no index involved, so there
> +     * is nothing finer to lock, and heap_insert() only checks for conflicts
> +     * against relation-level predicate locks anyway.
> +     */
> +    if (scan->rs_base.rs_flags & (SO_TYPE_SEQSCAN | SO_TYPE_SAMPLESCAN |
> +                                  SO_TYPE_TIDRANGESCAN))
>      {
>          /*
>           * Ensure a missing snapshot is noticed reliably, even if the

Seems like it'd be good to add a note to the SO_TYPE definitions mentioning
that this needs to be updated for additional scans.

I wish we could easily make the SO_TYPE ones an enum, so we could trigger
compiler warnings here by making it an switch() without a default. But it'd
probably be more annoying to change this than it's worth...


Do we have test coverage for the bitmap scan cases?

Greetings,

Andres Freund



pgsql-hackers by date:

Previous
From: Nikolay Samokhvalov
Date:
Subject: Re: pg_*_advice: tsv load failure, etc.
Next
From: Osama Abdul Qader
Date:
Subject: Re: Severe performance degradation with concurrent updates due to excessive EvalPlanQual (EPQ) re‑evaluation