Renumber SnapshotNow and the other special snapshot codes so that
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 11 Sep 2004 18:28:34 +0000 (18:28 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 11 Sep 2004 18:28:34 +0000 (18:28 +0000)
((Snapshot) NULL) can no longer be confused with a valid snapshot,
as per my recent suggestion.  Define a macro InvalidSnapshot for 0.
Use InvalidSnapshot instead of SnapshotAny as the do-nothing special
case for heap_update and heap_delete crosschecks; this seems a little
cleaner even though the behavior is really the same.

src/backend/access/heap/heapam.c
src/backend/commands/async.c
src/backend/executor/execMain.c
src/backend/executor/execUtils.c
src/include/utils/tqual.h

index 6dd0c357fbb14f8c8e4cea3873dca38910da3e62..e5284d0b8c11a9f252ba0d1ede0e51cfa6e2efe8 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.173 2004/08/29 05:06:40 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.174 2004/09/11 18:28:32 tgl Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -1262,7 +1262,7 @@ simple_heap_insert(Relation relation, HeapTuple tup)
  * tid - TID of tuple to be deleted
  * ctid - output parameter, used only for failure case (see below)
  * cid - delete command ID to use in verifying tuple visibility
- * crosscheck - if not SnapshotAny, also check tuple against this
+ * crosscheck - if not InvalidSnapshot, also check tuple against this
  * wait - true if should wait for any conflicting update to commit/abort
  *
  * Normal, successful return value is HeapTupleMayBeUpdated, which
@@ -1274,7 +1274,8 @@ simple_heap_insert(Relation relation, HeapTuple tup)
  */
 int
 heap_delete(Relation relation, ItemPointer tid,
-        ItemPointer ctid, CommandId cid, Snapshot crosscheck, bool wait)
+           ItemPointer ctid, CommandId cid,
+           Snapshot crosscheck, bool wait)
 {
    ItemId      lp;
    HeapTupleData tp;
@@ -1339,7 +1340,7 @@ l1:
            result = HeapTupleUpdated;
    }
 
-   if (crosscheck != SnapshotAny && result == HeapTupleMayBeUpdated)
+   if (crosscheck != InvalidSnapshot && result == HeapTupleMayBeUpdated)
    {
        /* Perform additional check for serializable RI updates */
        if (!HeapTupleSatisfiesSnapshot(tp.t_data, crosscheck))
@@ -1443,7 +1444,7 @@ simple_heap_delete(Relation relation, ItemPointer tid)
 
    result = heap_delete(relation, tid,
                         &ctid,
-                        GetCurrentCommandId(), SnapshotAny,
+                        GetCurrentCommandId(), InvalidSnapshot,
                         true /* wait for commit */ );
    switch (result)
    {
@@ -1477,7 +1478,7 @@ simple_heap_delete(Relation relation, ItemPointer tid)
  * newtup - newly constructed tuple data to store
  * ctid - output parameter, used only for failure case (see below)
  * cid - update command ID to use in verifying old tuple visibility
- * crosscheck - if not SnapshotAny, also check old tuple against this
+ * crosscheck - if not InvalidSnapshot, also check old tuple against this
  * wait - true if should wait for any conflicting update to commit/abort
  *
  * Normal, successful return value is HeapTupleMayBeUpdated, which
@@ -1491,7 +1492,8 @@ simple_heap_delete(Relation relation, ItemPointer tid)
  */
 int
 heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
-        ItemPointer ctid, CommandId cid, Snapshot crosscheck, bool wait)
+           ItemPointer ctid, CommandId cid,
+           Snapshot crosscheck, bool wait)
 {
    ItemId      lp;
    HeapTupleData oldtup;
@@ -1566,7 +1568,7 @@ l2:
            result = HeapTupleUpdated;
    }
 
