From a2a0b377f06e1122dcfb6eb40b5c0312bf604009 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Mon, 28 Oct 2024 13:46:49 -0700 Subject: [PATCH] Removed memory limit debug message from HNSW index scans (EXPLAIN ANALYZE can be used instead) --- README.md | 13 +------------ src/hnswscan.c | 19 ++----------------- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index a9aff94..4851120 100644 --- a/README.md +++ b/README.md @@ -537,18 +537,7 @@ Specify the max amount of memory to use, as a multiple of `work_mem` (1 by defau SET hnsw.scan_mem_multiplier = 2; ``` -You can see when increasing this is needed by enabling debug messages - -```sql -SET client_min_messages = debug1; -``` - -which will show when a scan reaches the memory limit - -```text -DEBUG: hnsw index scan reached memory limit after 20000 tuples -HINT: Increase hnsw.scan_mem_multiplier to scan more tuples. -``` +Note: Try increasing this if increasing `hnsw.max_scan_tuples` does not improve recall #### IVFFlat diff --git a/src/hnswscan.c b/src/hnswscan.c index f38057b..955998a 100644 --- a/src/hnswscan.c +++ b/src/hnswscan.c @@ -240,8 +240,8 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir) if (so->discarded == NULL) break; - /* Reached max number of tuples */ - if (so->tuples >= hnsw_max_scan_tuples) + /* Reached max number of tuples or memory limit */ + if (so->tuples >= hnsw_max_scan_tuples || MemoryContextMemAllocated(so->tmpCtx, false) > so->maxMemory) { if (pairingheap_is_empty(so->discarded)) break; @@ -249,21 +249,6 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir) /* Return remaining tuples */ 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) > so->maxMemory) - { - if (pairingheap_is_empty(so->discarded)) - { - ereport(DEBUG1, - (errmsg("hnsw index scan reached memory limit after " INT64_FORMAT " tuples", so->tuples), - errhint("Increase hnsw.scan_mem_multiplier to scan more tuples."))); - - break; - } - - /* Return remaining tuples */ - so->w = lappend(so->w, HnswGetSearchCandidate(w_node, pairingheap_remove_first(so->discarded))); - } else { /*