8000 Moved LoadElementsForInsert to separate function and removed unused c… · postgrespro/pgvector@648dd8a · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 648dd8a

Browse files
committed
Moved LoadElementsForInsert to separate function and removed unused code path
1 parent ee43ee9 commit 648dd8a

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

src/hnswutils.c

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,32 @@ AddConnections(char *base, HnswElement element, List *neighbors, int lc)
10741074
a->items[a->length++] = *((HnswCandidate *) lfirst(lc2));
10751075
}
10761076

1077+
/*
1078+
* Load elements for insert
1079+
*/
1080+
static void
1081+
LoadElementsForInsert(HnswNeighborArray * neighbors, Datum q, HnswCandidate * *pruned, Relation index, FmgrInfo *procinfo, Oid collation)
1082+
{
1083+
char *base = NULL;
1084+
1085+
for (int i = 0; i < neighbors->length; i++)
1086+
{
1087+
HnswCandidate *hc = &neighbors->items[i];
1088+
HnswElement element = HnswPtrAccess(base, hc->element);
1089+
double distance;
1090+
1091+
HnswLoadElement(element, &distance, &q, index, procinfo, collation, true, NULL);
1092+
hc->distance = distance;
1093+
1094+
/* Prune element if being deleted */
1095+
if (element->heaptidsLength == 0)
1096+
{
1097+
*pruned = &neighbors->items[i];
1098+
break;
1099+
}
1100+
}
1101+
}
1102+
10771103
/*
10781104
* Update connections
10791105
*/
@@ -1101,32 +1127,7 @@ HnswUpdateConnection(char *base, HnswElement element, HnswCandidate * hc, HnswNe
11011127

11021128
/* Load elements on insert */
11031129
if (index != NULL)
1104-
{
1105-
Datum q = HnswGetValue(base, hce);
1106-
1107-
for (int i = 0; i < currentNeighbors->length; i++)
1108-
{
1109-
HnswCandidate *hc3 = &currentNeighbors->items[i];
1110-
HnswElement hc3Element = HnswPtrAccess(base, hc3->element);
1111-
1112-
if (HnswPtrIsNull(base, hc3Element->value))
1113-
{
1114-
double distance;
1115-
1116-
HnswLoadElement(hc3Element, &distance, &q, index, procinfo, collation, true, NULL);
1117-
hc3->distance = distance;
1118-
}
1119-
else
1120-
hc3->distance = GetElementDistance(base, hc3Element, q, procinfo, collation);
1121-
1122-
/* Prune element if being deleted */
1123-
if (hc3Element->heaptidsLength == 0)
1124-
{
1125-
pruned = &currentNeighbors->items[i];
1126-
break;
1127-
}
1128-
}
1129-
}
1130+
LoadElementsForInsert(currentNeighbors, HnswGetValue(base, hce), &pruned, index, procinfo, collation);
11301131

11311132
if (pruned == NULL)
11321133
{

0 commit comments

Comments
 (0)
0