BUG #19686: Rolling back SET TABLESPACE + INSERT leads to index corruption - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #19686: Rolling back SET TABLESPACE + INSERT leads to index corruption
Date
Msg-id 19686-30f4da834585129f@postgresql.org
Whole thread
Responses Re: BUG #19686: Rolling back SET TABLESPACE + INSERT leads to index corruption
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      19686
Logged by:          Alexander Lakhin
Email address:      exclusion@gmail.com
PostgreSQL version: 19beta3
Operating system:   Ubuntu 24.04
Description:

The following script:
rm -rf /tmp/ts
mkdir /tmp/ts

echo "
CREATE TABLESPACE ts LOCATION '/tmp/ts';
CREATE TABLE t (a int);
CREATE INDEX ON t(a);

BEGIN;
ALTER TABLE t SET TABLESPACE ts;
INSERT INTO t VALUES (0);
ROLLBACK;
INSERT INTO t VALUES (0);
INSERT INTO t SELECT i FROM generate_series(1, 4000) i;
" | psql

triggers:
2026-09-13 18:09:42.598 EEST|postgres|regression|6aa6bcb6.297fd6|LOG:
statement: INSERT INTO t SELECT i FROM generate_series(1, 4000) i;
TRAP: failed Assert("_bt_posting_valid(itup)"), File: "nbtdedup.c", Line:
900, PID: 2719702
ExceptionalCondition at assert.c:51:13
_bt_form_posting at nbtdedup.c:905:7
_bt_dedup_finish_pending at nbtdedup.c:584:11
_bt_dedup_pass at nbtdedup.c:173:15
_bt_delete_or_dedup_one_page at nbtinsert.c:2827:3
_bt_findinsertloc at nbtinsert.c:918:4
_bt_doinsert at nbtinsert.c:261:16
btinsert at nbtree.c:219:11
index_insert at indexam.c:231:9

The assertion failure is reproduced starting from 0d861bbb7.

The index corruption is also reproduced with gist:
echo "
CREATE TABLESPACE ts LOCATION '/tmp/ts';
CREATE TABLE t (a int4range);
CREATE INDEX ON t USING gist (a);

BEGIN;
ALTER TABLE t SET TABLESPACE ts;
INSERT INTO t VALUES (int4range(0, 5));
ROLLBACK;
INSERT INTO t VALUES (int4range(0, 5));
" | psql

echo "
SELECT * FROM t;
SET enable_seqscan = off;
SET enable_bitmapscan = off;
EXPLAIN SELECT * FROM t WHERE a && int4range(0, 100);
SELECT * FROM t WHERE a && int4range(0, 100);
" | psql

returns:
ROLLBACK
INSERT 0 1
   a
-------
 [0,5)
(1 row)

SET
SET
                               QUERY PLAN
-------------------------------------------------------------------------
 Index Only Scan using t_a_idx on t  (cost=0.14..40.39 rows=14 width=32)
   Index Cond: (a && '[0,100)'::int4range)
(2 rows)

   a
-------
 [0,5)
 [0,5)
(2 rows)





pgsql-bugs by date:

Previous
From: Ayush Tiwari
Date:
Subject: Re: BUG #19684: Assertion in tuplesort_begin_heap() falsified by parallel plan with sort
Next
From: PG Bug reporting form
Date:
Subject: BUG #19687: ALTER SEQUENCE provokes error XX001 could not read blocks