Delete from locking ordering differences - Mailing list pgsql-sql

From Peter Hendriks
Subject Delete from locking ordering differences
Date
Msg-id CAFhXkLG=izjYB5_YK3x3yjcVLF1SCe7YfBaBDf8U0zFtRscr6w@mail.gmail.com
Whole thread Raw
Responses Re: Delete from locking ordering differences  (Rob Sargent <robjsargent@gmail.com>)
Re: Delete from locking ordering differences  (Peter Hendriks <peter@mindloops.nl>)
List pgsql-sql
We are wondering if anyone can explain the difference we are having in production with the following queries:

DELETE FROM store
WHERE id IN (
  SELECT id FROM store 
  FOR UPDATE SKIP LOCKED 
  ORDER BY ID
  LIMIT 1000
)
RETURNING id, payload

This query is sometimes executed with high concurrency, and then can hang indefinitely, we assume because of a locking problem that postgresql is not detecting as a deadlock.

This alternative query does not have the hanging problem:

WITH store_ids AS (
  SELECT id FROM store 
  FOR UPDATE SKIP LOCKED 
  ORDER BY ID
  LIMIT 1000
)
DELETE FROM store s
USING store_ids si 
WHERE s.id = si.id
RETURNING s.id, s.payload

Can anyone explain why the first query is expected to fail (hang), and the second query does not have this problem? We would be interested in more understanding on this. Thanks! 

pgsql-sql by date:

Previous
From: Geri Wright
Date:
Subject: Re: ON CONFLICT clause NOT working on Partition Table PostgreSQL 12
Next
From: Rob Sargent
Date:
Subject: Re: Delete from locking ordering differences