From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
---|---|
To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Cc: | david(at)endpoint(dot)com |
Subject: | BUG #16676: SELECT ... FETCH FIRST ROW WITH TIES FOR UPDATE SKIP LOCKED locks rows it doesn't return |
Date: | 2020-10-16 19:05:15 |
Message-ID: | 16676-fd62c3c835880da6@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 16676
Logged by: David Christensen
Email address: david(at)endpoint(dot)com
PostgreSQL version: 13.0
Operating system: OS X
Description:
Test case (found when demonstrating a queue mechanism for batches):
create table queue (id int generated always as identity, batch_id int not
null);
insert into queue (batch_id) values (1),(1),(2),(3);
postgres=# select * from queue;
id | batch_id
----+----------
1 | 1
2 | 1
3 | 2
4 | 3
(4 rows)
-- backend 1:
postgres=# begin;
BEGIN
postgres=*# select * from queue order by batch_id fetch first row with ties
for update skip locked;
id | batch_id
----+----------
1 | 1
2 | 1
(2 rows)
-- backend 2:
postgres=# select * from queue order by batch_id fetch first row with ties
for update skip locked;
id | batch_id
----+----------
4 | 3
(1 row)
-- QED
As you can see, the row id 3 with batch_id 2 is not returned as would be
implied by the strict ordering and the skipped locks. The working theory
here is the FETCH FIRST ROW WITH TIES locks the rows before deciding if they
should be included or not.
From | Date | Subject | |
---|---|---|---|
Next Message | Mary LaClair | 2020-10-16 19:16:52 | copy command bug |
Previous Message | David G. Johnston | 2020-10-16 14:23:27 | Re: BUG #16674: The idle connection get created automatically |