PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
read_stream.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * read_stream.h
4 * Mechanism for accessing buffered relation data with look-ahead
5 *
6 *
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/include/storage/read_stream.h
11 *
12 *-------------------------------------------------------------------------
13 */
14#ifndef READ_STREAM_H
15#define READ_STREAM_H
16
17#include "storage/bufmgr.h"
18#include "storage/smgr.h"
19
20/* Default tuning, reasonable for many users. */
21#define READ_STREAM_DEFAULT 0x00
22
23/*
24 * I/O streams that are performing maintenance work on behalf of potentially
25 * many users, and thus should be governed by maintenance_io_concurrency
26 * instead of effective_io_concurrency. For example, VACUUM or CREATE INDEX.
27 */
28#define READ_STREAM_MAINTENANCE 0x01
29
30/*
31 * We usually avoid issuing prefetch advice automatically when sequential
32 * access is detected, but this flag explicitly disables it, for cases that
33 * might not be correctly detected. Explicit advice is known to perform worse
34 * than letting the kernel (at least Linux) detect sequential access.
35 */
36#define READ_STREAM_SEQUENTIAL 0x02
37
38/*
39 * We usually ramp up from smaller reads to larger ones, to support users who
40 * don't know if it's worth reading lots of buffers yet. This flag disables
41 * that, declaring ahead of time that we'll be reading all available buffers.
42 */
43#define READ_STREAM_FULL 0x04
44
45/* ---
46 * Opt-in to using AIO batchmode.
47 *
48 * Submitting IO in larger batches can be more efficient than doing so
49 * one-by-one, particularly for many small reads. It does, however, require
50 * the ReadStreamBlockNumberCB callback to abide by the restrictions of AIO
51 * batching (c.f. pgaio_enter_batchmode()). Basically, the callback may not:
52 *
53 * a) block without first calling pgaio_submit_staged(), unless a
54 * to-be-waited-on lock cannot be part of a deadlock, e.g. because it is
55 * never held while waiting for IO.
56 *
57 * b) start another batch (without first exiting batchmode and re-entering
58 * before returning)
59 *
60 * As this requires care and is nontrivial in some cases, batching is only
61 * used with explicit opt-in.
62 * ---
63 */
64#define READ_STREAM_USE_BATCHING 0x08
65
66struct ReadStream;
67typedef struct ReadStream ReadStream;
68
69/* for block_range_read_stream_cb */
71{
75
76/* Callback that returns the next block number to read. */
78 void *callback_private_data,
79 void *per_buffer_data);
80
82 void *callback_private_data,
83 void *per_buffer_data);
85 BufferAccessStrategy strategy,
86 Relation rel,
87 ForkNumber forknum,
89 void *callback_private_data,
90 size_t per_buffer_data_size);
91extern Buffer read_stream_next_buffer(ReadStream *stream, void **per_buffer_data);
93 BufferAccessStrategy *strategy);
95 BufferAccessStrategy strategy,
96 SMgrRelation smgr,
97 char smgr_persistence,
98 ForkNumber forknum,
100 void *callback_private_data,
101 size_t per_buffer_data_size);
102extern void read_stream_reset(ReadStream *stream);
103extern void read_stream_end(ReadStream *stream);
104
105#endif /* READ_STREAM_H */
uint32 BlockNumber
Definition: block.h:31
int Buffer
Definition: buf.h:23
ReadStream * read_stream_begin_smgr_relation(int flags, BufferAccessStrategy strategy, SMgrRelation smgr, char smgr_persistence, ForkNumber forknum, ReadStreamBlockNumberCB callback, void *callback_private_data, size_t per_buffer_data_size)
Definition: read_stream.c:740
BlockNumber read_stream_next_block(ReadStream *stream, BufferAccessStrategy *strategy)
Definition: read_stream.c:997
void read_stream_reset(ReadStream *stream)
Definition: read_stream.c:1010
Buffer read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)
Definition: read_stream.c:770
ReadStream * read_stream_begin_relation(int flags, BufferAccessStrategy strategy, Relation rel, ForkNumber forknum, ReadStreamBlockNumberCB callback, void *callback_private_data, size_t per_buffer_data_size)
Definition: read_stream.c:716
void read_stream_end(ReadStream *stream)
Definition: read_stream.c:1055
BlockNumber(* ReadStreamBlockNumberCB)(ReadStream *stream, void *callback_private_data, void *per_buffer_data)
Definition: read_stream.h:77
BlockNumber block_range_read_stream_cb(ReadStream *stream, void *callback_private_data, void *per_buffer_data)
Definition: read_stream.c:162
struct BlockRangeReadStreamPrivate BlockRangeReadStreamPrivate
ForkNumber
Definition: relpath.h:56
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46