agora inbox for pgsql-bugs@postgresql.org  
help / color / mirror / Atom feed
From: Alexander Lakhin <exclusion@gmail.com>
To: Michael Zhilin <m.zhilin@postgrespro.ru>
To: pgsql-bugs@postgresql.org
Cc: y sokolov <y.sokolov@postgrespro.ru>
Subject: Re: [BUG] false positive in bt_index_check in case of short 4B varlena datum
Date: Thu, 14 Dec 2023 20:17:17 +0300
Message-ID: <59716bbe-fe82-92a9-1e35-171b2ed221be@gmail.com> (raw)
In-Reply-To: <7bdbe559-d61a-4ae4-a6e1-48abdf3024cc@postgrespro.ru>
References: <7bdbe559-d61a-4ae4-a6e1-48abdf3024cc@postgrespro.ru>

Hi Michael,

14.12.2023 19:18, Michael Zhilin wrote:
> Hi,
>
> Following example produces error raised from bt_index_check.
>
> drop table if exists t;
> create table t (v text);
> alter table t alter column v set storage plain;
> insert into t values ('x');
> copy t to '/tmp/1.lst';
> copy t from '/tmp/1.lst';
> create index t_idx on t(v);
> create extension if not exists amcheck;
> select bt_index_check('t_idx', true);
>
> postgres=# select bt_index_check('t_idx', true);
> ERROR:  heap tuple (0,2) from table "t" lacks matching index tuple within index "t_idx"
> HINT:  Retrying verification using the function bt_index_parent_check() might provide a more specific error.
>
> As result table contains 2 logically identical tuples:
>  - one contains varlena 'x' with 1B (1-byte) header (added by INSERT statement)
>  - one contains varlena 'x' with 4B (4-bytes) header (added by COPY statement)
> CREATE INDEX statement builds index with posting list referencing both heap tuples.
> The function bt_index_check calculates fingerprints of 1B and 4B header datums,
> they are different and function returns error.
>
> The attached patch allows to avoid such kind of false positives by converting short
> 4B datums to 1B before fingerprinting. Also it contains test for provided case.

By changing the storage mode for a column, you can also get another error:
CREATE TABLE t(f1 text);
CREATE INDEX t_idx ON t(f1);
INSERT INTO t VALUES(repeat('1234567890', 1000));
ALTER TABLE t ALTER COLUMN f1 SET STORAGE plain;

CREATE EXTENSION amcheck;
SELECT bt_index_check('t_idx', true);

ERROR:  index row requires 10016 bytes, maximum size is 8191

Best regards,
Alexander





view thread (31+ messages)  latest in thread

Message-ID: <59716bbe-fe82-92a9-1e35-171b2ed221be@gmail.com>
Permalink:  ../59716bbe-fe82-92a9-1e35-171b2ed221be@gmail.com/
Also on:    postgresql.org/message-id/59716bbe-fe82-92a9-1e35-171b2ed221be@gmail.com

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: pgsql-bugs@postgresql.org
  Cc: exclusion@gmail.com, m.zhilin@postgrespro.ru, y.sokolov@postgrespro.ru
  Subject: Re: [BUG] false positive in bt_index_check in case of short 4B varlena datum
  In-Reply-To: <59716bbe-fe82-92a9-1e35-171b2ed221be@gmail.com>

* 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