relscan.h 5.6 KB

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