diff --git a/src/ivfflat.h b/src/ivfflat.h index 4f7aa9ab..ab3ac992 100644 --- a/src/ivfflat.h +++ b/src/ivfflat.h @@ -15,7 +15,7 @@ #include "utils/tuplesort.h" #include "vector.h" -#if PG_VERSION_NUM >= 180000 +#if PG_VERSION_NUM >= 170000 #define IVFFLAT_USE_READ_STREAM #endif @@ -293,7 +293,8 @@ typedef struct IvfflatScanOpaqueData /* Stream */ #ifdef IVFFLAT_USE_READ_STREAM ReadStream *stream; - BlockRangeReadStreamPrivate streamData; + BlockNumber searchPage; + BlockNumber lastContiguousPage; #endif /* Sorting */ diff --git a/src/ivfscan.c b/src/ivfscan.c index 5a9ea82a..4894d817 100644 --- a/src/ivfscan.c +++ b/src/ivfscan.c @@ -195,8 +195,8 @@ GetScanItems(IndexScanDesc scan, Datum value) #ifdef IVFFLAT_USE_READ_STREAM searchPage = InvalidBlockNumber; - so->streamData.current_blocknum = scanlist->startPage; - so->streamData.last_exclusive = scanlist->lastContiguousPage + 1; + so->searchPage = scanlist->startPage; + so->lastContiguousPage = scanlist->lastContiguousPage; read_stream_reset(so->stream); /* Search contiguous entry pages for list */ @@ -311,6 +311,22 @@ InitScanSortState(TupleDesc tupdesc) return tuplesort_begin_heap(tupdesc, 1, attNums, sortOperators, sortCollations, nullsFirstFlags, work_mem, NULL, false); } +#ifdef IVFFLAT_USE_READ_STREAM +/* + * Get next block number for read stream + */ +static BlockNumber +IvfflatReadStreamNextBlock(ReadStream *stream, void *callback_private_data, void *per_buffer_data) +{ + IvfflatScanOpaque so = (IvfflatScanOpaque) callback_private_data; + + if (so->searchPage > so->lastContiguousPage) + return InvalidBlockNumber; + + return so->searchPage++; +} +#endif + /* * Prepare for an index scan */ @@ -380,7 +396,7 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys) 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, block_range_read_stream_cb, &so->streamData, 0); + so->stream = read_stream_begin_relation(READ_STREAM_DEFAULT, NULL, index, MAIN_FORKNUM, IvfflatReadStreamNextBlock, so, 0); #endif MemoryContextSwitchTo(oldCtx);