Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1obl4F-0005OY-Sx for pgsql-sql@arkaria.postgresql.org; Fri, 23 Sep 2022 15:58:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1obl4D-0006Wz-6L for pgsql-sql@arkaria.postgresql.org; Fri, 23 Sep 2022 15:58:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1obd9q-0002Ea-Pn for pgsql-sql@lists.postgresql.org; Fri, 23 Sep 2022 07:31:34 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1obd9o-0002G8-2a for pgsql-sql@lists.postgresql.org; Fri, 23 Sep 2022 07:31:34 +0000 Received: by mail-pj1-x1036.google.com with SMTP id y11so12116081pjv.4 for ; Fri, 23 Sep 2022 00:31:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindloops-nl.20210112.gappssmtp.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date; bh=rCEdi+vNBT6bHaJkeiGAu+WihTmG7iD39gwFRZuESwc=; b=eyeHopC3kOkfUdTj/QakKgfcHL1YUqA56ZI29hzxPjLRAnAlRM3Y1r//qQCbTp4/27 ZwY9FpDPZEs5wxfa2LMeIzAweEqgba5JQiWMJzyt0O6rfNSEKz+cf3oEh8b0O1RBV3Bx d1farOO0cn5yPuhEhFxwBUkgWx/qqlBWeqQDTEhB2dvuLLXjrPYBTGWtiZTjMNIYkzEg +4cEG7bXo+Rmq6v9w5cdtKxe2zEV3eexSgV/BkrbKWeDXogPfDpADkqqFEpyTVDqodKG aPfYzsyuJEoprVjIYYfimCgvcciFVbV0pGSgkEJW+neJRj2PRS7U4RhuhTT11g7AiQXP nVEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date; bh=rCEdi+vNBT6bHaJkeiGAu+WihTmG7iD39gwFRZuESwc=; b=bHXVEALfubtFT4wWDT0xwP3rfbnbH3qb0vfp+BxArjMO0KzYLy5YDL6UhSYP/SdQGn fwNHpB9294fwK9iezLC8UB/cCRGhID0Isc0VyjH7f0wqs7Ad+hLT2baZtGyBiZ4r/Bn9 iE0Ik1tgbW9MwSMFwiNvTcMqcT+TbQkDn0HKkEB9/AecgggP+LDWwn4U58aCCKeN7kXQ u9SndXmwnBtRyP4pFWJCftcz5mtQrgBPYDpwbTnDHo04mruAKIrEt+I9gVJirX+3QwjC A+9Okz895a6XSZCnEI+4+JSV9XyVEScmuAjR75RQXvYi90r9NzF0Mh5UL7sBCVc9oJKY Nb6g== X-Gm-Message-State: ACrzQf1k1sSqYdXzXoSyDxd3fQpAgGgK0SIPXSAoVSM0CEt1lcek1esq HdNMXXXp2VS35Y5A+evqEFatJ5QNmsW8vkpZpy5AQrhL5spzQl68 X-Google-Smtp-Source: AMsMyM5XV9y3psUuZD1JU+ufzdHZWRA66tpDTbr2SI2hAmLc1Vh8hvE2DZwXs3n6csnAlhzlyRFO5JnLsq53PMDLdPg= X-Received: by 2002:a17:90b:1c07:b0:202:8ad0:3210 with SMTP id oc7-20020a17090b1c0700b002028ad03210mr20200145pjb.193.1663918288251; Fri, 23 Sep 2022 00:31:28 -0700 (PDT) MIME-Version: 1.0 From: Peter Hendriks Date: Fri, 23 Sep 2022 09:31:17 +0200 Message-ID: Subject: Delete from locking ordering differences To: pgsql-sql@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000081c46105e9532a6d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000081c46105e9532a6d Content-Type: text/plain; charset="UTF-8" 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! --00000000000081c46105e9532a6d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
We are wondering if anyone can explain the difference we a= re having in production with the following queries:

DELE= TE FROM store
WHERE id IN (
=C2=A0 SELECT id FROM store= =C2=A0
=C2=A0 FOR UPDATE SKIP LOCKED=C2=A0
=C2=A0 ORDER= BY ID
=C2=A0 LIMIT 1000
)
RETURNING id, payl= oad

This query is sometimes executed with high con= currency, and then can hang indefinitely, we assume because of a locking pr= oblem that postgresql is not detecting as a deadlock.

<= div>This alternative query does not have the hanging problem:
WITH store_ids AS (
=C2=A0 SELECT id FROM store= =C2=A0
=C2=A0 FOR UPDATE SKIP LOCKED=C2=A0
=C2=A0 ORDER= BY ID
=C2=A0 LIMIT 1000
)
DELETE = FROM store s
USING store_ids si=C2=A0
WHERE s.id =3D si.id
RETU= RNING s.id, s.payload

Can anyone explain why the first query is expected to fail (hang), an= d the second query does not have this problem? We would be interested in mo= re understanding on this. Thanks!=C2=A0
--00000000000081c46105e9532a6d--