From a15806196ebae7e52c3446b1e26ee54cb0f793b9 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Thu, 19 Sep 2024 04:02:09 -0700 Subject: [PATCH] Keep scan-build happy --- src/hnswutils.c | 64 +++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/src/hnswutils.c b/src/hnswutils.c index 764e9d5..bb4a32c 100644 --- a/src/hnswutils.c +++ b/src/hnswutils.c @@ -874,6 +874,8 @@ HnswSearchLayer(char *base, Datum q, List *ep, int ef, int lc, Relation index, F for (int i = 0; i < unvisitedLength; i++) { HnswElement eElement; + HnswCandidate *e; + HnswPairingHeapNode *node; float eDistance; bool alwaysAdd = wlen < ef; @@ -883,6 +885,9 @@ HnswSearchLayer(char *base, Datum q, List *ep, int ef, int lc, Relation index, F { eElement = unvisited[i].element; eDistance = GetElementDistance(base, eElement, q, procinfo, collation); + + if (!(eDistance < f->distance || alwaysAdd)) + continue; } else { @@ -893,41 +898,38 @@ HnswSearchLayer(char *base, Datum q, List *ep, int ef, int lc, Relation index, F /* Avoid any allocations if not adding */ eElement = NULL; HnswLoadElementImpl(blkno, offno, &eDistance, &q, index, procinfo, collation, inserting, alwaysAdd ? NULL : &f->distance, &eElement); + + if (eElement == NULL) + continue; } - if (eDistance < f->distance || alwaysAdd) + Assert(!eElement->deleted); + + /* Make robust to issues */ + if (eElement->level < lc) + continue; + + /* Create a new candidate */ + e = palloc(sizeof(HnswCandidate)); + HnswPtrStore(base, e->element, eElement); + e->distance = eDistance; + + node = CreatePairingHeapNode(e); + pairingheap_add(C, &node->c_node); + pairingheap_add(W, &node->w_node); + + /* + * Do not count elements being deleted towards ef when vacuuming. + * It would be ideal to do this for inserts as well, but this + * could affect insert performance. + */ + if (CountElement(base, skipElement, eElement)) { - HnswCandidate *e; - HnswPairingHeapNode *node; + wlen++; - Assert(!eElement->deleted); - - /* Make robust to issues */ - if (eElement->level < lc) - continue; - - /* Create a new candidate */ - e = palloc(sizeof(HnswCandidate)); - HnswPtrStore(base, e->element, eElement); - e->distance = eDistance; - - node = CreatePairingHeapNode(e); - pairingheap_add(C, &node->c_node); - pairingheap_add(W, &node->w_node); - - /* - * Do not count elements being deleted towards ef when - * vacuuming. It would be ideal to do this for inserts as - * well, but this could affect insert performance. - */ - if (CountElement(base, skipElement, eElement)) - { - wlen++; - - /* No need to decrement wlen */ - if (wlen > ef) - pairingheap_remove_first(W); - } + /* No need to decrement wlen */ + if (wlen > ef) + pairingheap_remove_first(W); } } }