diff --git a/src/ivfscan.c b/src/ivfscan.c index 09b2baa..b557fea 100644 --- a/src/ivfscan.c +++ b/src/ivfscan.c @@ -1,5 +1,7 @@ #include "postgres.h" +#include + #include "access/relscan.h" #include "ivfflat.h" #include "miscadmin.h" @@ -46,7 +48,7 @@ GetScanLists(IndexScanDesc scan, Datum value) IvfflatScanOpaque so = (IvfflatScanOpaque) scan->opaque; double distance; IvfflatScanList *scanlist; - double maxDistance; + double maxDistance = DBL_MAX; /* Search all list pages */ while (BlockNumberIsValid(nextblkno)) @@ -194,6 +196,9 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys) scan = RelationGetIndexScan(index, nkeys, norderbys); lists = IvfflatGetLists(scan->indexRelation); + if (probes > lists) + probes = lists; + so = (IvfflatScanOpaque) palloc(offsetof(IvfflatScanOpaqueData, lists) + probes * sizeof(IvfflatScanList)); so->buf = InvalidBuffer; so->first = true;