relscan.h 6.7 KB

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