diff --git a/src/ivfflat.h b/src/ivfflat.h index d583c3bc..9499e801 100644 --- a/src/ivfflat.h +++ b/src/ivfflat.h @@ -293,6 +293,12 @@ typedef struct IvfflatScanOpaqueData Datum value; MemoryContext tmpCtx; + /* Support functions */ + FmgrInfo *procinfo; + FmgrInfo *normprocinfo; + Oid collation; + Datum (*distfunc) (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2); + /* Stream */ #ifdef IVFFLAT_USE_READ_STREAM ReadStream *stream; @@ -300,22 +306,16 @@ typedef struct IvfflatScanOpaqueData BlockNumber lastContiguousPage; #endif - /* Sorting */ + /* Lists */ + IvfflatScanList *lists; + int listsVisited; + pairingheap *listsHeap; + + /* Items */ Tuplesortstate *sortstate; TupleDesc tupdesc; TupleTableSlot *vslot; TupleTableSlot *mslot; - - /* Support functions */ - FmgrInfo *procinfo; - FmgrInfo *normprocinfo; - Oid collation; - Datum (*distfunc) (FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2); - - /* Lists */ - pairingheap *listsHeap; - int listsVisited; - IvfflatScanList *lists; } IvfflatScanOpaqueData; typedef IvfflatScanOpaqueData * IvfflatScanOpaque; diff --git a/src/ivfscan.c b/src/ivfscan.c index e1b13c84..0b2de98b 100644 --- a/src/ivfscan.c +++ b/src/ivfscan.c @@ -386,6 +386,10 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys) oldCtx = MemoryContextSwitchTo(so->tmpCtx); + so->lists = palloc_array_checked(IvfflatScanList, maxProbes); + so->listsVisited = 0; + so->listsHeap = pairingheap_allocate(CompareLists, scan); + /* Create tuple description for sorting */ so->tupdesc = CreateTemplateTupleDesc(2); TupleDescInitEntry(so->tupdesc, (AttrNumber) 1, "distance", FLOAT8OID, -1, 0); @@ -401,10 +405,6 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys) so->vslot = MakeSingleTupleTableSlot(so->tupdesc, &TTSOpsVirtual); so->mslot = MakeSingleTupleTableSlot(so->tupdesc, &TTSOpsMinimalTuple); - so->listsHeap = pairingheap_allocate(CompareLists, scan); - so->listsVisited = 0; - so->lists = palloc_array_checked(IvfflatScanList, maxProbes); - #ifdef IVFFLAT_USE_READ_STREAM so->stream = read_stream_begin_relation(READ_STREAM_DEFAULT, NULL, index, MAIN_FORKNUM, IvfflatReadStreamNextBlock, so, 0); #endif