From: Emil Iggland <emil@iggland.com>
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17141: SELECT LIMIT WITH TIES FOR UPDATE SKIP LOCKED returns wrong number of rows
Date: Wed, 11 Aug 2021 19:29:02 +0200
Message-ID: <88d7b60d-045e-27c5-a2f4-c669371128c5@iggland.com> (raw)
In-Reply-To: <17141-913d78b9675aac8e@postgresql.org>
References: <17141-913d78b9675aac8e@postgresql.org>
As does
SELECT * FROM queue
ORDER BY task DESC
FETCH NEXT 1 ROWS WITH TIES
FOR UPDATE SKIP LOCKED;
Note the use of NEXT instead of FIRST
On 2021-08-11 18:38, PG Bug reporting form wrote:
> The following bug has been logged on the website:
>
> Bug reference: 17141
> Logged by: Emil Iggland
> Email address: emil@iggland.com
> PostgreSQL version: 13.3
> Operating system: Windows
> Description:
>
> I am trying to create a queue which should assign multiple tasks to a
> worker. I use row locking with FOR UPDATE SKIP LOCKED, but the number of
> rows returned are inconsistent with what I expect.
>
> Minimum example:
>
> CREATE TABLE queue (task INTEGER);
> INSERT INTO queue (task)
> VALUES (180),(280),(380),(480),(580),(180),(280),(380),(480),(580);
>
> BEGIN;
> SELECT * FROM queue
> ORDER BY task DESC
> FETCH FIRST 1 ROWS WITH TIES
> FOR UPDATE SKIP LOCKED;
> /* Some work to be done here */
> COMMIT;
>
> select version();
> PostgreSQL 13.3, compiled by Visual C++ build 1914, 64-bit
>
> Expected result Worker 1: (580), (580), Actual result Worker 1: (580),
> (580)
> Expected result Worker 2: (480), (480), Actual result Worker 2: (480)
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: emil@iggland.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17141: SELECT LIMIT WITH TIES FOR UPDATE SKIP LOCKED returns wrong number of rows
In-Reply-To: <88d7b60d-045e-27c5-a2f4-c669371128c5@iggland.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox