1515 *
1616 *
1717 * IDENTIFICATION
18- * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.61 2001/01/01 21:35:00 tgl Exp $
18+ * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.62 2001/01/10 01:12:28 tgl Exp $
1919 *
2020 *-------------------------------------------------------------------------
2121 */
3434#include "miscadmin.h"
3535#include "utils/builtins.h"
3636#include "utils/syscache.h"
37+ #include "utils/temprel.h"
3738
38- static Oid copy_heap (Oid OIDOldHeap ,char * NewName );
39+
40+ static Oid copy_heap (Oid OIDOldHeap ,char * NewName ,bool istemp );
3941static void copy_index (Oid OIDOldIndex ,Oid OIDNewHeap ,char * NewIndexName );
4042static void rebuildheap (Oid OIDNewHeap ,Oid OIDOldHeap ,Oid OIDOldIndex );
4143
@@ -60,6 +62,7 @@ cluster(char *oldrelname, char *oldindexname)
6062Relation OldHeap ,
6163OldIndex ;
6264HeapTuple tuple ;
65+ bool istemp ;
6366char NewHeapName [NAMEDATALEN ];
6467char NewIndexName [NAMEDATALEN ];
6568char saveoldrelname [NAMEDATALEN ];
@@ -82,6 +85,8 @@ cluster(char *oldrelname, char *oldindexname)
8285LockRelation (OldIndex ,AccessExclusiveLock );
8386OIDOldIndex = RelationGetRelid (OldIndex );
8487
88+ istemp = is_temp_rel_name (saveoldrelname );
89+
8590/*
8691 * Check that index is in fact an index on the given relation
8792 */
@@ -105,7 +110,7 @@ cluster(char *oldrelname, char *oldindexname)
105110 */
106111snprintf (NewHeapName ,NAMEDATALEN ,"temp_%u" ,OIDOldHeap );
107112
108- OIDNewHeap = copy_heap (OIDOldHeap ,NewHeapName );
113+ OIDNewHeap = copy_heap (OIDOldHeap ,NewHeapName , istemp );
109114
110115/* We do not need CommandCounterIncrement() because copy_heap did it. */
111116
@@ -138,7 +143,7 @@ cluster(char *oldrelname, char *oldindexname)
138143}
139144
140145static Oid
141- copy_heap (Oid OIDOldHeap ,char * NewName )
146+ copy_heap (Oid OIDOldHeap ,char * NewName , bool istemp )
142147{
143148TupleDesc OldHeapDesc ,
144149tupdesc ;
@@ -155,7 +160,7 @@ copy_heap(Oid OIDOldHeap, char *NewName)
155160tupdesc = CreateTupleDescCopy (OldHeapDesc );
156161
157162OIDNewHeap = heap_create_with_catalog (NewName ,tupdesc ,
158- RELKIND_RELATION ,false ,
163+ RELKIND_RELATION ,istemp ,
159164allowSystemTableMods );
160165
161166/*
@@ -192,9 +197,13 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap, char *NewIndexName)
192197OldIndex = index_open (OIDOldIndex );
193198
194199/*
195- * Create a new (temporary) index like the one that's already here.
196- * To do this I get the info from pg_index, and add a new index with
197- * a temporary name.
200+ * Create a new index like the old one. To do this I get the info
201+ * from pg_index, and add a new index with a temporary name (that
202+ * will be changed later).
203+ *
204+ * NOTE: index_create will cause the new index to be a temp relation
205+ * if its parent table is, so we don't need to do anything special
206+ * for the temp-table case here.
198207 */
199208Old_pg_index_Tuple = SearchSysCache (INDEXRELID ,
200209ObjectIdGetDatum (OIDOldIndex ),