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 1wJbNp-0003NE-1k for pgsql-bugs@arkaria.postgresql.org; Sun, 03 May 2026 18:17:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wJbNo-004B94-0x for pgsql-bugs@arkaria.postgresql.org; Sun, 03 May 2026 18:17:36 +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 1wJbNn-004B8h-2v for pgsql-bugs@lists.postgresql.org; Sun, 03 May 2026 18:17:36 +0000 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wJbNl-00000000JXP-0D11 for pgsql-bugs@postgresql.org; Sun, 03 May 2026 18:17:35 +0000 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 5CCBDC0152; Sun, 03 May 2026 21:17:31 +0300 (MSK) Received: from smtpclient.apple (unknown [2a02:6bf:8080:86e::1:c]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp) with ESMTPSA id THjBH81MIuQ0-OVUVGwrJ; Sun, 03 May 2026 21:17:30 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1777832251; bh=MCBrPWhAAdhWa3J8k0wBCMwGapqVb3AazwYJMPKMIH4=; h=References:To:Cc:In-Reply-To:Date:From:Message-Id:Subject; b=ECXYNdzwefbhXui29lkE5m2dqigi0U5udiSSvl1h7rg5I3+O2j/1QAXuFCHvMynNT lNNrq4azn4SrnQ/iZN48RfLOYLwReaCDaBTS6tmNOTjKuvxoZ8bhxD4aEQyFcoPgNj lDjz7MQj7S1hAyGfmV6Vx1iGXZLtSzUk/XGxN84s= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Andrey Borodin Message-Id: <71E42FAF-FF92-4EE5-94A5-341EFB891281@yandex-team.ru> Content-Type: multipart/mixed; boundary="Apple-Mail=_1E6975B4-CF08-402E-8131-29B974A8BDCF" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.500.181\)) Subject: Re: [BUG] false positive in bt_index_check in case of short 4B varlena datum Date: Sun, 3 May 2026 23:17:19 +0500 In-Reply-To: Cc: Alexander Korotkov , Alexander Lakhin , Michael Zhilin , pgsql-bugs@postgresql.org, Yura Sokolov To: Andres Freund References: <0b535249-a00c-a38a-85f6-d5a38c62dd55@gmail.com> <7ckc7oka4bvafkf5bwlqs6ygrhlsbhz25ppozfch7zbuxcx3rf@e4pr4oqenalc> X-Mailer: Apple Mail (2.3864.500.181) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_1E6975B4-CF08-402E-8131-29B974A8BDCF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On 2 May 2026, at 00:41, Andres Freund wrote: >=20 > This is checking (as you noted) !VARATT_IS_EXTENDED, whereas the > bt_normalize_tuple() code is checking !VARATT_IS_COMPRESSED. >=20 > 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). >=20 > I didn't find other instanes of similar code that uses = !VARATT_IS_COMPRESSED. As far as I understand=20 !VARATT_IS_COMPRESSED(DatumGetPointer(normalized[i])) && = !VARATT_IS_SHORT(DatumGetPointer(normalized[i])) is exactly !VARATT_IS_EXTENDED(DatumGetPointer(untoasted_values[i])) Which is what was proposed in v2 patch. But later was changed to = !VARATT_IS_COMPRESSED(). As I understood it was done to further strengthen normalization. So the intent might be that short varatts need normalization in some = cases. But we have no tests that show such a case. I tried to build a problematic storage alternation like [0], but = everything works nicely. So I propose something in a line with attached patch. Best regards, Andrey Borodin. [0] = https://github.com/postgres/postgres/blob/master/contrib/amcheck/sql/check= _btree.sql#L170-L172 --Apple-Mail=_1E6975B4-CF08-402E-8131-29B974A8BDCF Content-Disposition: attachment; filename=0001-amcheck-avoid-using-VARSIZE-for-VARATT_IS_SHORT.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-amcheck-avoid-using-VARSIZE-for-VARATT_IS_SHORT.patch" Content-Transfer-Encoding: quoted-printable =46rom=20276482c76491b1aa18a729dd637342b374dcd7fa=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Andrey=20Borodin=20=0ADate:=20= Sun,=203=20May=202026=2023:13:59=20+0500=0ASubject:=20[PATCH]=20amcheck:=20= avoid=20using=20VARSIZE()=20for=20VARATT_IS_SHORT()=0A=0A---=0A=20= contrib/amcheck/verify_nbtree.c=20|=202=20+-=0A=20src/include/varatt.h=20= =20=20=20=20=20=20=20=20=20=20=20|=201=20+=0A=202=20files=20changed,=202=20= insertions(+),=201=20deletion(-)=0A=0Adiff=20--git=20= a/contrib/amcheck/verify_nbtree.c=20b/contrib/amcheck/verify_nbtree.c=0A= index=20b74ab5f7a05..a3394d88a4e=20100644=0A---=20= a/contrib/amcheck/verify_nbtree.c=0A+++=20= b/contrib/amcheck/verify_nbtree.c=0A@@=20-2888,7=20+2888,7=20@@=20= bt_normalize_tuple(BtreeCheckState=20*state,=20IndexTuple=20itup)=0A=20=09= =09=09=09=09=09=09ItemPointerGetBlockNumber(&(itup->t_tid)),=0A=20=09=09=09= =09=09=09=09ItemPointerGetOffsetNumber(&(itup->t_tid)),=0A=20=09=09=09=09= =09=09=09RelationGetRelationName(state->rel))));=0A-=09=09else=20if=20= (!VARATT_IS_COMPRESSED(DatumGetPointer(normalized[i]))=20&&=0A+=09=09= else=20if=20(!VARATT_IS_EXTENDED(DatumGetPointer(normalized[i]))=20&&=0A=20= =09=09=09=09=20VARSIZE(DatumGetPointer(normalized[i]))=20>=20= TOAST_INDEX_TARGET=20&&=0A=20=09=09=09=09=20(att->attstorage=20=3D=3D=20= TYPSTORAGE_EXTENDED=20||=0A=20=09=09=09=09=20=20att->attstorage=20=3D=3D=20= TYPSTORAGE_MAIN))=0Adiff=20--git=20a/src/include/varatt.h=20= b/src/include/varatt.h=0Aindex=20000bdf33b92..321342cab67=20100644=0A---=20= a/src/include/varatt.h=0A+++=20b/src/include/varatt.h=0A@@=20-297,6=20= +297,7=20@@=20typedef=20struct=0A=20static=20inline=20Size=0A=20= VARSIZE(const=20void=20*PTR)=0A=20{=0A+=09Assert(VARATT_IS_4B(PTR));=0A=20= =09return=20VARSIZE_4B(PTR);=0A=20}=0A=20=0A--=20=0A2.50.1=20(Apple=20= Git-155)=0A=0A= --Apple-Mail=_1E6975B4-CF08-402E-8131-29B974A8BDCF--