Commit d6fa4d95 authored by Marc G. Fournier's avatar Marc G. Fournier

Fixes:

CLUSTER command couldn't rename correctly the new created heap relation.
The table base name resulted in some "temp_XXXX" instead of the correct
base name.

Submitted by: Dirk Koeser <koeser@informatik.uni-rostock.de>
parent 4844adc8
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.1.1.1 1996/07/09 06:21:19 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.2 1996/08/15 07:39:24 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -105,9 +105,18 @@ cluster(char oldrelname[], char oldindexname[]) ...@@ -105,9 +105,18 @@ cluster(char oldrelname[], char oldindexname[])
Relation OldHeap, OldIndex; Relation OldHeap, OldIndex;
Relation NewHeap; Relation NewHeap;
char *NewIndexName; char NewIndexName[NAMEDATALEN+1];
char *szNewHeapName; char NewHeapName[NAMEDATALEN+1];
char saveoldrelname[NAMEDATALEN+1];
char saveoldindexname[NAMEDATALEN+1];
/* Save the old names because they will get lost when the old relations
* are destroyed.
*/
strcpy(saveoldrelname, oldrelname);
strcpy(saveoldindexname, oldindexname);
/* /*
* *
* I'm going to force all checking back into the commands.c function. * I'm going to force all checking back into the commands.c function.
...@@ -153,55 +162,42 @@ cluster(char oldrelname[], char oldindexname[]) ...@@ -153,55 +162,42 @@ cluster(char oldrelname[], char oldindexname[])
*/ */
NewHeap = copy_heap(OIDOldHeap); NewHeap = copy_heap(OIDOldHeap);
OIDNewHeap = NewHeap->rd_id; OIDNewHeap = NewHeap->rd_id;
szNewHeapName = pstrdup(NewHeap->rd_rel->relname.data); strcpy(NewHeapName,NewHeap->rd_rel->relname.data);
/* Need to do this to make the new heap visible. */ /* To make the new heap visible (which is until now empty). */
CommandCounterIncrement(); CommandCounterIncrement();
rebuildheap(OIDNewHeap, OIDOldHeap, OIDOldIndex); rebuildheap(OIDNewHeap, OIDOldHeap, OIDOldIndex);
/* Need to do this to make the new heap visible. */ /* To flush the filled new heap (and the statistics about it). */
CommandCounterIncrement(); CommandCounterIncrement();
/* can't be found in the SysCache. */ /* Create new index over the tuples of the new heap. */
copy_index(OIDOldIndex, OIDNewHeap); /* No contention with the old */ copy_index(OIDOldIndex, OIDNewHeap);
sprintf(NewIndexName, "temp_%x", OIDOldIndex);
/* /*
* make this really happen. Flush all the buffers. * make this really happen. Flush all the buffers.
* (Believe me, it is necessary ... ended up in a mess without it.)
*/ */
CommitTransactionCommand(); CommitTransactionCommand();
StartTransactionCommand(); StartTransactionCommand();
/*
* Questionable bit here. Because the renamerel destroys all trace of the
* pre-existing relation, I'm going to Destroy old, and then rename new
* to old. If this fails, it fails, and you lose your old. Tough - say
* I. Have good backups!
*/
/*
Here lies the bogosity. The RelationNameGetRelation returns a bad /* Destroy old heap (along with its index) and rename new. */
list of TupleDescriptors. Damn. Can't work out why this is. heap_destroy(oldrelname);
*/
heap_destroy(oldrelname); /* AAAAAAAAGH!! */
CommandCounterIncrement();
/* renamerel(NewHeapName, saveoldrelname);
* The Commit flushes all palloced memory, so I have to grab the TypeRename(NewHeapName, saveoldrelname);
* New stuff again. This is annoying, but oh heck!
renamerel(NewIndexName, saveoldindexname);
/*
* Again flush all the buffers.
*/ */
/* CommitTransactionCommand();
renamerel(szNewHeapName.data, oldrelname); StartTransactionCommand();
TypeRename(&szNewHeapName, &szOldRelName);
sprintf(NewIndexName.data, "temp_%x", OIDOldIndex);
renamerel(NewIndexName.data, szOldIndexName.data);
*/
NewIndexName = palloc(NAMEDATALEN+1); /* XXX */
sprintf(NewIndexName, "temp_%x", OIDOldIndex);
renamerel(NewIndexName, oldindexname);
} }
Relation Relation
...@@ -362,6 +358,7 @@ rebuildheap(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex) ...@@ -362,6 +358,7 @@ rebuildheap(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
pfree(ScanResult); pfree(ScanResult);
ReleaseBuffer(LocalBuffer); ReleaseBuffer(LocalBuffer);
} }
index_endscan(ScanDesc);
index_close(LocalOldIndex); index_close(LocalOldIndex);
heap_close(LocalOldHeap); heap_close(LocalOldHeap);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment