From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: lars.vonk@gmail.com
Subject: BUG #15715: UPDATE using "in (subquery for update limit 1)" does not respect the limit in subquery
Date: Tue, 26 Mar 2019 15:08:49 +0000
Message-ID: <15715-1eccf9c7dffc4093@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 15715
Logged by: Lars Vonk
Email address: lars.vonk@gmail.com
PostgreSQL version: 11.2
Operating system: Ubuntu 18.04.2 LTS
Description:
Hi,
We are using a ruby library called delayed-job
(https://github.com/collectiveidea/delayed_job) that generates the following
sql
LOG: duration: 82797.554 ms execute <unnamed>: UPDATE "delayed_jobs" SET
locked_at = '2019-03-26 13:25:20.808244', locked_by = 'host:myhost pid:9958'
WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at
<= '2019-03-26 13:25:20.807815' AND (locked_at IS NULL OR locked_at <
'2019-03-26 09:25:20.807828') OR locked_by = 'host:myhost pid:9958') AND
failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE)
RETURNING *
We noticed that all the "delayed_jobs" were getting locked instead of just
1. There is already a bug report (and a recent "fix") for this in
delayed_job:
https://github.com/collectiveidea/delayed_job_active_record/issues/143
We also found some related stackoverflow content which sort of hints that
this is a bug:
- https://dba.stackexchange.com/questions/69471/postgres-update-limit-1
-
https://github.com/feikesteenbergen/demos/blob/master/bugs/update_limit_bug.txt
So is this a postgres bug? Or is "limit 1" not garantueed in subqueries?
Kind regards,
Lars
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, lars.vonk@gmail.com
Subject: Re: BUG #15715: UPDATE using "in (subquery for update limit 1)" does not respect the limit in subquery
In-Reply-To: <15715-1eccf9c7dffc4093@postgresql.org>
References: <15715-1eccf9c7dffc4093@postgresql.org>
* 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