gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 line
6.1KB

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