tqual.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*-------------------------------------------------------------------------
  2. *
  3. * tqual.h
  4. * POSTGRES "time qualification" definitions, ie, tuple visibility rules.
  5. *
  6. * Should be moved/renamed... - vadim 07/28/98
  7. *
  8. * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
  9. * Portions Copyright (c) 1994, Regents of the University of California
  10. *
  11. * src/include/utils/tqual.h
  12. *
  13. *-------------------------------------------------------------------------
  14. */
  15. #ifndef TQUAL_H
  16. #define TQUAL_H
  17. #include "utils/snapshot.h"
  18. #include "access/xlogdefs.h"
  19. /* Static variables representing various special snapshot semantics */
  20. extern PGDLLIMPORT SnapshotData SnapshotSelfData;
  21. extern PGDLLIMPORT SnapshotData SnapshotAnyData;
  22. extern PGDLLIMPORT SnapshotData CatalogSnapshotData;
  23. #define SnapshotSelf (&SnapshotSelfData)
  24. #define SnapshotAny (&SnapshotAnyData)
  25. /* This macro encodes the knowledge of which snapshots are MVCC-safe */
  26. #define IsMVCCSnapshot(snapshot) \
  27. ((snapshot)->satisfies == HeapTupleSatisfiesMVCC || \
  28. (snapshot)->satisfies == HeapTupleSatisfiesHistoricMVCC)
  29. /*
  30. * HeapTupleSatisfiesVisibility
  31. * True iff heap tuple satisfies a time qual.
  32. *
  33. * Notes:
  34. * Assumes heap tuple is valid.
  35. * Beware of multiple evaluations of snapshot argument.
  36. * Hint bits in the HeapTuple's t_infomask may be updated as a side effect;
  37. * if so, the indicated buffer is marked dirty.
  38. */
  39. #define HeapTupleSatisfiesVisibility(tuple, snapshot, buffer) \
  40. ((*(snapshot)->satisfies) (tuple, snapshot, buffer))
  41. /* Result codes for HeapTupleSatisfiesVacuum */
  42. typedef enum
  43. {
  44. HEAPTUPLE_DEAD, /* tuple is dead and deletable */
  45. HEAPTUPLE_LIVE, /* tuple is live (committed, no deleter) */
  46. HEAPTUPLE_RECENTLY_DEAD, /* tuple is dead, but not deletable yet */
  47. HEAPTUPLE_INSERT_IN_PROGRESS, /* inserting xact is still in progress */
  48. HEAPTUPLE_DELETE_IN_PROGRESS /* deleting xact is still in progress */
  49. } HTSV_Result;
  50. /* These are the "satisfies" test routines for the various snapshot types */
  51. extern bool HeapTupleSatisfiesMVCC(HeapTuple htup,
  52. Snapshot snapshot, Buffer buffer);
  53. extern bool HeapTupleSatisfiesSelf(HeapTuple htup,
  54. Snapshot snapshot, Buffer buffer);
  55. extern bool HeapTupleSatisfiesAny(HeapTuple htup,
  56. Snapshot snapshot, Buffer buffer);
  57. extern bool HeapTupleSatisfiesToast(HeapTuple htup,
  58. Snapshot snapshot, Buffer buffer);
  59. extern bool HeapTupleSatisfiesDirty(HeapTuple htup,
  60. Snapshot snapshot, Buffer buffer);
  61. extern bool HeapTupleSatisfiesHistoricMVCC(HeapTuple htup,
  62. Snapshot snapshot, Buffer buffer);
  63. /* Special "satisfies" routines with different APIs */
  64. extern HTSU_Result HeapTupleSatisfiesUpdate(HeapTuple htup,
  65. CommandId curcid, Buffer buffer);
  66. extern HTSV_Result HeapTupleSatisfiesVacuum(HeapTuple htup,
  67. TransactionId OldestXmin, Buffer buffer);
  68. extern bool HeapTupleIsSurelyDead(HeapTuple htup,
  69. TransactionId OldestXmin);
  70. extern void HeapTupleSetHintBits(HeapTupleHeader tuple, Buffer buffer,
  71. uint16 infomask, TransactionId xid);
  72. extern bool HeapTupleHeaderIsOnlyLocked(HeapTupleHeader tuple);
  73. /*
  74. * To avoid leaking too much knowledge about reorderbuffer implementation
  75. * details this is implemented in reorderbuffer.c not tqual.c.
  76. */
  77. struct HTAB;
  78. extern bool ResolveCminCmaxDuringDecoding(struct HTAB *tuplecid_data,
  79. Snapshot snapshot,
  80. HeapTuple htup,
  81. Buffer buffer,
  82. CommandId *cmin, CommandId *cmax);
  83. /*
  84. * We don't provide a static SnapshotDirty variable because it would be
  85. * non-reentrant. Instead, users of that snapshot type should declare a
  86. * local variable of type SnapshotData, and initialize it with this macro.
  87. */
  88. #define InitDirtySnapshot(snapshotdata) \
  89. ((snapshotdata).satisfies = HeapTupleSatisfiesDirty)
  90. /*
  91. * Similarly, some initialization is required for SnapshotToast. We need
  92. * to set lsn and whenTaken correctly to support snapshot_too_old.
  93. */
  94. #define InitToastSnapshot(snapshotdata, l, w) \
  95. ((snapshotdata).satisfies = HeapTupleSatisfiesToast, \
  96. (snapshotdata).lsn = (l), \
  97. (snapshotdata).whenTaken = (w))
  98. #endif /* TQUAL_H */