pgsql: Handle new HOT chains in index-build table scans - Mailing list pgsql-committers

From Alvaro Herrera
Subject pgsql: Handle new HOT chains in index-build table scans
Date
Msg-id E1k6L5g-0000UZ-AO@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Handle new HOT chains in index-build table scans

When a table is scanned by heapam_index_build_range_scan (née
IndexBuildHeapScan) and the table lock being held allows concurrent data
changes, it is possible for new HOT chains to sprout in a page that were
unknown when the scan of a page happened.  This leads to an error such
as
  ERROR:  failed to find parent tuple for heap-only tuple at (X,Y) in table "tbl"
because the root tuple was not present when we first obtained the list
of the page's root tuples.  This can be fixed by re-obtaining the list
of root tuples, if we see that a heap-only tuple appears to point to a
non-existing root.

This was reported by Anastasia as occurring for BRIN summarization
(which exists since 9.5), but I think it could theoretically also happen
with CREATE INDEX CONCURRENTLY (much older) or REINDEX CONCURRENTLY
(very recent).  It seems a happy coincidence that BRIN forces us to
backpatch this all the way to 9.5.

Reported-by: Anastasia Lubennikova <a.lubennikova@postgrespro.ru>
Diagnosed-by: Anastasia Lubennikova <a.lubennikova@postgrespro.ru>
Co-authored-by: Anastasia Lubennikova <a.lubennikova@postgrespro.ru>
Co-authored-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/602d8487-f0b2-5486-0088-0f372b2549fa@postgrespro.ru
Backpatch: 9.5 - master

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1122a903e967a388a1a8f20de15dc65ca639d407

Modified Files
--------------
src/backend/access/heap/heapam_handler.c | 20 ++++++++++++++++++++
src/backend/access/heap/pruneheap.c      |  5 +++--
2 files changed, 23 insertions(+), 2 deletions(-)


pgsql-committers by date:

Previous
From: Andres Freund
Date:
Subject: pgsql: Fix out-of-date version reference, grammar.
Next
From: Andres Freund
Date:
Subject: pgsql: snapshot scalability: Move PGXACT->xmin back to PGPROC.