Skip to content

Prefetch since v0.4.0

Prefetch dramatically accelerates large dataset operations by loading data from disk into memory cache before it's needed. It minimizes disk I/O latency during queries, transforming slow disk access into lightning-fast memory operations for optimal query performance.

PostgreSQL 17 has introduced a new streaming I/O API for more efficient sequential I/O. Take advantage of it, a sequential scan on a table will be much faster.

Prefetch Mode

TIP

This feature is enabled by default. Any query can be benefit from prefetching with VectorChord v0.4.0 and later versions.

In VectorChord, we implemented two prefetch methods: A simple one, prefetch_buffer, and read_stream, which uses the streaming I/O API. Both methods are much faster than the previous behavior, read_buffer.

They can be set by vchordrq.io_rerank and vchordrq.io_search:

Prefetch ModeDescriptionSupported on PG Version
read_streamAdvanced streaming prefetch by streaming I/O APIPostgreSQL 17+ only
prefetch_bufferSimple prefetching using PostgreSQL's buffer prefetch mechanismAny
read_bufferBasic buffer reading without prefetchingAny

If you are using PostgreSQL 16 or an earlier version, the prefetch_buffer can also help you.

Furthermore, the Asynchronous I/O which will in PostgreSQL 18 will make read_stream more advantageous.


Based on our experimental results, the first query latency can be reduced by 2-3 times with prefetch:

Prefetch modes

See also: Indexing Prewarm