Re: BUG #17141: SELECT LIMIT WITH TIES FOR UPDATE SKIP LOCKED returns wrong number of rows

From: Emil Iggland <emil(at)iggland(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: David Christensen <david(dot)christensen(at)crunchydata(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>, Surafel Temesgen <surafel3000(at)gmail(dot)com>
Subject: Re: BUG #17141: SELECT LIMIT WITH TIES FOR UPDATE SKIP LOCKED returns wrong number of rows
Date: 2021-10-11 14:07:40
Message-ID: c159816b-2148-aaff-d78e-1b52a0cd68c5@iggland.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

To be it would seem that a "peek()" type function would do a good job
also, you can always peek at the next row to determine if it is not a
candidate, if it is the "look and lock"-it.
Then you can keep both features.

On 2021-10-03 00:30, Tom Lane wrote:
> Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> writes:
>> On 2021-Aug-25, Emil Iggland wrote:
>>> I see a lot of thought being put into how this issue can be worked
>>> around, but very little discussion on if this behaviour is correct or
>>> not. Without having thought about it much deeper, this seems to only be
>>> a problem with the "WITH TIES" clause which provokes this extra row
>>> being locked. Perhaps that is where the problem should be attacked.
>
>> The problem is that when the WITH TIES clause is added, we need to read
>> one extra row after the one that reaches the LIMIT count, in order to
>> verify whether it (the next one) should be included due to a tie. With
>> the executor structure that we currently have, there is no way to read
>> that row and not lock it. So a good fix would be to separate the act of
>> locking the row from the act of reading it.
>
> I'm not convinced that's a "good fix". SELECT FOR UPDATE generally
> considers that it should return rows only if they still match the
> WHERE condition after they're locked. The natural extension of that
> to WITH TIES is that you ought to check for equality after locking.
> So these features seem rather fundamentally in conflict.
>
> regards, tom lane
>

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Artur Zakirov 2021-10-11 14:50:51 Re: Text search prefix matching and stop words
Previous Message Francisco Olarte 2021-10-11 14:00:11 Re: GROUP BY using tablename.* does not work if tablename has 1 column with NULL values