Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wIrOc-008Xdw-0x for pgsql-bugs@arkaria.postgresql.org; Fri, 01 May 2026 17:11:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wIrOZ-00BjFT-0N for pgsql-bugs@arkaria.postgresql.org; Fri, 01 May 2026 17:11:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wIrOY-00BjFJ-2k for pgsql-bugs@lists.postgresql.org; Fri, 01 May 2026 17:11:18 +0000 Received: from fout-a6-smtp.messagingengine.com ([103.168.172.149]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wIrOW-00000004Idv-1PO9 for pgsql-bugs@postgresql.org; Fri, 01 May 2026 17:11:18 +0000 Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id 2526BEC0081; Fri, 1 May 2026 13:11:15 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Fri, 01 May 2026 13:11:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1777655475; x=1777741875; bh=rfeF0cQwjP 3yckGPhjQYAO2a4PtK8N1Dn+Ab9tPsx3Q=; b=fgQSxi9RqrHTEVs943kWe0msMh BtWy6hWYqjjRbMefNimqj56CBVN3u9KbsnTmKEfWgMtd072lxBuBYk+/mM0rExiy 2hKN5SUPIE9GuU9l/ETrt0Z1cOaynhw+D/BfvWp2iSvzGFOAiCj+wzoTWBkUA0FM zVqOFvkx6Fd4fKQJfOcM30S3zoS9sy7fIapD5JN5R7COdgMTaW/mxgzH5JqkV1ls i8tJldKzNLUf/hjIf9vXUgZYzC+kvoW94YeKGPBXiwPEnhBjRtXTopEqCymiz0qr Czh8fcNsjOoU10KYczXKOd8qdSzHkNO1gQP4DbfEW0Z9EIbRmJwjopWvt+CQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1777655475; x=1777741875; bh=rfeF0cQwjP3yckGPhjQYAO2a4PtK8N1Dn+A b9tPsx3Q=; b=oxoTS/cQN4XPo2HYLLpdF0hTqi5ITVMdW0kqWDMfIZgfU1nQKHF sFO3Njx8Z3FzXJ00tIZfA49k2CnG98ZbmwofcWaOFcCzFQEneZavnTus2zlShD7M kcfbJWMM6Nr9dSKjRfok0xv0yFIPNfoxo7j4u5eSvDlY3CDg/N/X5JkPO5ibtyvG LiKvCBD/CDY64+0WErH0WGM/fvVE7kGs1g73CIr3SpMbzOoQ8uIEk7i5e5ktlhI6 s0uAiv/BDjsZhsw0Ri1z15NBUusIDsSOmt4lnM+MrqMYa8c1Cu5nOmAMSAN/WwuN Z2tNDTXHg12YbfLHqUFvom4vuHOszk+l9JA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdeltdejjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfhfgggtuggjsehttdfstddttddvnecuhfhrohhmpeetnhgurhgvshcu hfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrghtth gvrhhnpedtgfegjeefieevveetffdtheekjeeuieevkeehueekvdffleehhfdufeekgeet ffenucffohhmrghinhepvhgvrhhifhihpghnsghtrhgvvgdrtgifnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghnughrvghssegrnhgrrhgr iigvlhdruggvpdhnsggprhgtphhtthhopeeipdhmohguvgepshhmthhpohhuthdprhgtph htthhopegrvghkohhrohhtkhhovhesghhmrghilhdrtghomhdprhgtphhtthhopegvgigt lhhushhiohhnsehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhdriihhihhlihhnsehpoh hsthhgrhgvshhprhhordhruhdprhgtphhtthhopeihrdhsohhkohhlohhvsehpohhsthhg rhgvshhprhhordhruhdprhgtphhtthhopehpghhsqhhlqdgsuhhgshesphhoshhtghhrvg hsqhhlrdhorhhgpdhrtghpthhtohepgiegmhhmmheshigrnhguvgigqdhtvggrmhdrrhhu X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 May 2026 13:11:14 -0400 (EDT) Date: Fri, 1 May 2026 13:11:13 -0400 From: Andres Freund To: Alexander Korotkov Cc: Alexander Lakhin , "Andrey M. Borodin" , Michael Zhilin , pgsql-bugs@postgresql.org, Yura Sokolov Subject: Re: [BUG] false positive in bt_index_check in case of short 4B varlena datum Message-ID: <7ckc7oka4bvafkf5bwlqs6ygrhlsbhz25ppozfch7zbuxcx3rf@e4pr4oqenalc> References: <76bc0dc9-4e43-4cd8-8eec-249b254ed1c9@postgrespro.ru> <8C83FCCA-2548-499A-8B1C-96C3D8ADB787@yandex-team.ru> <0b535249-a00c-a38a-85f6-d5a38c62dd55@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2024-03-23 13:37:04 +0200, Alexander Korotkov wrote: > @@ -2981,6 +2982,18 @@ bt_normalize_tuple(BtreeCheckState *state, IndexTuple itup) > ItemPointerGetBlockNumber(&(itup->t_tid)), > ItemPointerGetOffsetNumber(&(itup->t_tid)), > RelationGetRelationName(state->rel)))); > + else if (!VARATT_IS_COMPRESSED(DatumGetPointer(normalized[i])) && > + VARSIZE(DatumGetPointer(normalized[i])) > TOAST_INDEX_TARGET && > + (att->attstorage == TYPSTORAGE_EXTENDED || > + att->attstorage == TYPSTORAGE_MAIN)) > + { > + /* > + * This value will be compressed by index_form_tuple() with the > + * current storage settings. We may be here because this tuple > + * was formed with different storage settings. So, force forming. > + */ > + formnewtup = true; > + } > else if (VARATT_IS_COMPRESSED(DatumGetPointer(normalized[i]))) > { > formnewtup = true; While hacking on something, I added an assertion to VARSIZE() that the argument is actually a VARATT_4B (which it assumes). Worked everywhere, except for this caller: amcheck/regress fails, because sometimes the varlena is actually a short/1B varlena. Note that VARSIZE_4B on a short datum will give you completely bogus answers. E.g. in the case that failed the assertion, VARSIZE_1B() is 2, but VARSIZE_4B(PTR) is 7681. diff --git i/contrib/amcheck/verify_nbtree.c w/contrib/amcheck/verify_nbtree.c index b74ab5f7a05..0b87109fde3 100644 --- i/contrib/amcheck/verify_nbtree.c +++ w/contrib/amcheck/verify_nbtree.c @@ -2889,6 +2889,7 @@ bt_normalize_tuple(BtreeCheckState *state, IndexTuple itup) ItemPointerGetOffsetNumber(&(itup->t_tid)), RelationGetRelationName(state->rel)))); else if (!VARATT_IS_COMPRESSED(DatumGetPointer(normalized[i])) && + !VARATT_IS_SHORT(DatumGetPointer(normalized[i])) && VARSIZE(DatumGetPointer(normalized[i])) > TOAST_INDEX_TARGET && (att->attstorage == TYPSTORAGE_EXTENDED || att->attstorage == TYPSTORAGE_MAIN)) Fixes the assert failure. I guess I find it aesthetically a bit unpleasing to check the same stuff so many times for one varlena :). Not that it should matter performance-wise here... Greetings, Andres Freund