PostgreSQL Source Code git master
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-2025, 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"
21#include "storage/buf.h"
23#include "storage/spin.h"
24#include "utils/relcache.h"
25
26
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 */
70
71/*
72 * Shared state for parallel table scan.
73 *
74 * Each backend participating in a parallel table scan has its own
75 * TableScanDesc in backend-private memory, and those objects all contain a
76 * pointer to this structure. The information here must be sufficient to
77 * properly initialize each new TableScanDesc as workers join the scan, and it
78 * must act as a information what to scan for those workers.
79 */
81{
82 RelFileLocator phs_locator; /* physical relation to scan */
83 bool phs_syncscan; /* report location to syncscan logic? */
84 bool phs_snapshot_any; /* SnapshotAny, not phs_snapshot_data? */
85 Size phs_snapshot_off; /* data for snapshot */
88
89/*
90 * Shared state for parallel table scans, for block oriented storage.
91 */
93{
95
96 BlockNumber phs_nblocks; /* # blocks in relation at start of scan */
97 slock_t phs_mutex; /* mutual exclusion for setting startblock */
98 BlockNumber phs_startblock; /* starting block number */
99 BlockNumber phs_numblock; /* # blocks to scan, or InvalidBlockNumber if
100 * no limit */
101 pg_atomic_uint64 phs_nallocated; /* number of blocks allocated to
102 * workers so far. */
105
106/*
107 * Per backend state for parallel table scan, for block-oriented storage.
108 */
110{
111 uint64 phsw_nallocated; /* Current # of blocks into the scan */
112 uint32 phsw_chunk_remaining; /* # blocks left in this chunk */
113 uint32 phsw_chunk_size; /* The number of blocks to allocate in
114 * each I/O chunk for the scan */
117
118/*
119 * Base class for fetches from a table via an index. This is the base-class
120 * for such scans, which needs to be embedded in the respective struct for
121 * individual AMs.
122 */
124{
127
129
130/*
131 * We use the same IndexScanDescData structure for both amgettuple-based
132 * and amgetbitmap-based index scans. Some fields are only relevant in
133 * amgettuple-based scans.
134 */
135typedef struct IndexScanDescData
136{
137 /* scan parameters */
138 Relation heapRelation; /* heap relation descriptor, or NULL */
139 Relation indexRelation; /* index relation descriptor */
140 struct SnapshotData *xs_snapshot; /* snapshot to see */
141 int numberOfKeys; /* number of index qualifier conditions */
142 int numberOfOrderBys; /* number of ordering operators */
143 struct ScanKeyData *keyData; /* array of index qualifier descriptors */
144 struct ScanKeyData *orderByData; /* array of ordering op descriptors */
145 bool xs_want_itup; /* caller requests index tuples */
146 bool xs_temp_snap; /* unregister snapshot at scan end? */
147
148 /* signaling to index AM about killing index tuples */
149 bool kill_prior_tuple; /* last-returned tuple is dead */
150 bool ignore_killed_tuples; /* do not return killed entries */
151 bool xactStartedInRecovery; /* prevents killing/seeing killed
152 * tuples */
153
154 /* index access method's private state */
155 void *opaque; /* access-method-specific info */
156
157 /*
158 * Instrumentation counters maintained by all index AMs during both
159 * amgettuple calls and amgetbitmap calls (unless field remains NULL)
160 */
162
163 /*
164 * In an index-only scan, a successful amgettuple call must fill either
165 * xs_itup (and xs_itupdesc) or xs_hitup (and xs_hitupdesc) to provide the
166 * data returned by the scan. It can fill both, in which case the heap
167 * format will be used.
168 */
169 IndexTuple xs_itup; /* index tuple returned by AM */
170 struct TupleDescData *xs_itupdesc; /* rowtype descriptor of xs_itup */
171 HeapTuple xs_hitup; /* index data returned by AM, as HeapTuple */
172 struct TupleDescData *xs_hitupdesc; /* rowtype descriptor of xs_hitup */
173
175 bool xs_heap_continue; /* T if must keep walking, potential
176 * further results */
178
179 bool xs_recheck; /* T means scan keys must be rechecked */
180
181 /*
182 * When fetching with an ordering operator, the values of the ORDER BY
183 * expressions of the last returned tuple, according to the index. If
184 * xs_recheckorderby is true, these need to be rechecked just like the
185 * scan keys, and the values returned here are a lower-bound on the actual
186 * values.
187 */
191
192 /* parallel index scan information, in shared memory */
195
196/* Generic structure for parallel scans */
198{
199 RelFileLocator ps_locator; /* physical table relation to scan */
200 RelFileLocator ps_indexlocator; /* physical index relation to scan */
201 Size ps_offset_ins; /* Offset to SharedIndexScanInstrumentation */
202 Size ps_offset_am; /* Offset to am-specific structure */
205
206struct TupleTableSlot;
207
208/* Struct for storage-or-index scans of system tables */
209typedef struct SysScanDescData
210{
211 Relation heap_rel; /* catalog being scanned */
212 Relation irel; /* NULL if doing heap scan */
213 struct TableScanDescData *scan; /* only valid in storage-scan case */
214 struct IndexScanDescData *iscan; /* only valid in index-scan case */
215 struct SnapshotData *snapshot; /* snapshot to unregister at end of scan */
218
219#endif /* RELSCAN_H */
uint32 BlockNumber
Definition: block.h:31
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:475
uint64_t uint64
Definition: c.h:544
uint32_t uint32
Definition: c.h:543
size_t Size
Definition: c.h:615
uint64_t Datum
Definition: postgres.h:70
struct ParallelBlockTableScanWorkerData ParallelBlockTableScanWorkerData
struct ParallelBlockTableScanDescData * ParallelBlockTableScanDesc
Definition: relscan.h:104
struct IndexScanDescData IndexScanDescData
struct ParallelTableScanDescData ParallelTableScanDescData
struct ParallelTableScanDescData * ParallelTableScanDesc
Definition: relscan.h:87
struct IndexFetchTableData IndexFetchTableData
struct SysScanDescData SysScanDescData
struct ParallelBlockTableScanDescData ParallelBlockTableScanDescData
struct TableScanDescData * TableScanDesc
Definition: relscan.h:69
struct TableScanDescData TableScanDescData
struct ParallelIndexScanDescData ParallelIndexScanDescData
struct ParallelBlockTableScanWorkerData * ParallelBlockTableScanWorker
Definition: relscan.h:116
struct ScanKeyData * keyData
Definition: relscan.h:143
bool xs_heap_continue
Definition: relscan.h:175
struct ScanKeyData * orderByData
Definition: relscan.h:144
HeapTuple xs_hitup
Definition: relscan.h:171
struct ParallelIndexScanDescData * parallel_scan
Definition: relscan.h:193
bool * xs_orderbynulls
Definition: relscan.h:189
bool ignore_killed_tuples
Definition: relscan.h:150
IndexFetchTableData * xs_heapfetch
Definition: relscan.h:177
int numberOfOrderBys
Definition: relscan.h:142
bool xactStartedInRecovery
Definition: relscan.h:151
bool xs_recheckorderby
Definition: relscan.h:190
struct IndexScanInstrumentation * instrument
Definition: relscan.h:161
IndexTuple xs_itup
Definition: relscan.h:169
bool kill_prior_tuple
Definition: relscan.h:149
struct TupleDescData * xs_hitupdesc
Definition: relscan.h:172
struct TupleDescData * xs_itupdesc
Definition: relscan.h:170
Relation indexRelation
Definition: relscan.h:139
ItemPointerData xs_heaptid
Definition: relscan.h:174
struct SnapshotData * xs_snapshot
Definition: relscan.h:140
Relation heapRelation
Definition: relscan.h:138
Datum * xs_orderbyvals
Definition: relscan.h:188
pg_atomic_uint64 phs_nallocated
Definition: relscan.h:101
ParallelTableScanDescData base
Definition: relscan.h:94
RelFileLocator ps_indexlocator
Definition: relscan.h:200
RelFileLocator ps_locator
Definition: relscan.h:199
char ps_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: relscan.h:203
RelFileLocator phs_locator
Definition: relscan.h:82
Relation irel
Definition: relscan.h:212
Relation heap_rel
Definition: relscan.h:211
struct SnapshotData * snapshot
Definition: relscan.h:215
struct IndexScanDescData * iscan
Definition: relscan.h:214
struct TupleTableSlot * slot
Definition: relscan.h:216
struct TableScanDescData * scan
Definition: relscan.h:213
struct TableScanDescData::@50::@51 tidrange
TBMIterator rs_tbmiterator
Definition: relscan.h:47
Relation rs_rd
Definition: relscan.h:36
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 SnapshotData * rs_snapshot
Definition: relscan.h:37
union TableScanDescData::@50 st
struct ParallelTableScanDescData * rs_parallel
Definition: relscan.h:66