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