fix my old fault.
authorHiroshi Inoue <[email protected]>
Thu, 9 Aug 2001 19:22:24 +0000 (19:22 +0000)
committerHiroshi Inoue <[email protected]>
Thu, 9 Aug 2001 19:22:24 +0000 (19:22 +0000)
src/backend/access/heap/heapam.c
src/backend/executor/execMain.c
src/backend/utils/adt/tid.c
src/include/access/heapam.h

index 522e2b79778b3fbbe7246e9e241fab9cb730757e..bf12dad8d9349296e69f6426e1826757251dc1d1 100644 (file)
@@ -1256,7 +1256,8 @@ heap_get_latest_tid(Relation relation,
        {
                if (linkend)
                        return NULL;
-               return heap_get_latest_tid(relation, snapshot, &ctid);
+               heap_get_latest_tid(relation, snapshot, &ctid);
+               *tid = ctid;
        }
 
        return tid;
index 822affed09319ab3bb0e6de1cdce281e0255a59c..4e889d0787e122286187400d88a33cfbd5457e23 100644 (file)
@@ -1255,6 +1255,7 @@ ExecAppend(TupleTableSlot *slot,
         * insert the tuple
         */
        newId = heap_insert(resultRelationDesc, tuple);
+       setLastTid(&(tuple->t_self));
 
        IncrAppended();
        (estate->es_processed)++;
index 97da97a01c0d4117e5fa6a4a84dc2707d853679a..f039d69fced7d40df822bacfb9fc2ba7da37b74c 100644 (file)
@@ -124,22 +124,29 @@ tidne(PG_FUNCTION_ARGS)
  *
  *     Maybe these implementations should be moved to another place
  */
+static ItemPointerData Current_last_tid = { {0, 0}, 0};
+void   setLastTid(const ItemPointer tid)
+{
+       Current_last_tid = *tid;
+}
 Datum
 currtid_byreloid(PG_FUNCTION_ARGS)
 {
        Oid                     reloid = PG_GETARG_OID(0);
        ItemPointer tid = PG_GETARG_ITEMPOINTER(1);
-       ItemPointer result,
-                               ret;
+       ItemPointer result;
        Relation        rel;
 
        result = (ItemPointer) palloc(sizeof(ItemPointerData));
-       ItemPointerSetInvalid(result);
+       if (!reloid)
+       {
+               *result = Current_last_tid;
+               PG_RETURN_ITEMPOINTER(result);
+       }
+       ItemPointerCopy(tid, result);
        if ((rel = heap_open(reloid, AccessShareLock)) != NULL)
        {
-               ret = heap_get_latest_tid(rel, SnapshotNow, tid);
-               if (ret)
-                       ItemPointerCopy(ret, result);
+               heap_get_latest_tid(rel, SnapshotNow, result);
                heap_close(rel, AccessShareLock);
        }
        else
@@ -153,8 +160,7 @@ currtid_byrelname(PG_FUNCTION_ARGS)
 {
        text       *relname = PG_GETARG_TEXT_P(0);
        ItemPointer tid = PG_GETARG_ITEMPOINTER(1);
-       ItemPointer result,
-                               ret;
+       ItemPointer result;
        char       *str;
        Relation        rel;
 
@@ -162,12 +168,10 @@ currtid_byrelname(PG_FUNCTION_ARGS)
                                                                                          PointerGetDatum(relname)));
 
        result = (ItemPointer) palloc(sizeof(ItemPointerData));
-       ItemPointerSetInvalid(result);
+       ItemPointerCopy(tid, result);
        if ((rel = heap_openr(str, AccessShareLock)) != NULL)
        {
-               ret = heap_get_latest_tid(rel, SnapshotNow, tid);
-               if (ret)
-                       ItemPointerCopy(ret, result);
+               heap_get_latest_tid(rel, SnapshotNow, result);
                heap_close(rel, AccessShareLock);
        }
        else
index 089dfee6aa295fe2263ec2370cedb496fe25e68d..2c1415c3ee1775fb87e92be3d7928ae2a3435da4 100644 (file)
@@ -204,6 +204,7 @@ extern void heap_endscan(HeapScanDesc scan);
 extern HeapTuple heap_getnext(HeapScanDesc scandesc, int backw);
 extern void heap_fetch(Relation relation, Snapshot snapshot, HeapTuple tup, Buffer *userbuf);
 extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid);
+extern void    setLastTid(const ItemPointer tid);
 extern Oid     heap_insert(Relation relation, HeapTuple tup);
 extern int     heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid);
 extern int heap_update(Relation relation, ItemPointer otid, HeapTuple tup,