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 1l6cZR-000368-0k for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Feb 2021 17:01: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 1l6cZP-0004mM-NU for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Feb 2021 17:00:59 +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 1l6cZP-0004mE-GG for pgsql-hackers@lists.postgresql.org; Mon, 01 Feb 2021 17:00:59 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l6cZL-00063d-O0 for pgsql-hackers@lists.postgresql.org; Mon, 01 Feb 2021 17:00:58 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id D7500A62; Mon, 1 Feb 2021 12:00:51 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 01 Feb 2021 12:00:52 -0500 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=mZZ+aDj3f4cG0zcYUtWbQnKOstsj01oARZ5eVp9eDQI=; b=OjPoXWJt mpBO7y7n4zS1B450/klYzdwLZjSiANn4IRRo0Asld78+xegcMk09kV56eB6pNWPi vh81broR0BEoxADfip99JFDQUXPNKK7sg3R7D0N8ro1OQEj0zcSQkYwUhDVOVLKE puf83JbltuMH1fMCQrGn0ndczGm+6sQVx9E6YE1Kv17rvFVTq7hDMABQkbmXm9ot olzN3XLYLROeDJoZGoS8AUpxUbb/xysTEh6w/8/NUjV6tMLXXaEbx/DsakRsp3Qm 3Ekdfd+fme18hnJ8Oc8+1buT1FOxYfhBHydoxkhg/1DjwC29YayE7BkotyY/dOXY mNUm0wlQjVdOCA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeekgdelhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfggtggugfgjfgesthekre dttderudenucfhrhhomheptehlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgv segrlhhvhhdrnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepveejjeekjeejie evueduvdefffeihfffgfelhefgueegjeehuddvfeekiefhffdtnecuffhomhgrihhnpehp ohhsthhgrhgvshhqlhdrohhrghenucfkphepudeltddrleehrdduledrudejjeenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhr vgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: from perhan.alvh.no-ip.org (unknown [190.95.19.177]) by mail.messagingengine.com (Postfix) with ESMTPA id E509B24005B; Mon, 1 Feb 2021 12:00:50 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 6EC292A05A7; Mon, 1 Feb 2021 14:00:48 -0300 (-03) Date: Mon, 1 Feb 2021 14:00:48 -0300 From: Alvaro Herrera To: Julien Rouhaud Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Faulty HEAP_XMAX_LOCK_ONLY & HEAP_KEYS_UPDATED hintbit combination Message-ID: <20210201170048.GA22366@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210124061758.GA11756@nol> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2021-Jan-24, Julien Rouhaud wrote: > While working on pg14 compatibility for an extension relying on an apparently > uncommon combination of FOR UPDATE and stored function calls, I hit some new > Asserts introduced in 866e24d47db (Extend amcheck to check heap pages): > > + /* > + * Do not allow tuples with invalid combinations of hint bits to be placed > + * on a page. These combinations are detected as corruption by the > + * contrib/amcheck logic, so if you disable one or both of these > + * assertions, make corresponding changes there. > + */ > + Assert(!((tuple->t_data->t_infomask & HEAP_XMAX_LOCK_ONLY) && > + (tuple->t_data->t_infomask2 & HEAP_KEYS_UPDATED))); > > > I attach a simple self contained script to reproduce the problem, the last > UPDATE triggering the Assert. Maybe we should contest the idea that this is a sensible thing to Assert against. AFAICS this was originally suggested here: https://www.postgresql.org/message-id/flat/CAFiTN-syyHc3jZoou51v0SR8z0POoNfktqEO6MaGig4YS8mosA%40mail.gmail.com#ad215d0ee0606b5f67bbc57d011c96b8 and it appears now to have been a bad idea. If I recall correctly, HEAP_KEYS_UPDATED is supposed to distinguish locks/updates that don't modify the key columns from those that do. Since SELECT FOR UPDATE stands for a future update that may modify arbitrary portions of the tuple (including "key" columns), then it produces that bit, just as said UPDATE or a DELETE; as opposed to SELECT FOR NO KEY UPDATE which stands for a future UPDATE that will only change columns that aren't part of any keys. So I think that I misspoke earlier in this thread when I said this is a bug, and that the right fix here is to remove the Assert() and change amcheck to match. Separately, maybe it'd also be good to have a test case based on Julien's SQL snippet that produces this particular infomask combination (and other interesting combinations) and passes them through VACUUM etc to see that everything behaves correctly. You could also argue the HEAP_KEYS_UPDATED is a misnomer and that we'd do well to change its name, and update README.tuplock. -- Álvaro Herrera 39°49'30"S 73°17'W Bob [Floyd] used to say that he was planning to get a Ph.D. by the "green stamp method," namely by saving envelopes addressed to him as 'Dr. Floyd'. After collecting 500 such letters, he mused, a university somewhere in Arizona would probably grant him a degree. (Don Knuth)