From 00492d7e570e004d27968169b3e7e3dbe482e42e Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sun, 27 Oct 2024 14:21:15 -0700 Subject: [PATCH] Ensure max memory fits into Size for HNSW index scans --- src/hnswscan.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/hnswscan.c b/src/hnswscan.c index 0994d2b..445b7ae 100644 --- a/src/hnswscan.c +++ b/src/hnswscan.c @@ -121,6 +121,7 @@ hnswbeginscan(Relation index, int nkeys, int norderbys) { IndexScanDesc scan; HnswScanOpaque so; + double maxMemory; scan = RelationGetIndexScan(index, nkeys, norderbys); @@ -138,7 +139,9 @@ hnswbeginscan(Relation index, int nkeys, int norderbys) /* Set support functions */ HnswInitSupport(&so->support, index); - so->maxMemory = (Size) (work_mem * 1024.0 * hnsw_scan_mem_multiplier); + /* Calculate max memory */ + maxMemory = (double) work_mem * hnsw_scan_mem_multiplier * 1024.0; + so->maxMemory = Min(maxMemory, (double) SIZE_MAX); scan->opaque = so;