public inbox for [email protected]  
help / color / mirror / Atom feed
From: Andres Freund <[email protected]>
To: Alexander Korotkov <[email protected]>
Cc: Alexander Lakhin <[email protected]>
Cc: Andrey M. Borodin <[email protected]>
Cc: Michael Zhilin <[email protected]>
Cc: [email protected]
Cc: Yura Sokolov <[email protected]>
Subject: Re: [BUG] false positive in bt_index_check in case of short 4B varlena datum
Date: Fri, 1 May 2026 13:11:13 -0400
Message-ID: <7ckc7oka4bvafkf5bwlqs6ygrhlsbhz25ppozfch7zbuxcx3rf@e4pr4oqenalc> (raw)
In-Reply-To: <CAPpHfdspqdzVdEU2qHMibKn8OwVuLoZZYvKm-m5Ffqy2aMXgGQ@mail.gmail.com>
References: <[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CAPpHfdsAs-B7O2_=jGbF+BQzuW3kGSboY9CcxzEOWUgxxZCr5Q@mail.gmail.com>
	<[email protected]>
	<CAPpHfdtZxhgjZTpaLd--dCxzUOL6tN+aAZPBeTsGKHLkMQAZpw@mail.gmail.com>
	<CAPpHfdu412Z+jh5Oyc1yzWFM0+52h0kSGQKV4=xQ0aT0UeY2BA@mail.gmail.com>
	<CAPpHfdspqdzVdEU2qHMibKn8OwVuLoZZYvKm-m5Ffqy2aMXgGQ@mail.gmail.com>

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






reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: [BUG] false positive in bt_index_check in case of short 4B varlena datum
  In-Reply-To: <7ckc7oka4bvafkf5bwlqs6ygrhlsbhz25ppozfch7zbuxcx3rf@e4pr4oqenalc>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox