mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-22 12:07:34 +08:00
Compare commits
2 Commits
hnsw-build
...
fanalyzer
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba16f5e7cf | ||
|
|
4a1a91abf9 |
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@@ -39,6 +39,10 @@ jobs:
|
||||
sudo apt-get update
|
||||
sudo apt-get install libipc-run-perl
|
||||
- run: make prove_installcheck
|
||||
- if: ${{ matrix.os == 'ubuntu-22.04' }}
|
||||
run: make clean && make
|
||||
env:
|
||||
PG_CFLAGS: -Werror -fanalyzer
|
||||
mac:
|
||||
runs-on: macos-latest
|
||||
if: ${{ !startsWith(github.ref_name, 'windows') }}
|
||||
|
||||
@@ -116,7 +116,6 @@ typedef struct HnswNeighborArray
|
||||
{
|
||||
int length;
|
||||
HnswCandidate *items;
|
||||
HnswElement firstPruned;
|
||||
} HnswNeighborArray;
|
||||
|
||||
typedef struct HnswPairingHeapNode
|
||||
|
||||
@@ -139,7 +139,6 @@ HnswInitNeighbors(HnswElement element, int m)
|
||||
a = &element->neighbors[lc];
|
||||
a->length = 0;
|
||||
a->items = palloc(sizeof(HnswCandidate) * lm);
|
||||
a->firstPruned = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -749,12 +748,11 @@ CheckElementCloser(HnswCandidate * e, List *r, int lc, FmgrInfo *procinfo, Oid c
|
||||
* Algorithm 4 from paper
|
||||
*/
|
||||
static List *
|
||||
SelectNeighbors(List *c, int m, int lc, FmgrInfo *procinfo, Oid collation, HnswElement e2, HnswCandidate * newCandidate, HnswCandidate * *pruned)
|
||||
SelectNeighbors(List *c, int m, int lc, FmgrInfo *procinfo, Oid collation, HnswCandidate * *pruned)
|
||||
{
|
||||
List *r = NIL;
|
||||
List *w = list_copy(c);
|
||||
pairingheap *wd;
|
||||
bool mustCalculate = e2->neighbors[lc].firstPruned == NULL;
|
||||
|
||||
if (list_length(w) <= m)
|
||||
return w;
|
||||
@@ -769,30 +767,7 @@ SelectNeighbors(List *c, int m, int lc, FmgrInfo *procinfo, Oid collation, HnswE
|
||||
|
||||
w = list_delete_last(w);
|
||||
|
||||
/*
|
||||
* r and wd will be the same as previous calls until the new
|
||||
* candidate, so can skip distance calculations for as many candidates
|
||||
* as there is state for
|
||||
*/
|
||||
if (mustCalculate)
|
||||
closer = CheckElementCloser(e, r, lc, procinfo, collation);
|
||||
else if (e->element == e2->neighbors[lc].firstPruned)
|
||||
{
|
||||
closer = false;
|
||||
|
||||
/*
|
||||
* Could store multiple pruned and only calculate when exhausted
|
||||
* (or store full state) at the expense of memory
|
||||
*/
|
||||
mustCalculate = true;
|
||||
}
|
||||
else if (e == newCandidate)
|
||||
{
|
||||
closer = CheckElementCloser(e, r, lc, procinfo, collation);
|
||||
mustCalculate = true;
|
||||
}
|
||||
else
|
||||
closer = true;
|
||||
closer = CheckElementCloser(e, r, lc, procinfo, collation);
|
||||
|
||||
if (closer)
|
||||
r = lappend(r, e);
|
||||
@@ -800,11 +775,6 @@ SelectNeighbors(List *c, int m, int lc, FmgrInfo *procinfo, Oid collation, HnswE
|
||||
pairingheap_add(wd, &(CreatePairingHeapNode(e)->ph_node));
|
||||
}
|
||||
|
||||
/* Save first pruned */
|
||||
/* OK to leave previous element if empty */
|
||||
if (!pairingheap_is_empty(wd))
|
||||
e2->neighbors[lc].firstPruned = ((HnswPairingHeapNode *) pairingheap_first(wd))->inner->element;
|
||||
|
||||
/* Keep pruned connections */
|
||||
while (!pairingheap_is_empty(wd) && list_length(r) < m)
|
||||
r = lappend(r, ((HnswPairingHeapNode *) pairingheap_remove_first(wd))->inner);
|
||||
@@ -939,7 +909,7 @@ HnswUpdateConnection(HnswElement element, HnswCandidate * hc, int m, int lc, int
|
||||
c = lappend(c, &hc2);
|
||||
list_sort(c, CompareCandidateDistances);
|
||||
|
||||
SelectNeighbors(c, m, lc, procinfo, collation, hc->element, &hc2, &pruned);
|
||||
SelectNeighbors(c, m, lc, procinfo, collation, &pruned);
|
||||
|
||||
/* Should not happen */
|
||||
if (pruned == NULL)
|
||||
@@ -1038,7 +1008,7 @@ HnswInsertElement(HnswElement element, HnswElement entryPoint, Relation index, F
|
||||
else
|
||||
lw = w;
|
||||
|
||||
neighbors = SelectNeighbors(lw, lm, lc, procinfo, collation, element, NULL, NULL);
|
||||
neighbors = SelectNeighbors(lw, lm, lc, procinfo, collation, NULL);
|
||||
|
||||
AddConnections(element, neighbors, lm, lc);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user