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

Skip to content

Commit d70cf81

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 d663d43 commit d70cf81

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
@@ -2438,7 +2438,10 @@ IndexBuildHeapScan(Relation heapRelation,
24382438
rootTuple = *heapTuple;
24392439
offnum = ItemPointerGetOffsetNumber(&heapTuple->t_self);
24402440

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

24432446
ItemPointerSetOffsetNumber(&rootTuple.t_self,
24442447
root_offsets[offnum - 1]);
@@ -2856,7 +2859,11 @@ validate_index_heapscan(Relation heapRelation,
28562859
if (HeapTupleIsHeapOnly(heapTuple))
28572860
{
28582861
root_offnum = root_offsets[root_offnum - 1];
2859-
Assert(OffsetNumberIsValid(root_offnum));
2862+
if (!OffsetNumberIsValid(root_offnum))
2863+
elog(ERROR, "failed to find parent tuple for heap-only tuple at (%u,%u) in table \"%s\"",
2864+
ItemPointerGetBlockNumber(heapcursor),
2865+
ItemPointerGetOffsetNumber(heapcursor),
2866+
RelationGetRelationName(heapRelation));
28602867
ItemPointerSetOffsetNumber(&rootTuple, root_offnum);
28612868
}
28622869

0 commit comments

Comments
 (0)