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-2020, 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 "port/atomics.h"
20 #include "storage/buf.h"
21 #include "storage/spin.h"
22 #include "utils/relcache.h"
23 
24 
26 
27 /*
28  * Generic descriptor for table scans. This is the base-class for table scans,
29  * which needs to be embedded in the scans of individual AMs.
30  */
31 typedef struct TableScanDescData
32 {
33  /* scan parameters */
34  Relation rs_rd; /* heap relation descriptor */
35  struct SnapshotData *rs_snapshot; /* snapshot to see */
36  int rs_nkeys; /* number of scan keys */
37  struct ScanKeyData *rs_key; /* array of scan key descriptors */
38 
39  /*
40  * Information about type and behaviour of the scan, a bitmask of members
41  * of the ScanOptions enum (see tableam.h).
42  */
44 
45  void *rs_private; /* per-worker private memory for AM to use */
46  struct ParallelTableScanDescData *rs_parallel; /* parallel scan
47  * information */
50 
51 /*
52  * Shared state for parallel table scan.
53  *
54  * Each backend participating in a parallel table scan has its own
55  * TableScanDesc in backend-private memory, and those objects all contain a
56  * pointer to this structure. The information here must be sufficient to
57  * properly initialize each new TableScanDesc as workers join the scan, and it
58  * must act as a information what to scan for those workers.
59  */
61 {
62  Oid phs_relid; /* OID of relation to scan */
63  bool phs_syncscan; /* report location to syncscan logic? */
64  bool phs_snapshot_any; /* SnapshotAny, not phs_snapshot_data? */
65  Size phs_snapshot_off; /* data for snapshot */
68 
69 /*
70  * Shared state for parallel table scans, for block oriented storage.
71  */
73 {
75 
76  BlockNumber phs_nblocks; /* # blocks in relation at start of scan */
77  slock_t phs_mutex; /* mutual exclusion for setting startblock */
78  BlockNumber phs_startblock; /* starting block number */
79  pg_atomic_uint64 phs_nallocated; /* number of blocks allocated to
80  * workers so far. */
83 
84 /*
85  * Per backend state for parallel table scan, for block-oriented storage.
86  */
88 {
89  uint64 phsw_nallocated; /* Current # of blocks into the scan */
90  uint32 phsw_chunk_remaining; /* # blocks left in this chunk */
91  uint32 phsw_chunk_size; /* The number of blocks to allocate in
92  * each I/O chunk for the scan */
95 
96 /*
97  * Base class for fetches from a table via an index. This is the base-class
98  * for such scans, which needs to be embedded in the respective struct for
99  * individual AMs.
100  */
101 typedef struct IndexFetchTableData
102 {
105 
106 /*
107  * We use the same IndexScanDescData structure for both amgettuple-based
108  * and amgetbitmap-based index scans. Some fields are only relevant in
109  * amgettuple-based scans.
110  */
111 typedef struct IndexScanDescData
112 {
113  /* scan parameters */
114  Relation heapRelation; /* heap relation descriptor, or NULL */
115  Relation indexRelation; /* index relation descriptor */
116  struct SnapshotData *xs_snapshot; /* snapshot to see */
117  int numberOfKeys; /* number of index qualifier conditions */
118  int numberOfOrderBys; /* number of ordering operators */
119  struct ScanKeyData *keyData; /* array of index qualifier descriptors */
120  struct ScanKeyData *orderByData; /* array of ordering op descriptors */
121  bool xs_want_itup; /* caller requests index tuples */
122  bool xs_temp_snap; /* unregister snapshot at scan end? */
123 
124  /* signaling to index AM about killing index tuples */
125  bool kill_prior_tuple; /* last-returned tuple is dead */
126  bool ignore_killed_tuples; /* do not return killed entries */
127  bool xactStartedInRecovery; /* prevents killing/seeing killed
128  * tuples */
129 
130  /* index access method's private state */
131  void *opaque; /* access-method-specific info */
132 
133  /*
134  * In an index-only scan, a successful amgettuple call must fill either
135  * xs_itup (and xs_itupdesc) or xs_hitup (and xs_hitupdesc) to provide the
136  * data returned by the scan. It can fill both, in which case the heap
137  * format will be used.
138  */
139  IndexTuple xs_itup; /* index tuple returned by AM */
140  struct TupleDescData *xs_itupdesc; /* rowtype descriptor of xs_itup */
141  HeapTuple xs_hitup; /* index data returned by AM, as HeapTuple */
142  struct TupleDescData *xs_hitupdesc; /* rowtype descriptor of xs_hitup */
143 
145  bool xs_heap_continue; /* T if must keep walking, potential
146  * further results */
148 
149  bool xs_recheck; /* T means scan keys must be rechecked */
150 
151  /*
152  * When fetching with an ordering operator, the values of the ORDER BY
153  * expressions of the last returned tuple, according to the index. If
154  * xs_recheckorderby is true, these need to be rechecked just like the
155  * scan keys, and the values returned here are a lower-bound on the actual
156  * values.
157  */
161 
162  /* parallel index scan information, in shared memory */
165 
166 /* Generic structure for parallel scans */
168 {
171  Size ps_offset; /* Offset in bytes of am specific structure */
172  char ps_snapshot_data[FLEXIBLE_ARRAY_MEMBER];
174 
175 struct TupleTableSlot;
176 
177 /* Struct for storage-or-index scans of system tables */
178 typedef struct SysScanDescData
179 {
180  Relation heap_rel; /* catalog being scanned */
181  Relation irel; /* NULL if doing heap scan */
182  struct TableScanDescData *scan; /* only valid in storage-scan case */
183  struct IndexScanDescData *iscan; /* only valid in index-scan case */
184  struct SnapshotData *snapshot; /* snapshot to unregister at end of scan */
187 
188 #endif /* RELSCAN_H */
struct ParallelBlockTableScanWorkerData ParallelBlockTableScanWorkerData
pg_atomic_uint64 phs_nallocated
Definition: relscan.h:79
int slock_t
Definition: s_lock.h:934
Relation irel
Definition: relscan.h:181
Relation heap_rel
Definition: relscan.h:180
struct IndexFetchTableData IndexFetchTableData
ParallelTableScanDescData base
Definition: relscan.h:74
struct ScanKeyData * orderByData
Definition: relscan.h:120
IndexTuple xs_itup
Definition: relscan.h:139
struct TableScanDescData TableScanDescData
struct SnapshotData * snapshot
Definition: relscan.h:184
struct ParallelBlockTableScanDescData * ParallelBlockTableScanDesc
Definition: relscan.h:82
struct ParallelBlockTableScanDescData ParallelBlockTableScanDescData
struct TupleDescData * xs_itupdesc
Definition: relscan.h:140
struct TupleDescData * xs_hitupdesc
Definition: relscan.h:142
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:283
Datum * xs_orderbyvals
Definition: relscan.h:158
bool xs_recheckorderby
Definition: relscan.h:160
struct SnapshotData * xs_snapshot
Definition: relscan.h:116
uint32 BlockNumber
Definition: block.h:31
unsigned int Oid
Definition: postgres_ext.h:31
uint32 rs_flags
Definition: relscan.h:43
struct IndexScanDescData * iscan
Definition: relscan.h:183
struct TupleTableSlot * slot
Definition: relscan.h:185
bool ignore_killed_tuples
Definition: relscan.h:126
Relation indexRelation
Definition: relscan.h:115
Relation heapRelation
Definition: relscan.h:114
bool * xs_orderbynulls
Definition: relscan.h:159
struct TableScanDescData * scan
Definition: relscan.h:182
ItemPointerData xs_heaptid
Definition: relscan.h:144
bool xactStartedInRecovery
Definition: relscan.h:127
unsigned int uint32
Definition: c.h:374
struct ScanKeyData * rs_key
Definition: relscan.h:37
void * rs_private
Definition: relscan.h:45
struct IndexScanDescData IndexScanDescData
struct ParallelIndexScanDescData * parallel_scan
Definition: relscan.h:163
uintptr_t Datum
Definition: postgres.h:367
struct SysScanDescData SysScanDescData
IndexFetchTableData * xs_heapfetch
Definition: relscan.h:147
struct ParallelTableScanDescData * ParallelTableScanDesc
Definition: relscan.h:67
size_t Size
Definition: c.h:473
bool xs_heap_continue
Definition: relscan.h:145
Relation rs_rd
Definition: relscan.h:34
struct ScanKeyData * keyData
Definition: relscan.h:119
struct SnapshotData * rs_snapshot
Definition: relscan.h:35
HeapTuple xs_hitup
Definition: relscan.h:141
bool kill_prior_tuple
Definition: relscan.h:125
struct ParallelTableScanDescData * rs_parallel
Definition: relscan.h:46
int numberOfOrderBys
Definition: relscan.h:118
struct ParallelTableScanDescData ParallelTableScanDescData
struct ParallelIndexScanDescData ParallelIndexScanDescData
struct ParallelBlockTableScanWorkerData * ParallelBlockTableScanWorker
Definition: relscan.h:94
struct TableScanDescData * TableScanDesc
Definition: relscan.h:49