-   if (crosscheck != SnapshotAny && result == HeapTupleMayBeUpdated)
+   if (crosscheck != InvalidSnapshot && result == HeapTupleMayBeUpdated)
    {
        /* Perform additional check for serializable RI updates */
        if (!HeapTupleSatisfiesSnapshot(oldtup.t_data, crosscheck))
@@ -1804,7 +1806,7 @@ simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
 
    result = heap_update(relation, otid, tup,
                         &ctid,
-                        GetCurrentCommandId(), SnapshotAny,
+                        GetCurrentCommandId(), InvalidSnapshot,
                         true /* wait for commit */ );
    switch (result)
    {
index f25b8570455004ba2b9fefdabe9a07b88cc573fb..c964f8d9fa789c71fad9fe43b41ec379d5d78355 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.116 2004/09/06 23:32:54 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.117 2004/09/11 18:28:33 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -544,7 +544,7 @@ AtCommit_Notify(void)
                 */
                result = heap_update(lRel, &lTuple->t_self, rTuple,
                                     &ctid,
-                                    GetCurrentCommandId(), SnapshotAny,
+                                    GetCurrentCommandId(), InvalidSnapshot,
                                     false /* no wait for commit */ );
                switch (result)
                {
index d77bc7054a31455ce42de96eb038cc2532d6545f..b009e73e105d282afb8faa9d8312ac2341bfd3a3 100644 (file)
@@ -26,7 +26,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.236 2004/08/29 05:06:42 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.237 2004/09/11 18:28:34 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -176,7 +176,7 @@ ExecutorStart(QueryDesc *queryDesc, bool useCurrentSnapshot, bool explainOnly)
    {
        /* normal query --- use query snapshot, no crosscheck */
        estate->es_snapshot = CopyQuerySnapshot();
-       estate->es_crosscheck_snapshot = SnapshotAny;
+       estate->es_crosscheck_snapshot = InvalidSnapshot;
    }
 
    /*
index 79ab787b07a0fcdeddf316d5a4000cb9a7902d49..a1736766b2675eabe43e2032c06fff9248c63a91 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/executor/execUtils.c,v 1.114 2004/08/29 05:06:42 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/executor/execUtils.c,v 1.115 2004/09/11 18:28:34 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -179,7 +179,7 @@ CreateExecutorState(void)
     */
    estate->es_direction = ForwardScanDirection;
    estate->es_snapshot = SnapshotNow;
-   estate->es_crosscheck_snapshot = SnapshotAny;       /* means no crosscheck */
+   estate->es_crosscheck_snapshot = InvalidSnapshot;   /* no crosscheck */
    estate->es_range_table = NIL;
 
    estate->es_result_relations = NULL;
index e378e444da1be2a2fce399d2095b410671be3ea2..627bcaf75a12f8f59c96b79d2b9bab1ae422c878 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/utils/tqual.h,v 1.50 2004/08/29 04:13:11 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/tqual.h,v 1.51 2004/09/11 18:28:34 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include "access/xact.h"
 
 
+/*
+ * "Regular" snapshots are pointers to a SnapshotData structure.
+ *
+ * We also have some "special" snapshot values that have fixed meanings
+ * and don't need any backing SnapshotData.  These are encoded by small
+ * integer values, which of course is a gross violation of ANSI C, but
+ * it works fine on all known platforms.
+ *
+ * SnapshotDirty is an even more special case: its semantics are fixed,
+ * but there is a backing SnapshotData struct for it.  That struct is
+ * actually used as *output* data from tqual.c, not input into it.
+ * (But hey, SnapshotDirty ought to have a dirty implementation, no? ;-))
+ */
+
 typedef struct SnapshotData
 {
    TransactionId xmin;         /* XID < xmin are visible to me */
@@ -32,10 +46,12 @@ typedef struct SnapshotData
 
 typedef SnapshotData *Snapshot;
 
-#define SnapshotNow                    ((Snapshot) 0x0)
-#define SnapshotSelf               ((Snapshot) 0x1)
-#define SnapshotAny                    ((Snapshot) 0x2)
-#define SnapshotToast              ((Snapshot) 0x3)
+/* Special snapshot values: */
+#define InvalidSnapshot                ((Snapshot) 0x0) /* same as NULL */
+#define SnapshotNow                    ((Snapshot) 0x1)
+#define SnapshotSelf               ((Snapshot) 0x2)
+#define SnapshotAny                    ((Snapshot) 0x3)
+#define SnapshotToast              ((Snapshot) 0x4)
 
 extern DLLIMPORT Snapshot SnapshotDirty;
 extern DLLIMPORT Snapshot QuerySnapshot;