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 1mgDrc-0004EB-Hk for pgsql-hackers@arkaria.postgresql.org; Thu, 28 Oct 2021 22:27:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mgDrb-000479-C3 for pgsql-hackers@arkaria.postgresql.org; Thu, 28 Oct 2021 22:27:11 +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 1mgDpV-0005eE-9a for pgsql-hackers@lists.postgresql.org; Thu, 28 Oct 2021 22:25:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mgDpS-0003j0-Gn for pgsql-hackers@postgresql.org; Thu, 28 Oct 2021 22:25:00 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 19SMOpw0560365; Thu, 28 Oct 2021 18:24:51 -0400 From: Tom Lane To: Andres Freund cc: Kyotaro Horiguchi , sulamul@gmail.com, bossartn@amazon.com, pgsql-hackers@postgresql.org Subject: Re: inefficient loop in StandbyReleaseLockList() In-reply-to: <20211028221424.6wtcse3qkbf2cmqo@alap3.anarazel.de> References: <20211028.155751.1898631306946946681.horikyota.ntt@gmail.com> <20211028220748.6ekrl74minwq75f4@alap3.anarazel.de> <20211028221424.6wtcse3qkbf2cmqo@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Thu, 28 Oct 2021 15:14:24 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <560363.1635459891.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 28 Oct 2021 18:24:51 -0400 Message-ID: <560364.1635459891@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > Which leads to to wonder whether the better fix would be to switch to de= leting > the last element, but still use the while (!empty) style. That should co= nvert > the O(n^2) due to 1cff1b9 back to O(n). It might or might not be faster/= slower > than using foreach(), but it should be within the same ballpark. Does it matter what order we're releasing the locks in? regards, tom lane