public inbox for [email protected]  
help / color / mirror / Atom feed
From: Andres Freund <[email protected]>
To: Andrey Borodin <[email protected]>
Cc: Alexander Korotkov <[email protected]>
Cc: Alexander Lakhin <[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 15:41:05 -0400
Message-ID: <c64tbgvkqu6v5y66lkitiy6dd32ksrwz3nysbclqnyztstx2lj@ymw4bqsf7zpv> (raw)
In-Reply-To: <[email protected]>
References: <[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>
	<7ckc7oka4bvafkf5bwlqs6ygrhlsbhz25ppozfch7zbuxcx3rf@e4pr4oqenalc>
	<[email protected]>

Hi,

On 2026-05-01 23:06:49 +0500, Andrey Borodin wrote:
> > On 1 May 2026, at 22:11, Andres Freund <[email protected]> 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






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: <c64tbgvkqu6v5y66lkitiy6dd32ksrwz3nysbclqnyztstx2lj@ymw4bqsf7zpv>

* 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