mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-05 20:20:59 +08:00
Improved HNSW vacuum performance
This commit is contained in:
@@ -283,11 +283,33 @@ WriteNewElementPages(Relation index, HnswElement e, int m, BlockNumber insertPag
|
||||
*updatedInsertPage = newInsertPage;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get index of deleted neighbor
|
||||
*/
|
||||
static int
|
||||
GetDeletedIndex(HnswElement element, HTAB *deleted, int lc)
|
||||
{
|
||||
HnswNeighborArray *neighbors = &element->neighbors[lc];
|
||||
|
||||
for (int i = 0; i < neighbors->length; i++)
|
||||
{
|
||||
HnswCandidate *hc = &neighbors->items[i];
|
||||
ItemPointerData ipData;
|
||||
|
||||
ItemPointerSet(&ipData, hc->element->blkno, hc->element->offno);
|
||||
|
||||
if (HnswDeletedContains(deleted, &ipData))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update neighbors
|
||||
*/
|
||||
void
|
||||
UpdateNeighborPages(Relation index, FmgrInfo *procinfo, Oid collation, HnswElement e, int m)
|
||||
UpdateNeighborPages(Relation index, FmgrInfo *procinfo, Oid collation, HnswElement e, int m, HTAB *deleted)
|
||||
{
|
||||
for (int lc = e->level; lc >= 0; lc--)
|
||||
{
|
||||
@@ -311,8 +333,13 @@ UpdateNeighborPages(Relation index, FmgrInfo *procinfo, Oid collation, HnswEleme
|
||||
/* Do not lock yet since selecting neighbors can take time */
|
||||
HnswLoadNeighbors(hc->element, index);
|
||||
|
||||
/* Find deleted index without loading elements if possible */
|
||||
if (deleted != NULL)
|
||||
idx = GetDeletedIndex(hc->element, deleted, lc);
|
||||
|
||||
/* Select neighbors */
|
||||
HnswUpdateConnection(e, hc, lm, lc, &idx, index, procinfo, collation);
|
||||
if (idx == -1)
|
||||
HnswUpdateConnection(e, hc, lm, lc, &idx, index, procinfo, collation);
|
||||
|
||||
/* New element was not selected as a neighbor */
|
||||
if (idx == -1)
|
||||
@@ -484,7 +511,7 @@ WriteElement(Relation index, FmgrInfo *procinfo, Oid collation, HnswElement elem
|
||||
HnswUpdateMetaPage(index, false, NULL, newInsertPage, MAIN_FORKNUM);
|
||||
|
||||
/* Update neighbors */
|
||||
UpdateNeighborPages(index, procinfo, collation, element, m);
|
||||
UpdateNeighborPages(index, procinfo, collation, element, m, NULL);
|
||||
|
||||
/* Update metapage if needed */
|
||||
if (element->level > entryPoint->level)
|
||||
|
||||
Reference in New Issue
Block a user