diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 0375e3104878b141ca4eda5e4bee52e287159c7c..9caad11ae638fbdd4ba6b6cdca203723d1df4872 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -27,7 +27,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.145 2001/08/10 18:57:35 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.146 2001/09/08 16:15:28 inoue Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1268,6 +1268,7 @@ ExecAppend(TupleTableSlot *slot,
 	 * insert the tuple
 	 */
 	newId = heap_insert(resultRelationDesc, tuple);
+	setLastTid(&(tuple->t_self));
 
 	IncrAppended();
 	(estate->es_processed)++;
diff --git a/src/backend/utils/adt/tid.c b/src/backend/utils/adt/tid.c
index db0e864cecfcd2f5c42f98e7eccff071a60123b3..a09c2f8f4d795a31bc023734aeea97bf28f8df4b 100644
--- a/src/backend/utils/adt/tid.c
+++ b/src/backend/utils/adt/tid.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.25 2001/07/06 09:41:36 inoue Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.26 2001/09/08 16:15:28 inoue Exp $
  *
  * NOTES
  *	  input routine largely stolen from boxin().
@@ -124,6 +124,11 @@ 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)
 {
@@ -133,6 +138,11 @@ currtid_byreloid(PG_FUNCTION_ARGS)
 	Relation	rel;
 
 	result = (ItemPointer) palloc(sizeof(ItemPointerData));
+	if (!reloid) 
+	{ 
+		*result = Current_last_tid; 
+		PG_RETURN_ITEMPOINTER(result); 
+	} 
 	ItemPointerCopy(tid, result);
 	if ((rel = heap_open(reloid, AccessShareLock)) != NULL)
 	{
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 2f9a6de2ad2a54bf2bbfea7a41e56f54245cb2dd..0a44e709a45d961210ef7a6e0dda717b0fd3fc95 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: heapam.h,v 1.66 2001/07/12 04:11:13 tgl Exp $
+ * $Id: heapam.h,v 1.67 2001/09/08 16:15:28 inoue Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -205,6 +205,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, IndexScanDesc iscan);
 extern ItemPointer heap_get_latest_tid(Relation relation, Snapshot snapshot, ItemPointer tid);
+extern void	setLastid(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,