Improved code [skip ci]

This commit is contained in:
Andrew Kane
2024-09-22 10:24:36 -07:00
parent 08420b6404
commit d7152448f9

View File

@@ -55,11 +55,13 @@ ResumeScanItems(IndexScanDesc scan)
Oid collation = so->collation; Oid collation = so->collation;
List *ep = NIL; List *ep = NIL;
char *base = NULL; char *base = NULL;
int batch_size = hnsw_ef_search;
if (pairingheap_is_empty(so->discarded)) if (pairingheap_is_empty(so->discarded))
return NIL; return NIL;
for (int i = 0; i < hnsw_ef_search; i++) /* Get next batch of candidates */
for (int i = 0; i < batch_size; i++)
{ {
HnswSearchCandidate *hc; HnswSearchCandidate *hc;
@@ -71,7 +73,7 @@ ResumeScanItems(IndexScanDesc scan)
ep = lappend(ep, hc); ep = lappend(ep, hc);
} }
return HnswSearchLayer(base, so->q, ep, hnsw_ef_search, 0, index, procinfo, collation, so->m, false, NULL, &so->v, &so->discarded, false); return HnswSearchLayer(base, so->q, ep, batch_size, 0, index, procinfo, collation, so->m, false, NULL, &so->v, &so->discarded, false);
} }
/* /*
@@ -217,6 +219,7 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir)
if (!hnsw_streaming) if (!hnsw_streaming)
break; break;
/* Prevent scans from consuming too much memory */
if (MemoryContextMemAllocated(so->tmpCtx, false) > (Size) work_mem * 1024L) if (MemoryContextMemAllocated(so->tmpCtx, false) > (Size) work_mem * 1024L)
{ {
if (pairingheap_is_empty(so->discarded)) if (pairingheap_is_empty(so->discarded))