Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c370125

Browse files
committed
During index build, check and elog (not just Assert) for broken HOT chain.
The recently-fixed bug in WAL replay could result in not finding a parent tuple for a heap-only tuple. The existing code would either Assert or generate an invalid index entry, neither of which is desirable. Throw a regular error instead.
1 parent 3857234 commit c370125

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/backend/catalog/index.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,7 +2476,10 @@ IndexBuildHeapScan(Relation heapRelation,
24762476
rootTuple = *heapTuple;
24772477
offnum = ItemPointerGetOffsetNumber(&heapTuple->t_self);
24782478

2479-
Assert(OffsetNumberIsValid(root_offsets[offnum - 1]));
2479+
if (!OffsetNumberIsValid(root_offsets[offnum - 1]))
2480+
elog(ERROR, "failed to find parent tuple for heap-only tuple at (%u,%u) in table \"%s\"",
2481+
ItemPointerGetBlockNumber(&heapTuple->t_self),
2482+
offnum, RelationGetRelationName(heapRelation));
24802483

24812484
ItemPointerSetOffsetNumber(&rootTuple.t_self,
24822485
root_offsets[offnum - 1]);
@@ -2891,7 +2894,11 @@ validate_index_heapscan(Relation heapRelation,
28912894
if (HeapTupleIsHeapOnly(heapTuple))
28922895
{
28932896
root_offnum = root_offsets[root_offnum - 1];
2894-
Assert(OffsetNumberIsValid(root_offnum));
2897+
if (!OffsetNumberIsValid(root_offnum))
2898+
elog(ERROR, "failed to find parent tuple for heap-only tuple at (%u,%u) in table \"%s\"",
2899+
ItemPointerGetBlockNumber(heapcursor),
2900+
ItemPointerGetOffsetNumber(heapcursor),
2901+
RelationGetRelationName(heapRelation));
28952902
ItemPointerSetOffsetNumber(&rootTuple, root_offnum);
28962903
}
28972904

0 commit comments

Comments
 (0)