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 1wItjd-008dQD-22 for pgsql-bugs@arkaria.postgresql.org; Fri, 01 May 2026 19:41:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wItjc-00CHjL-2q for pgsql-bugs@arkaria.postgresql.org; Fri, 01 May 2026 19:41:12 +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 1wItjc-00CHjD-0t for pgsql-bugs@lists.postgresql.org; Fri, 01 May 2026 19:41:12 +0000 Received: from fhigh-b6-smtp.messagingengine.com ([202.12.124.157]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wItjZ-00000004Jkc-2xhN for pgsql-bugs@postgresql.org; Fri, 01 May 2026 19:41:12 +0000 Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.stl.internal (Postfix) with ESMTP id 6B3BC7A009C; Fri, 1 May 2026 15:41:07 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Fri, 01 May 2026 15:41:07 -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=1777664467; x=1777750867; bh=7NtZxSgK2U OSjgT30VuV7+ggPemDvg3tLF9t3jD+mYw=; b=lOBhKDk30sPkvki0SaVHeafGoA xikVabR8tgy5Q1TjcA572pIUckEQvGXg6xMctTCOPkyaoOKKWVj6QIgN5p/HjkFW Ea3RBfE7U/cOn3KALpx9vQ8K6liiIli+ZPjgHa2lwiPFbKfEPelPTJq2U4kkNgmv 7Dz15c28N9I7r4fIkVN3F1krctb0m4NHfALlJAToyzeyoXYTL1h4TjPw2llVuuYT 7S/CWdSQbuIUPzXKVMgNGm0MBfO76lNBadxusKg6pfUR3XUSlQH0IM5mhrAhmKd9 43QlG+sa06K0YZu5HzVoBILAii+QWgC7luoL5XJRfO8dO49+WDnbOImJg7qA== 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= 1777664467; x=1777750867; bh=7NtZxSgK2UOSjgT30VuV7+ggPemDvg3tLF9 t3jD+mYw=; b=pTqaxW0zxWISCuXdZeWdoNkD+nBxXvllusdh54T85HyA2PO81fh NSk0Uhd0eqMuWpA+Rg7cqVA36NO1Cyn7Z480uoOImwOAprWhC9VN6odX2kX+v9hM L3/lEdYZuzUZRZ1nFbRmqiOo7xT1+i7flRntApyWd6BfLkxd82B134oTUMyaDMaM S/UftoDviYZzkYw5Qe9NJ6ihsXR6aSeSCIRZmiKu9KuXJtPdCGjmB5N8/13trt5m SHyaIlQq5VLgTtTZGBSiTCBjHK0YkIvJQ70fIOgc3YAqf4+iuUrmHhRmellyNcIz L4fdjVe5zEoExp1JKp7fVRnyfiEOKuRHz7w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdeluddtiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfhfgggtuggjsehttdfstddttddvnecuhfhrohhmpeetnhgurhgvshcu hfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrghtth gvrhhnpeeffffgledvffegtdevlefgtdeggffhvdekgfegteeiveejkeetudelveejhfeu geenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnh gurhgvshesrghnrghrrgiivghlrdguvgdpnhgspghrtghpthhtohepiedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheprggvkhhorhhothhkohhvsehgmhgrihhlrdgtohhmpd hrtghpthhtohepvgigtghluhhsihhonhesghhmrghilhdrtghomhdprhgtphhtthhopehm rdiihhhilhhinhesphhoshhtghhrvghsphhrohdrrhhupdhrtghpthhtohephidrshhokh holhhovhesphhoshhtghhrvghsphhrohdrrhhupdhrtghpthhtohepphhgshhqlhdqsghu ghhssehpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopeiggehmmhhmseihrghnug gvgidqthgvrghmrdhruh X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 May 2026 15:41:06 -0400 (EDT) Date: Fri, 1 May 2026 15:41:05 -0400 From: Andres Freund To: Andrey Borodin Cc: Alexander Korotkov , Alexander Lakhin , 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: References: <0b535249-a00c-a38a-85f6-d5a38c62dd55@gmail.com> <7ckc7oka4bvafkf5bwlqs6ygrhlsbhz25ppozfch7zbuxcx3rf@e4pr4oqenalc> 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 2026-05-01 23:06:49 +0500, Andrey Borodin wrote: > > On 1 May 2026, at 22:11, Andres Freund wrote: > > > > 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. > > I remember the original code was taken from somewhere else because there > was already some instances like this: > /* > * If value is above size target, and is of a compressible datatype, > * try to compress it in-line. > */ > if (!VARATT_IS_EXTENDED(DatumGetPointer(untoasted_values[i])) && > VARSIZE(DatumGetPointer(untoasted_values[i])) > TOAST_INDEX_TARGET && > (att->attstorage == TYPSTORAGE_EXTENDED || > att->attstorage == TYPSTORAGE_MAIN)) > { > > I don't have VARATT_IS_EXTENDED vs VARATT_IS_COMPRESSED vs VARATT_IS_SHORT > business in my warm cache right away, but I'll try to remember what it means soon. This is checking (as you noted) !VARATT_IS_EXTENDED, whereas the bt_normalize_tuple() code is checking !VARATT_IS_COMPRESSED. VARATT_IS_EXTENDED() will return true for short varlenas (because it's not a standard 4 byte uncompressed varlena), whereas VARATT_IS_COMPRESSED() will return false for a short varlena (since it's not compressed). I didn't find other instanes of similar code that uses !VARATT_IS_COMPRESSED. Greetings, Andres Freund