Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd6fa4d9

Browse files
committed
Fixes:
CLUSTER command couldn't rename correctly the new created heap relation.The table base name resulted in some "temp_XXXX" instead of the correctbase name.Submitted by: Dirk Koeser <koeser@informatik.uni-rostock.de>
1 parent4844adc commitd6fa4d9

File tree

1 file changed

+34
-37
lines changed

1 file changed

+34
-37
lines changed

‎src/backend/commands/cluster.c‎

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.1.1.1 1996/07/09 06:21:19 scrappy Exp $
17+
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.2 1996/08/15 07:39:24 scrappy Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -105,9 +105,18 @@ cluster(char oldrelname[], char oldindexname[])
105105
RelationOldHeap,OldIndex;
106106
RelationNewHeap;
107107

108-
char*NewIndexName;
109-
char*szNewHeapName;
110-
108+
charNewIndexName[NAMEDATALEN+1];
109+
charNewHeapName[NAMEDATALEN+1];
110+
charsaveoldrelname[NAMEDATALEN+1];
111+
charsaveoldindexname[NAMEDATALEN+1];
112+
113+
114+
/* Save the old names because they will get lost when the old relations
115+
* are destroyed.
116+
*/
117+
strcpy(saveoldrelname,oldrelname);
118+
strcpy(saveoldindexname,oldindexname);
119+
111120
/*
112121
*
113122
* I'm going to force all checking back into the commands.c function.
@@ -153,55 +162,42 @@ cluster(char oldrelname[], char oldindexname[])
153162
*/
154163
NewHeap=copy_heap(OIDOldHeap);
155164
OIDNewHeap=NewHeap->rd_id;
156-
szNewHeapName=pstrdup(NewHeap->rd_rel->relname.data);
165+
strcpy(NewHeapName,NewHeap->rd_rel->relname.data);
166+
157167

158-
/*Need to do this tomake the new heap visible. */
168+
/*Tomake the new heap visible (which is until now empty). */
159169
CommandCounterIncrement();
160170

161171
rebuildheap(OIDNewHeap,OIDOldHeap,OIDOldIndex);
162172

163-
/*Need to do this to makethenew heap visible. */
173+
/*To flush the filled new heap (andthestatistics about it). */
164174
CommandCounterIncrement();
165175

166-
/* can't be found in the SysCache. */
167-
copy_index(OIDOldIndex,OIDNewHeap);/* No contention with the old */
176+
/* Create new index over the tuples of the new heap. */
177+
copy_index(OIDOldIndex,OIDNewHeap);
178+
sprintf(NewIndexName,"temp_%x",OIDOldIndex);
168179

169180
/*
170181
* make this really happen. Flush all the buffers.
182+
* (Believe me, it is necessary ... ended up in a mess without it.)
171183
*/
172184
CommitTransactionCommand();
173185
StartTransactionCommand();
174-
175-
/*
176-
* Questionable bit here. Because the renamerel destroys all trace of the
177-
* pre-existing relation, I'm going to Destroy old, and then rename new
178-
* to old. If this fails, it fails, and you lose your old. Tough - say
179-
* I. Have good backups!
180-
*/
181186

182-
/*
183-
Here lies the bogosity. The RelationNameGetRelation returns a bad
184-
list of TupleDescriptors. Damn. Can't work out why this is.
185-
*/
186-
187-
heap_destroy(oldrelname);/* AAAAAAAAGH!! */
188-
189-
CommandCounterIncrement();
187+
188+
/* Destroy old heap (along with its index) and rename new. */
189+
heap_destroy(oldrelname);
190190

191-
/*
192-
* The Commit flushes all palloced memory, so I have to grab the
193-
* New stuff again. This is annoying, but oh heck!
191+
renamerel(NewHeapName,saveoldrelname);
192+
TypeRename(NewHeapName,saveoldrelname);
193+
194+
renamerel(NewIndexName,saveoldindexname);
195+
196+
/*
197+
* Again flush all the buffers.
194198
*/
195-
/*
196-
renamerel(szNewHeapName.data, oldrelname);
197-
TypeRename(&szNewHeapName, &szOldRelName);
198-
199-
sprintf(NewIndexName.data, "temp_%x", OIDOldIndex);
200-
renamerel(NewIndexName.data, szOldIndexName.data);
201-
*/
202-
NewIndexName=palloc(NAMEDATALEN+1);/* XXX */
203-
sprintf(NewIndexName,"temp_%x",OIDOldIndex);
204-
renamerel(NewIndexName,oldindexname);
199+
CommitTransactionCommand();
200+
StartTransactionCommand();
205201
}
206202

207203
Relation
@@ -362,6 +358,7 @@ rebuildheap(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
362358
pfree(ScanResult);
363359
ReleaseBuffer(LocalBuffer);
364360
}
361+
index_endscan(ScanDesc);
365362

366363
index_close(LocalOldIndex);
367364
heap_close(LocalOldHeap);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp