Improved variable names [skip ci]

This commit is contained in:
Andrew Kane
2023-08-01 20:15:03 -07:00
parent 3169a60e5c
commit 5802009c86
3 changed files with 52 additions and 52 deletions

View File

@@ -41,17 +41,17 @@ HnswFreeOffset(Relation index, Buffer buf, Page page, HnswElement element, Size
for (offno = FirstOffsetNumber; offno <= maxoffno; offno = OffsetNumberNext(offno)) for (offno = FirstOffsetNumber; offno <= maxoffno; offno = OffsetNumberNext(offno))
{ {
HnswElementTuple item = (HnswElementTuple) PageGetItem(page, PageGetItemId(page, offno)); HnswElementTuple etup = (HnswElementTuple) PageGetItem(page, PageGetItemId(page, offno));
/* Skip neighbor tuples */ /* Skip neighbor tuples */
if (!HnswIsElementTuple(item)) if (!HnswIsElementTuple(etup))
continue; continue;
/* TODO Remove level check */ /* TODO Remove level check */
if (item->deleted && item->level == element->level) if (etup->deleted && etup->level == element->level)
{ {
BlockNumber neighborPage = ItemPointerGetBlockNumber(&item->neighbortid); BlockNumber neighborPage = ItemPointerGetBlockNumber(&etup->neighbortid);
OffsetNumber neighborOffno = ItemPointerGetOffsetNumber(&item->neighbortid); OffsetNumber neighborOffno = ItemPointerGetOffsetNumber(&etup->neighbortid);
ItemId itemid; ItemId itemid;
if (neighborPage == BufferGetBlockNumber(buf)) if (neighborPage == BufferGetBlockNumber(buf))

View File

@@ -420,41 +420,41 @@ HnswLoadElement(HnswElement element, float *distance, Datum *q, Relation index,
{ {
Buffer buf; Buffer buf;
Page page; Page page;
HnswElementTuple item; HnswElementTuple etup;
/* Read vector */ /* Read vector */
buf = ReadBuffer(index, element->blkno); buf = ReadBuffer(index, element->blkno);
LockBuffer(buf, BUFFER_LOCK_SHARE); LockBuffer(buf, BUFFER_LOCK_SHARE);
page = BufferGetPage(buf); page = BufferGetPage(buf);
item = (HnswElementTuple) PageGetItem(page, PageGetItemId(page, element->offno)); etup = (HnswElementTuple) PageGetItem(page, PageGetItemId(page, element->offno));
Assert(HnswIsElementTuple(item)); Assert(HnswIsElementTuple(etup));
/* Load element */ /* Load element */
element->heaptids = NIL; element->heaptids = NIL;
for (int i = 0; i < HNSW_HEAPTIDS; i++) for (int i = 0; i < HNSW_HEAPTIDS; i++)
{ {
/* Can stop at first invalid */ /* Can stop at first invalid */
if (!ItemPointerIsValid(&item->heaptids[i])) if (!ItemPointerIsValid(&etup->heaptids[i]))
break; break;
HnswAddHeapTid(element, &item->heaptids[i]); HnswAddHeapTid(element, &etup->heaptids[i]);
} }
element->level = item->level; element->level = etup->level;
element->neighborPage = ItemPointerGetBlockNumber(&item->neighbortid); element->neighborPage = ItemPointerGetBlockNumber(&etup->neighbortid);
element->neighborOffno = ItemPointerGetOffsetNumber(&item->neighbortid); element->neighborOffno = ItemPointerGetOffsetNumber(&etup->neighbortid);
element->deleted = item->deleted; element->deleted = etup->deleted;
if (loadvec) if (loadvec)
{ {
element->vec = palloc(VECTOR_SIZE(item->vec.dim)); element->vec = palloc(VECTOR_SIZE(etup->vec.dim));
memcpy(element->vec, &item->vec, VECTOR_SIZE(item->vec.dim)); memcpy(element->vec, &etup->vec, VECTOR_SIZE(etup->vec.dim));
} }
/* Calculate distance */ /* Calculate distance */
if (distance != NULL) if (distance != NULL)
*distance = (float) DatumGetFloat8(FunctionCall2Coll(procinfo, collation, *q, PointerGetDatum(&item->vec))); *distance = (float) DatumGetFloat8(FunctionCall2Coll(procinfo, collation, *q, PointerGetDatum(&etup->vec)));
/* Load neighbors if on same page */ /* Load neighbors if on same page */
if (element->neighborPage == element->blkno) if (element->neighborPage == element->blkno)

View File

@@ -60,47 +60,47 @@ RemoveHeapTids(HnswVacuumState * vacuumstate)
/* Iterate over nodes */ /* Iterate over nodes */
for (offno = FirstOffsetNumber; offno <= maxoffno; offno = OffsetNumberNext(offno)) for (offno = FirstOffsetNumber; offno <= maxoffno; offno = OffsetNumberNext(offno))
{ {
HnswElementTuple item = (HnswElementTuple) PageGetItem(page, PageGetItemId(page, offno)); HnswElementTuple etup = (HnswElementTuple) PageGetItem(page, PageGetItemId(page, offno));
int idx = 0; int idx = 0;
bool itemUpdated = false; bool itemUpdated = false;
/* Skip neighbor tuples */ /* Skip neighbor tuples */
if (!HnswIsElementTuple(item)) if (!HnswIsElementTuple(etup))
continue; continue;
if (ItemPointerIsValid(&item->heaptids[0])) if (ItemPointerIsValid(&etup->heaptids[0]))
{ {
for (int i = 0; i < HNSW_HEAPTIDS; i++) for (int i = 0; i < HNSW_HEAPTIDS; i++)
{ {
/* Stop at first unused */ /* Stop at first unused */
if (!ItemPointerIsValid(&item->heaptids[i])) if (!ItemPointerIsValid(&etup->heaptids[i]))
break; break;
if (vacuumstate->callback(&item->heaptids[i], vacuumstate->callback_state)) if (vacuumstate->callback(&etup->heaptids[i], vacuumstate->callback_state))
itemUpdated = true; itemUpdated = true;
else else
{ {
/* Move to front of list */ /* Move to front of list */
item->heaptids[idx++] = item->heaptids[i]; etup->heaptids[idx++] = etup->heaptids[i];
} }
} }
if (itemUpdated) if (itemUpdated)
{ {
Size itemsz = HNSW_ELEMENT_TUPLE_SIZE(item->vec.dim); Size etupSize = HNSW_ELEMENT_TUPLE_SIZE(etup->vec.dim);
/* Mark rest as invalid */ /* Mark rest as invalid */
for (int i = idx; i < HNSW_HEAPTIDS; i++) for (int i = idx; i < HNSW_HEAPTIDS; i++)
ItemPointerSetInvalid(&item->heaptids[i]); ItemPointerSetInvalid(&etup->heaptids[i]);
if (!PageIndexTupleOverwrite(page, offno, (Item) item, itemsz)) if (!PageIndexTupleOverwrite(page, offno, (Item) etup, etupSize))
elog(ERROR, "failed to add index item to \"%s\"", RelationGetRelationName(index)); elog(ERROR, "failed to add index item to \"%s\"", RelationGetRelationName(index));
updated = true; updated = true;
} }
} }
if (!ItemPointerIsValid(&item->heaptids[0])) if (!ItemPointerIsValid(&etup->heaptids[0]))
{ {
ItemPointerData ip; ItemPointerData ip;
@@ -109,13 +109,13 @@ RemoveHeapTids(HnswVacuumState * vacuumstate)
(void) hash_search(vacuumstate->deleted, &ip, HASH_ENTER, NULL); (void) hash_search(vacuumstate->deleted, &ip, HASH_ENTER, NULL);
} }
else if (item->level > highestLevel && !(highestPoint->blkno == entryPoint->blkno && highestPoint->offno == entryPoint->offno)) else if (etup->level > highestLevel && !(highestPoint->blkno == entryPoint->blkno && highestPoint->offno == entryPoint->offno))
{ {
/* Keep track of highest non-entry point */ /* Keep track of highest non-entry point */
/* TODO Keep track of closest one to entry point? */ /* TODO Keep track of closest one to entry point? */
highestPoint->blkno = blkno; highestPoint->blkno = blkno;
highestPoint->offno = offno; highestPoint->offno = offno;
highestLevel = item->level; highestLevel = etup->level;
} }
} }
@@ -317,26 +317,26 @@ RepairGraph(HnswVacuumState * vacuumstate)
/* Load items into memory to minimize locking */ /* Load items into memory to minimize locking */
for (offno = FirstOffsetNumber; offno <= maxoffno; offno = OffsetNumberNext(offno)) for (offno = FirstOffsetNumber; offno <= maxoffno; offno = OffsetNumberNext(offno))
{ {
HnswElementTuple item = (HnswElementTuple) PageGetItem(page, PageGetItemId(page, offno)); HnswElementTuple etup = (HnswElementTuple) PageGetItem(page, PageGetItemId(page, offno));
HnswElement element; HnswElement element;
/* Skip neighbor tuples */ /* Skip neighbor tuples */
if (!HnswIsElementTuple(item)) if (!HnswIsElementTuple(etup))
continue; continue;
/* Skip updating neighbors if being deleted */ /* Skip updating neighbors if being deleted */
if (!ItemPointerIsValid(&item->heaptids[0])) if (!ItemPointerIsValid(&etup->heaptids[0]))
continue; continue;
/* Create an element */ /* Create an element */
element = palloc(sizeof(HnswElementData)); element = palloc(sizeof(HnswElementData));
element->neighborPage = ItemPointerGetBlockNumber(&item->neighbortid); element->neighborPage = ItemPointerGetBlockNumber(&etup->neighbortid);
element->neighborOffno = ItemPointerGetOffsetNumber(&item->neighbortid); element->neighborOffno = ItemPointerGetOffsetNumber(&etup->neighbortid);
element->level = item->level; element->level = etup->level;
element->blkno = blkno; element->blkno = blkno;
element->offno = offno; element->offno = offno;
element->vec = palloc(VECTOR_SIZE(item->vec.dim)); element->vec = palloc(VECTOR_SIZE(etup->vec.dim));
memcpy(element->vec, &item->vec, VECTOR_SIZE(item->vec.dim)); memcpy(element->vec, &etup->vec, VECTOR_SIZE(etup->vec.dim));
elements = lappend(elements, element); elements = lappend(elements, element);
} }
@@ -393,32 +393,32 @@ MarkDeleted(HnswVacuumState * vacuumstate)
/* Update element and neighbors together */ /* Update element and neighbors together */
for (offno = FirstOffsetNumber; offno <= maxoffno; offno = OffsetNumberNext(offno)) for (offno = FirstOffsetNumber; offno <= maxoffno; offno = OffsetNumberNext(offno))
{ {
HnswElementTuple item = (HnswElementTuple) PageGetItem(page, PageGetItemId(page, offno)); HnswElementTuple etup = (HnswElementTuple) PageGetItem(page, PageGetItemId(page, offno));
Size itemsz; HnswNeighborTuple ntup;
Size etupSize;
Size ntupSize;
Buffer nbuf; Buffer nbuf;
Page npage; Page npage;
BlockNumber neighborPage; BlockNumber neighborPage;
OffsetNumber neighborOffno; OffsetNumber neighborOffno;
Size ntupsz;
HnswNeighborTuple ntup;
int neighborCount; int neighborCount;
/* Skip neighbor tuples */ /* Skip neighbor tuples */
if (!HnswIsElementTuple(item)) if (!HnswIsElementTuple(etup))
continue; continue;
if (ItemPointerIsValid(&item->heaptids[0])) if (ItemPointerIsValid(&etup->heaptids[0]))
continue; continue;
/* Calculate sizes */ /* Calculate sizes */
itemsz = HNSW_ELEMENT_TUPLE_SIZE(item->vec.dim); etupSize = HNSW_ELEMENT_TUPLE_SIZE(etup->vec.dim);
ntupsz = HNSW_NEIGHBOR_TUPLE_SIZE(item->level, vacuumstate->m); ntupSize = HNSW_NEIGHBOR_TUPLE_SIZE(etup->level, vacuumstate->m);
neighborCount = (item->level + 2) * vacuumstate->m; neighborCount = (etup->level + 2) * vacuumstate->m;
/* Get neighbor page */ /* Get neighbor page */
neighborPage = ItemPointerGetBlockNumber(&item->neighbortid); neighborPage = ItemPointerGetBlockNumber(&etup->neighbortid);
neighborOffno = ItemPointerGetOffsetNumber(&item->neighbortid); neighborOffno = ItemPointerGetOffsetNumber(&etup->neighbortid);
if (neighborPage == blkno) if (neighborPage == blkno)
{ {
@@ -436,8 +436,8 @@ MarkDeleted(HnswVacuumState * vacuumstate)
/* Overwrite element */ /* Overwrite element */
/* TODO Increment version? */ /* TODO Increment version? */
item->deleted = 1; etup->deleted = 1;
MemSet(&item->vec.x, 0, item->vec.dim * sizeof(float)); MemSet(&etup->vec.x, 0, etup->vec.dim * sizeof(float));
/* Overwrite neighbors */ /* Overwrite neighbors */
for (int i = 0; i < neighborCount; i++) for (int i = 0; i < neighborCount; i++)
@@ -446,10 +446,10 @@ MarkDeleted(HnswVacuumState * vacuumstate)
ntup->neighbors[i].distance = NAN; ntup->neighbors[i].distance = NAN;
} }
if (!PageIndexTupleOverwrite(page, offno, (Item) item, itemsz)) if (!PageIndexTupleOverwrite(page, offno, (Item) etup, etupSize))
elog(ERROR, "failed to add index item to \"%s\"", RelationGetRelationName(index)); elog(ERROR, "failed to add index item to \"%s\"", RelationGetRelationName(index));
if (!PageIndexTupleOverwrite(npage, neighborOffno, (Item) ntup, ntupsz)) if (!PageIndexTupleOverwrite(npage, neighborOffno, (Item) ntup, ntupSize))
elog(ERROR, "failed to add index item to \"%s\"", RelationGetRelationName(index)); elog(ERROR, "failed to add index item to \"%s\"", RelationGetRelationName(index));
/* Commit */ /* Commit */