[BUG] Error in BRIN summarization
Anastasia Lubennikova <a.lubennikova@postgrespro.ru>
From: Anastasia Lubennikova <a.lubennikova@postgrespro.ru>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2020-07-23T17:39:11Z
Lists: pgsql-hackers
Attachments
- brin_summarize_fix_v0.patch (text/x-patch) patch v0
- brin_test.sql (application/sql)
One of our clients caught an error "failed to find parent tuple for
heap-only tuple at (50661,130) in table "tbl'" in PostgreSQL v12.
Steps to reproduce (REL_12_STABLE):
1) Create table with primary key, create brin index, fill table with
some initial data:
create table tbl (id int primary key, a int) with (fillfactor=50);
create index idx on tbl using brin (a) with (autosummarize=on);
insert into tbl select i, i from generate_series(0,100000) as i;
2) Run script test_brin.sql using pgbench:
pgbench postgres -f ../review/brin_test.sql -n -T 120
The script is a bit messy because I was trying to reproduce a
problematic workload. Though I didn't manage to simplify it.
The idea is that it inserts new values into the table to produce
unindexed pages and also updates some values to trigger HOT-updates on
these pages.
3) Open psql session and run brin_summarize_new_values
select brin_summarize_new_values('idx'::regclass::oid); \watch 2
Wait a bit. And in psql you will see the ERROR.
This error is caused by the problem with root_offsets array bounds. It
occurs if a new HOT tuple was inserted after we've collected
root_offsets, and thus we don't have root_offset for tuple's offnum.
Concurrent insertions are possible, because brin_summarize_new_values()
only holds ShareUpdateLock on table and no lock (only pin) on the page.
The draft fix is in the attachments. It saves root_offsets_size and
checks that we only access valid fields.
Patch also adds some debug messages, just to ensure that problem was caught.
TODO:
- check if heapam_index_validate_scan() has the same problem
- code cleanup
- test other PostgreSQL versions
[1]
https://www.postgresql.org/message-id/flat/CA%2BTgmoYgwjmmjK24Qxb_vWAu8_Hh7gfVFcr3%2BR7ocdLvYOWJXg%40mail.gmail.com
--
Anastasia Lubennikova
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Commits
-
Disable autovacuum for BRIN test table
- b83f1bcca0bb 13.0 landed
- 6e70443edacf 14.0 landed
- 4f47c8e7d438 12.5 landed
- 060e5bd70e4d 11.10 landed
- d4d21490376e 9.6.20 landed
- aa4da2674ca2 9.5.24 landed
- 3a45ac076aab 10.15 landed
-
Handle new HOT chains in index-build table scans
- e5902117dd83 9.6.20 landed
- a811ea5bde2f 14.0 landed
- 704de3739c5b 11.10 landed
- 40bceae7b4de 9.5.24 landed
- 385cbe8e4197 10.15 landed
- 2f29fd4cb252 13.0 landed
- 1122a903e967 12.5 landed
-
BRIN: Handle concurrent desummarization properly
- ce3a8fde8e62 9.5.24 landed
- 8782ea2f36a2 13.0 landed
- 7af39993a47c 11.10 landed
- 7a3c261fbbb4 9.6.20 landed
- 721ef4d28aae 10.15 landed
- 1f42d35a1d61 14.0 landed
- 0426c75e7d1d 12.5 landed