diff --git a/src/hnswbuild.c b/src/hnswbuild.c index 90ff9c3..2463e29 100644 --- a/src/hnswbuild.c +++ b/src/hnswbuild.c @@ -151,9 +151,6 @@ CreateElementPages(HnswBuildState * buildstate) e->offno = PageAddItem(page, (Item) element, elementsz, InvalidOffsetNumber, false, false); if (e->offno == InvalidOffsetNumber) elog(ERROR, "failed to add index item to \"%s\"", RelationGetRelationName(index)); - - if (e == buildstate->entryPoint) - UpdateMetaPage(index, true, e, InvalidBlockNumber, forkNum); } insertPage = BufferGetBlockNumber(buf); @@ -163,7 +160,7 @@ CreateElementPages(HnswBuildState * buildstate) GenericXLogFinish(state); UnlockReleaseBuffer(buf); - UpdateMetaPage(index, false, NULL, insertPage, forkNum); + UpdateMetaPage(index, true, buildstate->entryPoint, insertPage, forkNum); } /* diff --git a/src/hnswutils.c b/src/hnswutils.c index 62a9e99..8eaec74 100644 --- a/src/hnswutils.c +++ b/src/hnswutils.c @@ -876,8 +876,16 @@ UpdateMetaPage(Relation index, bool updateEntry, HnswElement entryPoint, BlockNu if (updateEntry) { - metap->entryBlkno = entryPoint->blkno; - metap->entryOffno = entryPoint->offno; + if (entryPoint == NULL) + { + metap->entryBlkno = InvalidBlockNumber; + metap->entryOffno = InvalidOffsetNumber; + } + else + { + metap->entryBlkno = entryPoint->blkno; + metap->entryOffno = entryPoint->offno; + } } if (BlockNumberIsValid(insertPage))