PostgreSQL Source Code git master
Loading...
Searching...
No Matches
relscan.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * relscan.h
4 * POSTGRES relation scan descriptor definitions.
5 *
6 *
7 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/include/access/relscan.h
11 *
12 *-------------------------------------------------------------------------
13 */
14#ifndef RELSCAN_H
15#define RELSCAN_H
16
17#include "access/htup_details.h"
18#include "access/itup.h"
19#include "nodes/tidbitmap.h"
20#include "port/atomics.h"
22#include "storage/spin.h"
23#include "utils/relcache.h"
24
25
28
29/*
30 * Generic descriptor for table scans. This is the base-class for table scans,
31 * which needs to be embedded in the scans of individual AMs.
32 */
33typedef struct TableScanDescData
34{
35 /* scan parameters */
36 Relation rs_rd; /* heap relation descriptor */
37 struct SnapshotData *rs_snapshot; /* snapshot to see */
38 int rs_nkeys; /* number of scan keys */
39 struct ScanKeyData *rs_key; /* array of scan key descriptors */
40
41 /*
42 * Scan type-specific members
43 */
44 union
45 {
46 /* Iterator for Bitmap Table Scans */
48
49 /*
50 * Range of ItemPointers for table_scan_getnextslot_tidrange() to
51 * scan.
52 */
53 struct
54 {
58 } st;
59
60 /*
61 * Information about type and behaviour of the scan, a bitmask of members
62 * of the ScanOptions enum (see tableam.h).
63 */
65
66 struct ParallelTableScanDescData *rs_parallel; /* parallel scan
67 * information */
68
69 /*
70 * Instrumentation counters maintained by all table AMs.
71 */
75
76/*
77 * Shared state for parallel table scan.
78 *
79 * Each backend participating in a parallel table scan has its own
80 * TableScanDesc in backend-private memory, and those objects all contain a
81 * pointer to this structure. The information here must be sufficient to
82 * properly initialize each new TableScanDesc as workers join the scan, and it
83 * must act as a information what to scan for those workers.
84 */
86{
87 RelFileLocator phs_locator; /* physical relation to scan */
88 bool phs_syncscan; /* report location to syncscan logic? */
89 bool phs_snapshot_any; /* SnapshotAny, not phs_snapshot_data? */
90 Size phs_snapshot_off; /* data for snapshot */
93
94/*
95 * Shared state for parallel table scans, for block oriented storage.
96 */
98{
100
101 BlockNumber phs_nblocks; /* # blocks in relation at start of scan */
102 slock_t phs_mutex; /* mutual exclusion for setting startblock */
103 BlockNumber phs_startblock; /* starting block number */
104 BlockNumber phs_numblock; /* # blocks to scan, or InvalidBlockNumber if
105 * no limit */
106 pg_atomic_uint64 phs_nallocated; /* number of blocks allocated to
107 * workers so far. */
110
111/*
112 * Per backend state for parallel table scan, for block-oriented storage.
113 */
115{
116 uint64 phsw_nallocated; /* Current # of blocks into the scan */
117 uint32 phsw_chunk_remaining; /* # blocks left in this chunk */
118 uint32 phsw_chunk_size; /* The number of blocks to allocate in
119 * each I/O chunk for the scan */
122
123/*
124 * Base class for fetches from a table via an index. This is the base-class
125 * for such scans, which needs to be embedded in the respective struct for
126 * individual AMs.
127 */
129{
131
132 /*
133 * Bitmask of ScanOptions affecting the relation. No SO_INTERNAL_FLAGS are
134 * permitted.
135 */
138
140
141/*
142 * We use the same IndexScanDescData structure for both amgettuple-based
143 * and amgetbitmap-based index scans. Some fields are only relevant in
144 * amgettuple-based scans.
145 */
146typedef struct IndexScanDescData
147{
148 /* scan parameters */
149 Relation heapRelation; /* heap relation descriptor, or NULL */
150 Relation indexRelation; /* index relation descriptor */
151 struct SnapshotData *xs_snapshot; /* snapshot to see */
152 int numberOfKeys; /* number of index qualifier conditions */
153 int numberOfOrderBys; /* number of ordering operators */
154 struct ScanKeyData *keyData; /* array of index qualifier descriptors */
155 struct ScanKeyData *orderByData; /* array of ordering op descriptors */
156 bool xs_want_itup; /* caller requests index tuples */
157 bool xs_temp_snap; /* unregister snapshot at scan end? */
158
159 /* signaling to index AM about killing index tuples */
160 bool kill_prior_tuple; /* last-returned tuple is dead */
161 bool ignore_killed_tuples; /* do not return killed entries */
162 bool xactStartedInRecovery; /* prevents killing/seeing killed
163 * tuples */
164
165 /* index access method's private state */
166 void *opaque; /* access-method-specific info */
167
168 /*
169 * Instrumentation counters maintained by all index AMs during both
170 * amgettuple calls and amgetbitmap calls (unless field remains NULL)
171 */
173
174 /*
175 * In an index-only scan, a successful amgettuple call must fill either
176 * xs_itup (and xs_itupdesc) or xs_hitup (and xs_hitupdesc) to provide the
177 * data returned by the scan. It can fill both, in which case the heap
178 * format will be used.
179 */
180 IndexTuple xs_itup; /* index tuple returned by AM */
181 struct TupleDescData *xs_itupdesc; /* rowtype descriptor of xs_itup */
182 HeapTuple xs_hitup; /* index data returned by AM, as HeapTuple */
183 struct TupleDescData *xs_hitupdesc; /* rowtype descriptor of xs_hitup */
184
186 bool xs_heap_continue; /* T if must keep walking, potential
187 * further results */
189
190 bool xs_recheck; /* T means scan keys must be rechecked */
191
192 /*
193 * When fetching with an ordering operator, the values of the ORDER BY
194 * expressions of the last returned tuple, according to the index. If
195 * xs_recheckorderby is true, these need to be rechecked just like the
196 * scan keys, and the values returned here are a lower-bound on the actual
197 * values.
198 */
202
203 /* parallel index scan information, in shared memory */
206
207/* Generic structure for parallel scans */
209{
210 RelFileLocator ps_locator; /* physical table relation to scan */
211 RelFileLocator ps_indexlocator; /* physical index relation to scan */
212 Size ps_offset_am; /* Offset to am-specific structure */
215
216struct TupleTableSlot;
217
218/* Struct for storage-or-index scans of system tables */
219typedef struct SysScanDescData
220{
221 Relation heap_rel; /* catalog being scanned */
222 Relation irel; /* NULL if doing heap scan */
223 struct TableScanDescData *scan; /* only valid in storage-scan case */
224 struct IndexScanDescData *iscan; /* only valid in index-scan case */
225 struct SnapshotData *snapshot; /* snapshot to unregister at end of scan */
228
229#endif /* RELSCAN_H */
uint32 BlockNumber
Definition block.h:31
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:558
uint64_t uint64
Definition c.h:625
uint32_t uint32
Definition c.h:624
size_t Size
Definition c.h:689
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
struct ParallelBlockTableScanDescData * ParallelBlockTableScanDesc
Definition relscan.h:109
struct ParallelTableScanDescData * ParallelTableScanDesc
Definition relscan.h:92
struct TableScanDescData * TableScanDesc
Definition relscan.h:74
struct ParallelBlockTableScanWorkerData * ParallelBlockTableScanWorker
Definition relscan.h:121
struct ScanKeyData * keyData
Definition relscan.h:154
bool xs_heap_continue
Definition relscan.h:186
struct ScanKeyData * orderByData
Definition relscan.h:155
HeapTuple xs_hitup
Definition relscan.h:182
struct ParallelIndexScanDescData * parallel_scan
Definition relscan.h:204
bool * xs_orderbynulls
Definition relscan.h:200
bool ignore_killed_tuples
Definition relscan.h:161
IndexFetchTableData * xs_heapfetch
Definition relscan.h:188
bool xactStartedInRecovery
Definition relscan.h:162
bool xs_recheckorderby
Definition relscan.h:201
struct IndexScanInstrumentation * instrument
Definition relscan.h:172
IndexTuple xs_itup
Definition relscan.h:180
bool kill_prior_tuple
Definition relscan.h:160
struct TupleDescData * xs_hitupdesc
Definition relscan.h:183
struct TupleDescData * xs_itupdesc
Definition relscan.h:181
Relation indexRelation
Definition relscan.h:150
ItemPointerData xs_heaptid
Definition relscan.h:185
struct SnapshotData * xs_snapshot
Definition relscan.h:151
Relation heapRelation
Definition relscan.h:149
Datum * xs_orderbyvals
Definition relscan.h:199
pg_atomic_uint64 phs_nallocated
Definition relscan.h:106
ParallelTableScanDescData base
Definition relscan.h:99
RelFileLocator ps_indexlocator
Definition relscan.h:211
RelFileLocator ps_locator
Definition relscan.h:210
char ps_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition relscan.h:213
RelFileLocator phs_locator
Definition relscan.h:87
Relation irel
Definition relscan.h:222
Relation heap_rel
Definition relscan.h:221
struct SnapshotData * snapshot
Definition relscan.h:225
struct IndexScanDescData * iscan
Definition relscan.h:224
struct TupleTableSlot * slot
Definition relscan.h:226
struct TableScanDescData * scan
Definition relscan.h:223
TBMIterator rs_tbmiterator
Definition relscan.h:47
Relation rs_rd
Definition relscan.h:36
union TableScanDescData::@55 st
struct TableScanInstrumentation * rs_instrument
Definition relscan.h:72
ItemPointerData rs_mintid
Definition relscan.h:55
ItemPointerData rs_maxtid
Definition relscan.h:56
uint32 rs_flags
Definition relscan.h:64
struct ScanKeyData * rs_key
Definition relscan.h:39
struct TableScanDescData::@55::@56 tidrange
struct SnapshotData * rs_snapshot
Definition relscan.h:37
struct ParallelTableScanDescData * rs_parallel
Definition relscan.h:66