Added hnsw.search_mem_multiplier option

This commit is contained in:
Andrew Kane
2024-10-24 18:02:20 -07:00
parent 67eff41c44
commit ac6576e53a
4 changed files with 15 additions and 6 deletions

View File

@@ -138,6 +138,8 @@ hnswbeginscan(Relation index, int nkeys, int norderbys)
/* Set support functions */
HnswInitSupport(&so->support, index);
so->maxMemory = (Size) (work_mem * 1024.0 * hnsw_search_mem_multiplier);
scan->opaque = so;
return scan;
@@ -244,13 +246,13 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir)
so->w = lappend(so->w, HnswGetSearchCandidate(w_node, pairingheap_remove_first(so->discarded)));
}
/* Prevent scans from consuming too much memory */
else if (MemoryContextMemAllocated(so->tmpCtx, false) > (Size) work_mem * 1024L)
else if (MemoryContextMemAllocated(so->tmpCtx, false) >= so->maxMemory)
{
if (pairingheap_is_empty(so->discarded))
{
ereport(DEBUG1,
(errmsg("hnsw index scan exceeded work_mem after " INT64_FORMAT " tuples", so->tuples),
errhint("Increase work_mem to scan more tuples.")));
(errmsg("hnsw index scan reached memory limit after " INT64_FORMAT " tuples", so->tuples),
errhint("Increase hnsw.search_mem_multiplier to scan more tuples.")));
break;
}