Ensure max memory fits into Size for HNSW index scans

This commit is contained in:
Andrew Kane
2024-10-27 14:21:15 -07:00
parent 857d716d9e
commit 00492d7e57

View File

@@ -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;