Added asynchronous I/O for IVFFlat indexes for Postgres 17 [skip ci]

This commit is contained in:
Andrew Kane committed 2026-11-10 23:34:57 -08:00
1 parent bcbb135db5
commit e962accee8
2 files changed
+22 -5

No files matched your search

+3 -2
View File
@@ -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 */
+19 -3
View File
@@ -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);