mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-11 07:06:57 +08:00
Improving naming [skip ci]
This commit is contained in:
22
src/hnsw.h
22
src/hnsw.h
@@ -232,19 +232,27 @@ typedef HnswScanOpaqueData * HnswScanOpaque;
|
|||||||
|
|
||||||
typedef struct HnswVacuumState
|
typedef struct HnswVacuumState
|
||||||
{
|
{
|
||||||
|
/* Info */
|
||||||
Relation index;
|
Relation index;
|
||||||
IndexBulkDeleteResult *stats;
|
IndexBulkDeleteResult *stats;
|
||||||
IndexBulkDeleteCallback callback;
|
IndexBulkDeleteCallback callback;
|
||||||
void *callback_state;
|
void *callback_state;
|
||||||
|
|
||||||
|
/* Settings */
|
||||||
int m;
|
int m;
|
||||||
int efConstruction;
|
int efConstruction;
|
||||||
HTAB *deleted;
|
|
||||||
BufferAccessStrategy bas;
|
/* Support functions */
|
||||||
FmgrInfo *procinfo;
|
FmgrInfo *procinfo;
|
||||||
Oid collation;
|
Oid collation;
|
||||||
|
|
||||||
|
/* Variables */
|
||||||
|
HTAB *deleted;
|
||||||
|
BufferAccessStrategy bas;
|
||||||
HnswNeighborTuple ntup;
|
HnswNeighborTuple ntup;
|
||||||
Size nsize;
|
|
||||||
HnswElementData highestPoint;
|
HnswElementData highestPoint;
|
||||||
|
|
||||||
|
/* Memory */
|
||||||
MemoryContext tmpCtx;
|
MemoryContext tmpCtx;
|
||||||
} HnswVacuumState;
|
} HnswVacuumState;
|
||||||
|
|
||||||
@@ -258,13 +266,13 @@ Buffer HnswNewBuffer(Relation index, ForkNumber forkNum);
|
|||||||
void HnswInitPage(Buffer buf, Page page);
|
void HnswInitPage(Buffer buf, Page page);
|
||||||
void HnswInitRegisterPage(Relation index, Buffer *buf, Page *page, GenericXLogState **state);
|
void HnswInitRegisterPage(Relation index, Buffer *buf, Page *page, GenericXLogState **state);
|
||||||
void HnswInit(void);
|
void HnswInit(void);
|
||||||
List *SearchLayer(Datum q, List *ep, int ef, int lc, Relation index, FmgrInfo *procinfo, Oid collation, bool inserting, BlockNumber *skipPage, OffsetNumber *skipOffno);
|
List *HnswSearchLayer(Datum q, List *ep, int ef, int lc, Relation index, FmgrInfo *procinfo, Oid collation, bool inserting, BlockNumber *skipPage, OffsetNumber *skipOffno);
|
||||||
HnswElement GetEntryPoint(Relation index);
|
HnswElement HnswGetEntryPoint(Relation index);
|
||||||
HnswElement HnswInitElement(ItemPointer tid, int m, double ml, int maxLevel);
|
HnswElement HnswInitElement(ItemPointer tid, int m, double ml, int maxLevel);
|
||||||
void HnswFreeElement(HnswElement element);
|
void HnswFreeElement(HnswElement element);
|
||||||
HnswElement HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, FmgrInfo *procinfo, Oid collation, int m, int efConstruction, List **updates, bool vacuuming);
|
HnswElement HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, FmgrInfo *procinfo, Oid collation, int m, int efConstruction, List **updates, bool vacuuming);
|
||||||
HnswCandidate *EntryCandidate(HnswElement em, Datum q, Relation rel, FmgrInfo *procinfo, Oid collation, bool loadvec);
|
HnswCandidate *HnswEntryCandidate(HnswElement em, Datum q, Relation rel, FmgrInfo *procinfo, Oid collation, bool loadvec);
|
||||||
void UpdateMetaPage(Relation index, bool updateEntry, HnswElement entryPoint, BlockNumber insertPage, ForkNumber forkNum);
|
void HnswUpdateMetaPage(Relation index, bool updateEntry, HnswElement entryPoint, BlockNumber insertPage, ForkNumber forkNum);
|
||||||
void HnswSetNeighborTuple(HnswNeighborTuple ntup, HnswElement e, int m);
|
void HnswSetNeighborTuple(HnswNeighborTuple ntup, HnswElement e, int m);
|
||||||
void HnswAddHeapTid(HnswElement element, ItemPointer heaptid);
|
void HnswAddHeapTid(HnswElement element, ItemPointer heaptid);
|
||||||
void HnswInitNeighbors(HnswElement element, int m);
|
void HnswInitNeighbors(HnswElement element, int m);
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ CreateElementPages(HnswBuildState * buildstate)
|
|||||||
GenericXLogFinish(state);
|
GenericXLogFinish(state);
|
||||||
UnlockReleaseBuffer(buf);
|
UnlockReleaseBuffer(buf);
|
||||||
|
|
||||||
UpdateMetaPage(index, true, buildstate->entryPoint, insertPage, forkNum);
|
HnswUpdateMetaPage(index, true, buildstate->entryPoint, insertPage, forkNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ WriteNewElementPages(Relation index, HnswElement e, int m)
|
|||||||
|
|
||||||
/* Update the insert page */
|
/* Update the insert page */
|
||||||
if (insertPage != originalInsertPage && (!OffsetNumberIsValid(freeOffno) || firstFreePage == insertPage))
|
if (insertPage != originalInsertPage && (!OffsetNumberIsValid(freeOffno) || firstFreePage == insertPage))
|
||||||
UpdateMetaPage(index, false, NULL, insertPage, MAIN_FORKNUM);
|
HnswUpdateMetaPage(index, false, NULL, insertPage, MAIN_FORKNUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -405,7 +405,7 @@ WriteElement(Relation index, HnswElement element, int m, List *updates, HnswElem
|
|||||||
|
|
||||||
/* Update metapage if needed */
|
/* Update metapage if needed */
|
||||||
if (entryPoint == NULL || element->level > entryPoint->level)
|
if (entryPoint == NULL || element->level > entryPoint->level)
|
||||||
UpdateMetaPage(index, true, element, InvalidBlockNumber, MAIN_FORKNUM);
|
HnswUpdateMetaPage(index, true, element, InvalidBlockNumber, MAIN_FORKNUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -442,7 +442,7 @@ HnswInsertTuple(Relation index, Datum *values, bool *isnull, ItemPointer heap_ti
|
|||||||
element->vec = DatumGetVector(value);
|
element->vec = DatumGetVector(value);
|
||||||
|
|
||||||
/* Get entry point */
|
/* Get entry point */
|
||||||
entryPoint = GetEntryPoint(index);
|
entryPoint = HnswGetEntryPoint(index);
|
||||||
|
|
||||||
/* Insert element in graph */
|
/* Insert element in graph */
|
||||||
dup = HnswInsertElement(element, entryPoint, index, procinfo, collation, m, efConstruction, &updates, false);
|
dup = HnswInsertElement(element, entryPoint, index, procinfo, collation, m, efConstruction, &updates, false);
|
||||||
|
|||||||
@@ -18,20 +18,20 @@ GetScanItems(IndexScanDesc scan, Datum q)
|
|||||||
Oid collation = so->collation;
|
Oid collation = so->collation;
|
||||||
List *ep = NIL;
|
List *ep = NIL;
|
||||||
List *w;
|
List *w;
|
||||||
HnswElement entryPoint = GetEntryPoint(index);
|
HnswElement entryPoint = HnswGetEntryPoint(index);
|
||||||
|
|
||||||
if (entryPoint == NULL)
|
if (entryPoint == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ep = lappend(ep, EntryCandidate(entryPoint, q, index, procinfo, collation, false));
|
ep = lappend(ep, HnswEntryCandidate(entryPoint, q, index, procinfo, collation, false));
|
||||||
|
|
||||||
for (int lc = entryPoint->level; lc >= 1; lc--)
|
for (int lc = entryPoint->level; lc >= 1; lc--)
|
||||||
{
|
{
|
||||||
w = SearchLayer(q, ep, 1, lc, index, procinfo, collation, false, NULL, NULL);
|
w = HnswSearchLayer(q, ep, 1, lc, index, procinfo, collation, false, NULL, NULL);
|
||||||
ep = w;
|
ep = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
so->w = SearchLayer(q, ep, hnsw_ef_search, 0, index, procinfo, collation, false, NULL, NULL);
|
so->w = HnswSearchLayer(q, ep, hnsw_ef_search, 0, index, procinfo, collation, false, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ CreateElementFromBlock(BlockNumber blkno, OffsetNumber offno)
|
|||||||
* Get the entry point
|
* Get the entry point
|
||||||
*/
|
*/
|
||||||
HnswElement
|
HnswElement
|
||||||
GetEntryPoint(Relation index)
|
HnswGetEntryPoint(Relation index)
|
||||||
{
|
{
|
||||||
Buffer buf;
|
Buffer buf;
|
||||||
Page page;
|
Page page;
|
||||||
@@ -668,7 +668,7 @@ AddToVisited(HTAB *v, HnswCandidate * hc, Relation index, bool *found)
|
|||||||
* Algorithm 2 from paper
|
* Algorithm 2 from paper
|
||||||
*/
|
*/
|
||||||
List *
|
List *
|
||||||
SearchLayer(Datum q, List *ep, int ef, int lc, Relation index, FmgrInfo *procinfo, Oid collation, bool inserting, BlockNumber *skipPage, OffsetNumber *skipOffno)
|
HnswSearchLayer(Datum q, List *ep, int ef, int lc, Relation index, FmgrInfo *procinfo, Oid collation, bool inserting, BlockNumber *skipPage, OffsetNumber *skipOffno)
|
||||||
{
|
{
|
||||||
ListCell *lc2;
|
ListCell *lc2;
|
||||||
|
|
||||||
@@ -791,7 +791,7 @@ SearchLayer(Datum q, List *ep, int ef, int lc, Relation index, FmgrInfo *procinf
|
|||||||
* Create a candidate for the entry point
|
* Create a candidate for the entry point
|
||||||
*/
|
*/
|
||||||
HnswCandidate *
|
HnswCandidate *
|
||||||
EntryCandidate(HnswElement entryPoint, Datum q, Relation index, FmgrInfo *procinfo, Oid collation, bool loadvec)
|
HnswEntryCandidate(HnswElement entryPoint, Datum q, Relation index, FmgrInfo *procinfo, Oid collation, bool loadvec)
|
||||||
{
|
{
|
||||||
HnswCandidate *hc = palloc(sizeof(HnswCandidate));
|
HnswCandidate *hc = palloc(sizeof(HnswCandidate));
|
||||||
|
|
||||||
@@ -848,7 +848,7 @@ HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, F
|
|||||||
/* Get entry point and level */
|
/* Get entry point and level */
|
||||||
if (entryPoint != NULL)
|
if (entryPoint != NULL)
|
||||||
{
|
{
|
||||||
entryCandidate = EntryCandidate(entryPoint, q, index, procinfo, collation, true);
|
entryCandidate = HnswEntryCandidate(entryPoint, q, index, procinfo, collation, true);
|
||||||
ep = lappend(ep, entryCandidate);
|
ep = lappend(ep, entryCandidate);
|
||||||
entryLevel = entryPoint->level;
|
entryLevel = entryPoint->level;
|
||||||
removeEntryPoint = vacuuming && list_length(entryPoint->heaptids) == 0;
|
removeEntryPoint = vacuuming && list_length(entryPoint->heaptids) == 0;
|
||||||
@@ -861,7 +861,7 @@ HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, F
|
|||||||
|
|
||||||
for (int lc = entryLevel; lc >= level + 1; lc--)
|
for (int lc = entryLevel; lc >= level + 1; lc--)
|
||||||
{
|
{
|
||||||
w = SearchLayer(q, ep, 1, lc, index, procinfo, collation, true, skipPage, skipOffno);
|
w = HnswSearchLayer(q, ep, 1, lc, index, procinfo, collation, true, skipPage, skipOffno);
|
||||||
ep = w;
|
ep = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -872,7 +872,7 @@ HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, F
|
|||||||
{
|
{
|
||||||
int lm = HnswGetLayerM(m, lc);
|
int lm = HnswGetLayerM(m, lc);
|
||||||
|
|
||||||
w = SearchLayer(q, ep, efConstruction, lc, index, procinfo, collation, true, skipPage, skipOffno);
|
w = HnswSearchLayer(q, ep, efConstruction, lc, index, procinfo, collation, true, skipPage, skipOffno);
|
||||||
if (removeEntryPoint)
|
if (removeEntryPoint)
|
||||||
w = list_delete_ptr(w, entryCandidate);
|
w = list_delete_ptr(w, entryCandidate);
|
||||||
newNeighbors[lc] = SelectNeighbors(w, lm, lc, procinfo, collation, NULL);
|
newNeighbors[lc] = SelectNeighbors(w, lm, lc, procinfo, collation, NULL);
|
||||||
@@ -904,7 +904,7 @@ HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, F
|
|||||||
* Update the metapage
|
* Update the metapage
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
UpdateMetaPage(Relation index, bool updateEntry, HnswElement entryPoint, BlockNumber insertPage, ForkNumber forkNum)
|
HnswUpdateMetaPage(Relation index, bool updateEntry, HnswElement entryPoint, BlockNumber insertPage, ForkNumber forkNum)
|
||||||
{
|
{
|
||||||
Buffer buf;
|
Buffer buf;
|
||||||
Page page;
|
Page page;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ RemoveHeapTids(HnswVacuumState * vacuumstate)
|
|||||||
HnswElement highestPoint = &vacuumstate->highestPoint;
|
HnswElement highestPoint = &vacuumstate->highestPoint;
|
||||||
Relation index = vacuumstate->index;
|
Relation index = vacuumstate->index;
|
||||||
BufferAccessStrategy bas = vacuumstate->bas;
|
BufferAccessStrategy bas = vacuumstate->bas;
|
||||||
HnswElement entryPoint = GetEntryPoint(vacuumstate->index);
|
HnswElement entryPoint = HnswGetEntryPoint(vacuumstate->index);
|
||||||
|
|
||||||
/* Store separately since highestPoint.level is uint8 */
|
/* Store separately since highestPoint.level is uint8 */
|
||||||
int highestLevel = -1;
|
int highestLevel = -1;
|
||||||
@@ -201,7 +201,7 @@ RepairGraphElement(HnswVacuumState * vacuumstate, HnswElement element)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* Refresh entry point for each element */
|
/* Refresh entry point for each element */
|
||||||
entryPoint = GetEntryPoint(index);
|
entryPoint = HnswGetEntryPoint(index);
|
||||||
|
|
||||||
/* Special case for entry point */
|
/* Special case for entry point */
|
||||||
if (element->blkno == entryPoint->blkno && element->offno == entryPoint->offno)
|
if (element->blkno == entryPoint->blkno && element->offno == entryPoint->offno)
|
||||||
@@ -261,7 +261,7 @@ RepairGraphEntryPoint(HnswVacuumState * vacuumstate)
|
|||||||
RepairGraphElement(vacuumstate, highestPoint);
|
RepairGraphElement(vacuumstate, highestPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
entryPoint = GetEntryPoint(index);
|
entryPoint = HnswGetEntryPoint(index);
|
||||||
if (entryPoint != NULL)
|
if (entryPoint != NULL)
|
||||||
{
|
{
|
||||||
ItemPointerData epData;
|
ItemPointerData epData;
|
||||||
@@ -269,7 +269,7 @@ RepairGraphEntryPoint(HnswVacuumState * vacuumstate)
|
|||||||
ItemPointerSet(&epData, entryPoint->blkno, entryPoint->offno);
|
ItemPointerSet(&epData, entryPoint->blkno, entryPoint->offno);
|
||||||
|
|
||||||
if (DeletedContains(vacuumstate->deleted, &epData))
|
if (DeletedContains(vacuumstate->deleted, &epData))
|
||||||
UpdateMetaPage(index, true, highestPoint, InvalidBlockNumber, MAIN_FORKNUM);
|
HnswUpdateMetaPage(index, true, highestPoint, InvalidBlockNumber, MAIN_FORKNUM);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Highest point will be used to repair */
|
/* Highest point will be used to repair */
|
||||||
@@ -484,7 +484,7 @@ MarkDeleted(HnswVacuumState * vacuumstate)
|
|||||||
UnlockReleaseBuffer(buf);
|
UnlockReleaseBuffer(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateMetaPage(index, false, NULL, insertPage, MAIN_FORKNUM);
|
HnswUpdateMetaPage(index, false, NULL, insertPage, MAIN_FORKNUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user