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