PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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-2017, 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/genam.h"
18 #include "access/heapam.h"
19 #include "access/htup_details.h"
20 #include "access/itup.h"
21 #include "access/tupdesc.h"
22 #include "storage/spin.h"
23 
24 /*
25  * Shared state for parallel heap scan.
26  *
27  * Each backend participating in a parallel heap scan has its own
28  * HeapScanDesc in backend-private memory, and those objects all contain
29  * a pointer to this structure. The information here must be sufficient
30  * to properly initialize each new HeapScanDesc as workers join the scan,
31  * and it must act as a font of block numbers for those workers.
32  */
34 {
35  Oid phs_relid; /* OID of relation to scan */
36  bool phs_syncscan; /* report location to syncscan logic? */
37  BlockNumber phs_nblocks; /* # blocks in relation at start of scan */
38  slock_t phs_mutex; /* mutual exclusion for block number fields */
39  BlockNumber phs_startblock; /* starting block number */
40  BlockNumber phs_cblock; /* current block number */
41  char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER];
43 
44 typedef struct HeapScanDescData
45 {
46  /* scan parameters */
47  Relation rs_rd; /* heap relation descriptor */
48  Snapshot rs_snapshot; /* snapshot to see */
49  int rs_nkeys; /* number of scan keys */
50  ScanKey rs_key; /* array of scan key descriptors */
51  bool rs_bitmapscan; /* true if this is really a bitmap scan */
52  bool rs_samplescan; /* true if this is really a sample scan */
53  bool rs_pageatatime; /* verify visibility page-at-a-time? */
54  bool rs_allow_strat; /* allow or disallow use of access strategy */
55  bool rs_allow_sync; /* allow or disallow use of syncscan */
56  bool rs_temp_snap; /* unregister snapshot at scan end? */
57 
58  /* state set up at initscan time */
59  BlockNumber rs_nblocks; /* total number of blocks in rel */
60  BlockNumber rs_startblock; /* block # to start at */
61  BlockNumber rs_numblocks; /* max number of blocks to scan */
62  /* rs_numblocks is usually InvalidBlockNumber, meaning "scan whole rel" */
63  BufferAccessStrategy rs_strategy; /* access strategy for reads */
64  bool rs_syncscan; /* report location to syncscan logic? */
65 
66  /* scan current state */
67  bool rs_inited; /* false = scan not init'd yet */
68  HeapTupleData rs_ctup; /* current tuple in scan, if any */
69  BlockNumber rs_cblock; /* current block # in scan, if any */
70  Buffer rs_cbuf; /* current buffer in scan, if any */
71  /* NB: if rs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
72  ParallelHeapScanDesc rs_parallel; /* parallel scan information */
73 
74  /* these fields only used in page-at-a-time mode and for bitmap scans */
75  int rs_cindex; /* current tuple's index in vistuples */
76  int rs_ntuples; /* number of visible tuples on page */
79 
80 /*
81  * We use the same IndexScanDescData structure for both amgettuple-based
82  * and amgetbitmap-based index scans. Some fields are only relevant in
83  * amgettuple-based scans.
84  */
85 typedef struct IndexScanDescData
86 {
87  /* scan parameters */
88  Relation heapRelation; /* heap relation descriptor, or NULL */
89  Relation indexRelation; /* index relation descriptor */
90  Snapshot xs_snapshot; /* snapshot to see */
91  int numberOfKeys; /* number of index qualifier conditions */
92  int numberOfOrderBys; /* number of ordering operators */
93  ScanKey keyData; /* array of index qualifier descriptors */
94  ScanKey orderByData; /* array of ordering op descriptors */
95  bool xs_want_itup; /* caller requests index tuples */
96  bool xs_temp_snap; /* unregister snapshot at scan end? */
97 
98  /* signaling to index AM about killing index tuples */
99  bool kill_prior_tuple; /* last-returned tuple is dead */
100  bool ignore_killed_tuples; /* do not return killed entries */
101  bool xactStartedInRecovery; /* prevents killing/seeing killed
102  * tuples */
103 
104  /* index access method's private state */
105  void *opaque; /* access-method-specific info */
106 
107  /* in an index-only scan, this is valid after a successful amgettuple */
108  IndexTuple xs_itup; /* index tuple returned by AM */
109  TupleDesc xs_itupdesc; /* rowtype descriptor of xs_itup */
110 
111  /* xs_ctup/xs_cbuf/xs_recheck are valid after a successful index_getnext */
112  HeapTupleData xs_ctup; /* current heap tuple, if any */
113  Buffer xs_cbuf; /* current heap buffer in scan, if any */
114  /* NB: if xs_cbuf is not InvalidBuffer, we hold a pin on that buffer */
115  bool xs_recheck; /* T means scan keys must be rechecked */
116 
117  /*
118  * When fetching with an ordering operator, the values of the ORDER BY
119  * expressions of the last returned tuple, according to the index. If
120  * xs_recheckorderby is true, these need to be rechecked just like the
121  * scan keys, and the values returned here are a lower-bound on the actual
122  * values.
123  */
127 
128  /* state data for traversing HOT chains in index_getnext */
129  bool xs_continue_hot; /* T if must keep walking HOT chain */
130 
131  /* parallel index scan information, in shared memory */
134 
135 /* Generic structure for parallel scans */
137 {
140  Size ps_offset; /* Offset in bytes of am specific structure */
141  char ps_snapshot_data[FLEXIBLE_ARRAY_MEMBER];
143 
144 /* Struct for heap-or-index scans of system tables */
145 typedef struct SysScanDescData
146 {
147  Relation heap_rel; /* catalog being scanned */
148  Relation irel; /* NULL if doing heap scan */
149  HeapScanDesc scan; /* only valid in heap-scan case */
150  IndexScanDesc iscan; /* only valid in index-scan case */
151  Snapshot snapshot; /* snapshot to unregister at end of scan */
153 
154 #endif /* RELSCAN_H */
ParallelIndexScanDesc parallel_scan
Definition: relscan.h:132
int slock_t
Definition: s_lock.h:888
BlockNumber phs_cblock
Definition: relscan.h:40
Relation irel
Definition: relscan.h:148
Snapshot snapshot
Definition: relscan.h:151
BlockNumber rs_cblock
Definition: relscan.h:69
char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: relscan.h:41
Relation heap_rel
Definition: relscan.h:147
IndexTuple xs_itup
Definition: relscan.h:108
bool rs_allow_sync
Definition: relscan.h:55
#define MaxHeapTuplesPerPage
Definition: htup_details.h:575
Snapshot xs_snapshot
Definition: relscan.h:90
Datum * xs_orderbyvals
Definition: relscan.h:124
bool xs_recheckorderby
Definition: relscan.h:126
struct HeapScanDescData HeapScanDescData
uint32 BlockNumber
Definition: block.h:31
TupleDesc xs_itupdesc
Definition: relscan.h:109
char ps_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: relscan.h:141
unsigned int Oid
Definition: postgres_ext.h:31
IndexScanDesc iscan
Definition: relscan.h:150
bool ignore_killed_tuples
Definition: relscan.h:100
Relation indexRelation
Definition: relscan.h:89
HeapTupleData rs_ctup
Definition: relscan.h:68
uint16 OffsetNumber
Definition: off.h:24
Relation heapRelation
Definition: relscan.h:88
bool rs_bitmapscan
Definition: relscan.h:51
bool * xs_orderbynulls
Definition: relscan.h:125
Buffer xs_cbuf
Definition: relscan.h:113
bool rs_pageatatime
Definition: relscan.h:53
BlockNumber rs_numblocks
Definition: relscan.h:61
bool xs_temp_snap
Definition: relscan.h:96
ParallelHeapScanDesc rs_parallel
Definition: relscan.h:72
bool xactStartedInRecovery
Definition: relscan.h:101
bool xs_continue_hot
Definition: relscan.h:129
Snapshot rs_snapshot
Definition: relscan.h:48
struct ParallelHeapScanDescData ParallelHeapScanDescData
struct SysScanDescData SysScanDescData
bool rs_inited
Definition: relscan.h:67
BlockNumber rs_startblock
Definition: relscan.h:60
bool rs_temp_snap
Definition: relscan.h:56
ScanKey orderByData
Definition: relscan.h:94
uintptr_t Datum
Definition: postgres.h:374
BlockNumber rs_nblocks
Definition: relscan.h:59
BufferAccessStrategy rs_strategy
Definition: relscan.h:63
struct IndexScanDescData IndexScanDescData
BlockNumber phs_startblock
Definition: relscan.h:39
Relation rs_rd
Definition: relscan.h:47
bool xs_want_itup
Definition: relscan.h:95
Buffer rs_cbuf
Definition: relscan.h:70
OffsetNumber rs_vistuples[MaxHeapTuplesPerPage]
Definition: relscan.h:77
HeapTupleData xs_ctup
Definition: relscan.h:112
size_t Size
Definition: c.h:352
ScanKey keyData
Definition: relscan.h:93
HeapScanDesc scan
Definition: relscan.h:149
BlockNumber phs_nblocks
Definition: relscan.h:37
bool rs_allow_strat
Definition: relscan.h:54
bool kill_prior_tuple
Definition: relscan.h:99
struct ParallelIndexScanDescData ParallelIndexScanDescData
bool rs_syncscan
Definition: relscan.h:64
int numberOfOrderBys
Definition: relscan.h:92
int Buffer
Definition: buf.h:23
bool rs_samplescan
Definition: relscan.h:52
ScanKey rs_key
Definition: relscan.h:50