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 1mWn8E-0000Lo-7t for pgsql-bugs@arkaria.postgresql.org; Sat, 02 Oct 2021 22:05:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mWn8D-0006cn-7K for pgsql-bugs@arkaria.postgresql.org; Sat, 02 Oct 2021 22:05:21 +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 1mWn8D-0006cf-0h for pgsql-bugs@lists.postgresql.org; Sat, 02 Oct 2021 22:05:21 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mWn8A-0005HX-F8 for pgsql-bugs@lists.postgresql.org; Sat, 02 Oct 2021 22:05:20 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 298905C00BD; Sat, 2 Oct 2021 18:05:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sat, 02 Oct 2021 18:05:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=RlDYGmo43MZcc+ffRt4EWSosnpMr3dTe56ojdUE6324=; b=axUYQFEK t8zfQv0wf5H4greIohzrAnJ0Z+jBJav+EBC2h0llvimqocgsAHf3pU/6hODZRiQ/ sKNCO/OVXEUVE3GUSTGV5/RIzIFxexOXshScXgKEE4uDrkjiYqcbIMPWJVRpE6Eo OzBgyHXz3jmb9Hgk8OW5DAMB/gLgJ4hrqGU0pLorD0QTuj9UC6rIT4klCDXiIlcA 08BJ2uBo6c/S5BEBUKeYBuV4l49h6YQSVSuj1IRemIuXZpSNuLaTDwbLQ61PmHvY TIb5e3ZgQgX3V07/xsU9AoaeDa6aA7jUkEU8JUYMcIO13xmjDJwHY6979neWVuzM Hy/EGdEf/Wotdg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudekledgtdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhvrghr ohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqe enucggtffrrghtthgvrhhnpedujeevjeffjeevuddutedvkeeiueeitddvieelfeekveej udefgeeuvdejhfeuleenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhh vghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 2 Oct 2021 18:05:16 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 46F772A0875; Sat, 2 Oct 2021 19:05:14 -0300 (-03) Date: Sat, 2 Oct 2021 19:05:14 -0300 From: Alvaro Herrera To: Emil Iggland Cc: David Christensen , PostgreSQL mailing lists , Surafel Temesgen Subject: Re: BUG #17141: SELECT LIMIT WITH TIES FOR UPDATE SKIP LOCKED returns wrong number of rows Message-ID: <202110022205.jwz6b5bdyja5@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Aug-25, Emil Iggland wrote: > I see a lot of thought being put into how this issue can be worked > around, but very little discussion on if this behaviour is correct or > not. Without having thought about it much deeper, this seems to only be > a problem with the "WITH TIES" clause which provokes this extra row > being locked. Perhaps that is where the problem should be attacked. The problem is that when the WITH TIES clause is added, we need to read one extra row after the one that reaches the LIMIT count, in order to verify whether it (the next one) should be included due to a tie. With the executor structure that we currently have, there is no way to read that row and not lock it. So a good fix would be to separate the act of locking the row from the act of reading it. -- Álvaro Herrera 39°49'30"S 73°17'W — https://www.EnterpriseDB.com/