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 1mDuW8-0007GF-QT for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Aug 2021 20:08:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mDuVa-00034j-7p for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Aug 2021 20:07:26 +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 1mDuVZ-00034b-9b for pgsql-bugs@lists.postgresql.org; Wed, 11 Aug 2021 20:07:26 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mDuVR-0001Xk-LO for pgsql-bugs@lists.postgresql.org; Wed, 11 Aug 2021 20:07:24 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 1DB8B5C00CA; Wed, 11 Aug 2021 16:07:14 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 11 Aug 2021 16:07:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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= fm3; bh=Y3TctIaBLoNkBTj8pIDcVOEC/e0a1f/SoOyZwnr5aU8=; b=Nyzd9gbp 6ieK6Mm+S5/NnAxj+Wosz9512zJ1m+m6KYsGCnMgzjQhiNLnuPe987GHVB9T02C/ 90r5EMQ7wjWVnggTrONl84J/F4nm0MJDvJ+apnu1jcBhFn1CtV3BMvWDtXnjKDOt +1jy36ExGXeR+f+XjTxKjkhEqbnjqIkZrslPIpKe+mQ6RTXHmIY3q8pXTp8DjnsB 024KrsxWK9rmb4eWnAQpboljCIEbADolFaLXBFuCfTVq5bzVoBeRFJt4hL6PktK8 AjtBTFyQnDBUCauk3OyD9HxJoUV3ciTS7lo4gy0EgMSO4FNDerDWuUy8YJorBR65 tbYgGpCIZHCorw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrkedugddugeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhvrghr ohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqe enucggtffrrghtthgvrhhnpeetudekjeeigfehvedtffekheelgeeiheeuteelffevffek vefgteduveevleeiueenucffohhmrghinhepphhoshhtghhrrdgvshenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghl vhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 11 Aug 2021 16:07:12 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 443C72A0868; Wed, 11 Aug 2021 16:07:09 -0400 (-04) Date: Wed, 11 Aug 2021 16:07:09 -0400 From: Alvaro Herrera To: emil@iggland.com, pgsql-bugs@lists.postgresql.org, Surafel Temesgen , David Christensen Subject: Re: BUG #17141: SELECT LIMIT WITH TIES FOR UPDATE SKIP LOCKED returns wrong number of rows Message-ID: <202108112007.evylbmzueapg@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <17141-913d78b9675aac8e@postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Aug-11, PG Bug reporting form wrote: > BEGIN; > SELECT * FROM queue > ORDER BY task DESC > FETCH FIRST 1 ROWS WITH TIES > FOR UPDATE SKIP LOCKED; > /* Some work to be done here */ > COMMIT; > > select version(); > PostgreSQL 13.3, compiled by Visual C++ build 1914, 64-bit > > Expected result Worker 1: (580), (580), Actual result Worker 1: (580), (580) > Expected result Worker 2: (480), (480), Actual result Worker 2: (480) Ouch, we already saw this actually: https://postgr.es/m/16676-fd62c3c835880da6@postgresql.org The problem is that the first worker locks the first (480) row (even though it does not return it), so the second worker skips it due to SKIP LOCKED. I have this on my list of things to look at, but it's not at the top yet sadly ... -- Álvaro Herrera