Jim C. Nasby wrote:
> On Tue, May 15, 2007 at 06:13:47PM -0400, Alvaro Herrera wrote:
> > Tom Lane wrote:
> > > Alvaro Herrera <[EMAIL PROTECTED]> writes:
> > > > I suppose it would be pretty trivial to set the relfrozenxid to
> > > > RecentXmin or something during TRUNCATE.
> > >
> > > I had the idea we were doing that already --- at least I'm pretty sure I
> > > remember it being discussed. But I see it's not being done in HEAD.
> >
> > Patch to do it attached. I am thinking we can do something similar in
> > CLUSTER as well.
>
> Actually, it already happens for CLUSTER because cluster calls
> heap_create_with_catalog, which calls AddNewRelationTuple. See
> backend/catalog/heap.c line 716.
Right, but that heap is dropped later, and only the relfilenode remains,
because they are swapped.
In any case the change is a very small patch, which I attach but I
haven't tested. This only works if the new rewriteheap stuff actually
changes Xids to follow OldestXmin, i.e. all tuples that have older
Xmin/Xmax are frozen (or marked with the current Xid). Heikki, can you
confirm that this is the case?
--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
Index: src/backend/commands/cluster.c
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/commands/cluster.c,v
retrieving revision 1.159
diff -c -p -r1.159 cluster.c
*** src/backend/commands/cluster.c 8 Apr 2007 01:26:28 -0000 1.159
--- src/backend/commands/cluster.c 15 May 2007 22:55:22 -0000
*************** typedef struct
*** 54,60 ****
static void cluster_rel(RelToCluster *rv, bool recheck);
static void rebuild_relation(Relation OldHeap, Oid indexOid);
! static void copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex);
static List *get_tables_to_cluster(MemoryContext cluster_context);
--- 54,60 ----
static void cluster_rel(RelToCluster *rv, bool recheck);
static void rebuild_relation(Relation OldHeap, Oid indexOid);
! static TransactionId copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex);
static List *get_tables_to_cluster(MemoryContext cluster_context);
*************** rebuild_relation(Relation OldHeap, Oid i
*** 512,517 ****
--- 512,518 ----
Oid tableSpace = OldHeap->rd_rel->reltablespace;
Oid OIDNewHeap;
char NewHeapName[NAMEDATALEN];
+ TransactionId frozenXid;
ObjectAddress object;
/* Mark the correct index as clustered */
*************** rebuild_relation(Relation OldHeap, Oid i
*** 538,548 ****
/*
* Copy the heap data into the new table in the desired order.
*/
! copy_heap_data(OIDNewHeap, tableOid, indexOid);
/* To make the new heap's data visible (probably not needed?). */
CommandCounterIncrement();
/* Swap the physical files of the old and new heaps. */
swap_relation_files(tableOid, OIDNewHeap);
--- 539,556 ----
/*
* Copy the heap data into the new table in the desired order.
*/
! frozenXid = copy_heap_data(OIDNewHeap, tableOid, indexOid);
/* To make the new heap's data visible (probably not needed?). */
CommandCounterIncrement();
+ /*
+ * update the relation's freeze Xid. We don't need to change the
+ * actual tuple on disk, because swap_relation_files will do it for
+ * us.
+ */
+ OldHeap->rd_rel->relfrozenxid = frozenXid;
+
/* Swap the physical files of the old and new heaps. */
swap_relation_files(tableOid, OIDNewHeap);
*************** make_new_heap(Oid OIDOldHeap, const char
*** 640,648 ****
}
/*
! * Do the physical copying of heap data.
*/
! static void
copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
{
Relation NewHeap,
--- 648,657 ----
}
/*
! * Do the physical copying of heap data. Returns the transaction ID used as
! * cutoff point.
*/
! static TransactionId
copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
{
Relation NewHeap,
*************** copy_heap_data(Oid OIDNewHeap, Oid OIDOl
*** 809,814 ****
--- 818,825 ----
index_close(OldIndex, NoLock);
heap_close(OldHeap, NoLock);
heap_close(NewHeap, NoLock);
+
+ return OldestXmin;
}
/*
---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to [EMAIL PROTECTED] so that your
message can get through to the mailing list cleanly