Re: Too coarse predicate locks granularity for B+ tree indexes

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: Rinat Shigapov <rinatshigapov(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Too coarse predicate locks granularity for B+ tree indexes
Date: 2023-02-07 11:10:37
Message-ID: CA+hUKG+=M+zeGttx+Af-uY=H0kdqsFU720J-v8jMp7J4FUbBLA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Tue, Feb 7, 2023 at 11:24 PM Rinat Shigapov <rinatshigapov(at)gmail(dot)com> wrote:
> Does the current PostgreSQL release support B+ tree index predicate locks more granular then page-level locks?

No. I tried to follow some breadcrumbs left by Kevin and Dan that
should allow unique index scans that find a match to skip the btree
page lock, though, and p-lock just the heap tuple. If you like
half-baked experimental code, see the v4-0002 patch in this thread,
where I took some shortcuts (jamming stuff that should be in the
planner down into the executor) for a proof-of-concept:

https://www.postgresql.org/message-id/flat/CAEepm%3D2GK3FVdnt5V3d%2Bh9njWipCv_fNL%3DwjxyUhzsF%3D0PcbNg%40mail.gmail.com

With that approach, if it *doesn't* find a match, then you're back to
having to p-lock the whole index page to represent the "gap", so that
you can conflict with anyone who tries to insert a matching value
later. I believe the next-key approach would allow for finer grained
gap-locks (haven't studied that myself), but that's a secondary
problem; the primary problem (it seems to me) is getting rid of index
locks completely in the (common?) case that you have a qualifying
match.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Giovanni Biscontini 2023-02-07 11:15:57 Re: PostgreSQL
Previous Message Thomas Kellerer 2023-02-07 11:10:07 Re: PostgreSQL

Browse pgsql-hackers by date

  From Date Subject
Next Message Sujit.Rathod@fujitsu.com 2023-02-07 11:14:48 Missing TAG for FEB (current) Minor Version Release
Previous Message Rinat Shigapov 2023-02-07 11:08:26 Re: Too coarse predicate locks granularity for B+ tree indexes