Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 412cb38

Browse files
committed
Do The Right Thing (tm) if asked to cluster a temp table. Previous
code would cluster, but table would magically lose its tempness.
1 parent 353f71a commit 412cb38

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/backend/commands/cluster.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
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
*/
@@ -34,8 +34,10 @@
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);
3941
static void copy_index(Oid OIDOldIndex, Oid OIDNewHeap, char *NewIndexName);
4042
static void rebuildheap(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex);
4143

@@ -60,6 +62,7 @@ cluster(char *oldrelname, char *oldindexname)
6062
Relation OldHeap,
6163
OldIndex;
6264
HeapTuple tuple;
65+
bool istemp;
6366
char NewHeapName[NAMEDATALEN];
6467
char NewIndexName[NAMEDATALEN];
6568
char saveoldrelname[NAMEDATALEN];
@@ -82,6 +85,8 @@ cluster(char *oldrelname, char *oldindexname)
8285
LockRelation(OldIndex, AccessExclusiveLock);
8386
OIDOldIndex = 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
*/
106111
snprintf(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

140145
static Oid
141-
copy_heap(Oid OIDOldHeap, char *NewName)
146+
copy_heap(Oid OIDOldHeap, char *NewName, bool istemp)
142147
{
143148
TupleDesc OldHeapDesc,
144149
tupdesc;
@@ -155,7 +160,7 @@ copy_heap(Oid OIDOldHeap, char *NewName)
155160
tupdesc = CreateTupleDescCopy(OldHeapDesc);
156161

157162
OIDNewHeap = heap_create_with_catalog(NewName, tupdesc,
158-
RELKIND_RELATION, false,
163+
RELKIND_RELATION, istemp,
159164
allowSystemTableMods);
160165

161166
/*
@@ -192,9 +197,13 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap, char *NewIndexName)
192197
OldIndex = 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
*/
199208
Old_pg_index_Tuple = SearchSysCache(INDEXRELID,
200209
ObjectIdGetDatum(OIDOldIndex),

0 commit comments

Comments
 (0)