mirror of
https://github.com/postgres/postgres.git
synced 2025-12-13 14:22:43 +03:00
Change snapshot type to be determined by enum rather than callback.
This is in preparation for allowing the same snapshot be used for
different table AMs. With the current callback based approach we would
need one callback for each supported AM, which clearly would not be
extensible. Thus add a new Snapshot->snapshot_type field, and move
the dispatch into HeapTupleSatisfiesVisibility() (which is now a
function). Later work will then dispatch calls to
HeapTupleSatisfiesVisibility() and other AMs visibility functions
depending on the type of the table. The central SnapshotType enum
also seems like a good location to centralize documentation about the
intended behaviour of various types of snapshots.
As tqual.h isn't included by bufmgr.h any more (as HeapTupleSatisfies*
isn't referenced by TestForOldSnapshot() anymore) a few files now need
to include it directly.
Author: Andres Freund, loosely based on earlier work by Haribabu Kommi
Discussion:
https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de
https://postgr.es/m/20160812231527.GA690404@alvherre.pgsql
This commit is contained in:
@@ -20,19 +20,89 @@
|
||||
#include "storage/buf.h"
|
||||
|
||||
|
||||
/*
|
||||
* The different snapshot types. We use SnapshotData structures to represent
|
||||
* both "regular" (MVCC) snapshots and "special" snapshots that have non-MVCC
|
||||
* semantics. The specific semantics of a snapshot are encoded by its type.
|
||||
*
|
||||
* The behaviour of each type of snapshot should be documented alongside its
|
||||
* enum value, best in terms that are not specific to an individual table AM.
|
||||
*
|
||||
* The reason the snapshot type rather than a callback as it used to be is
|
||||
* that that allows to use the same snapshot for different table AMs without
|
||||
* having one callback per AM.
|
||||
*/
|
||||
typedef enum SnapshotType
|
||||
{
|
||||
/*-------------------------------------------------------------------------
|
||||
* A tuple is visible iff the tuple is valid for the given MVCC snapshot.
|
||||
*
|
||||
* Here, we consider the effects of:
|
||||
* - all transactions committed as of the time of the given snapshot
|
||||
* - previous commands of this transaction
|
||||
*
|
||||
* Does _not_ include:
|
||||
* - transactions shown as in-progress by the snapshot
|
||||
* - transactions started after the snapshot was taken
|
||||
* - changes made by the current command
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
SNAPSHOT_MVCC = 0,
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* A tuple is visible iff the tuple is valid including effects of open
|
||||
* transactions.
|
||||
*
|
||||
* Here, we consider the effects of:
|
||||
* - all committed and in-progress transactions (as of the current instant)
|
||||
* - previous commands of this transaction
|
||||
* - changes made by the current command
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
SNAPSHOT_SELF,
|
||||
|
||||
/*
|
||||
* Any tuple is visible.
|
||||
*/
|
||||
SNAPSHOT_ANY,
|
||||
|
||||
/*
|
||||
* A tuple is visible iff the tuple tuple is valid as a TOAST row.
|
||||
*/
|
||||
SNAPSHOT_TOAST,
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* A tuple is visible iff the tuple is valid including effects of open
|
||||
* transactions.
|
||||
*
|
||||
* Here, we consider the effects of:
|
||||
* - all committed and in-progress transactions (as of the current instant)
|
||||
* - previous commands of this transaction
|
||||
* - changes made by the current command
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
SNAPSHOT_DIRTY,
|
||||
|
||||
/*
|
||||
* A tuple is visible iff it follows the rules of SNAPSHOT_MVCC, but
|
||||
* supports being called in timetravel context (for decoding catalog
|
||||
* contents in the context of logical decoding).
|
||||
*/
|
||||
SNAPSHOT_HISTORIC_MVCC,
|
||||
|
||||
/*
|
||||
* A tuple is visible iff the tuple might be visible to some transaction;
|
||||
* false if it's surely dead to everyone, ie, vacuumable.
|
||||
*
|
||||
* Snapshot.xmin must have been set up with the xmin horizon to use.
|
||||
*/
|
||||
SNAPSHOT_NON_VACUUMABLE
|
||||
} SnapshotType;
|
||||
|
||||
typedef struct SnapshotData *Snapshot;
|
||||
|
||||
#define InvalidSnapshot ((Snapshot) NULL)
|
||||
|
||||
/*
|
||||
* We use SnapshotData structures to represent both "regular" (MVCC)
|
||||
* snapshots and "special" snapshots that have non-MVCC semantics.
|
||||
* The specific semantics of a snapshot are encoded by the "satisfies"
|
||||
* function.
|
||||
*/
|
||||
typedef bool (*SnapshotSatisfiesFunc) (HeapTuple htup,
|
||||
Snapshot snapshot, Buffer buffer);
|
||||
|
||||
/*
|
||||
* Struct representing all kind of possible snapshots.
|
||||
*
|
||||
@@ -52,7 +122,7 @@ typedef bool (*SnapshotSatisfiesFunc) (HeapTuple htup,
|
||||
*/
|
||||
typedef struct SnapshotData
|
||||
{
|
||||
SnapshotSatisfiesFunc satisfies; /* tuple test function */
|
||||
SnapshotType snapshot_type; /* type of snapshot */
|
||||
|
||||
/*
|
||||
* The remaining fields are used only for MVCC snapshots, and are normally
|
||||
|
||||
Reference in New Issue
Block a user