|
14 | 14 | *
|
15 | 15 | *
|
16 | 16 | * 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 $ |
18 | 18 | *
|
19 | 19 | *-------------------------------------------------------------------------
|
20 | 20 | */
|
@@ -105,9 +105,18 @@ cluster(char oldrelname[], char oldindexname[])
|
105 | 105 | Relation OldHeap, OldIndex;
|
106 | 106 | Relation NewHeap;
|
107 | 107 |
|
108 |
| - char *NewIndexName; |
109 |
| - char *szNewHeapName; |
110 |
| - |
| 108 | + char NewIndexName[NAMEDATALEN+1]; |
| 109 | + char NewHeapName[NAMEDATALEN+1]; |
| 110 | + char saveoldrelname[NAMEDATALEN+1]; |
| 111 | + char saveoldindexname[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 | + |
111 | 120 | /*
|
112 | 121 | *
|
113 | 122 | * I'm going to force all checking back into the commands.c function.
|
@@ -153,55 +162,42 @@ cluster(char oldrelname[], char oldindexname[])
|
153 | 162 | */
|
154 | 163 | NewHeap = copy_heap(OIDOldHeap);
|
155 | 164 | OIDNewHeap = NewHeap->rd_id;
|
156 |
| - szNewHeapName = pstrdup(NewHeap->rd_rel->relname.data); |
| 165 | + strcpy(NewHeapName,NewHeap->rd_rel->relname.data); |
| 166 | + |
157 | 167 |
|
158 |
| - /* Need to do this to make the new heap visible. */ |
| 168 | + /* To make the new heap visible (which is until now empty). */ |
159 | 169 | CommandCounterIncrement();
|
160 | 170 |
|
161 | 171 | rebuildheap(OIDNewHeap, OIDOldHeap, OIDOldIndex);
|
162 | 172 |
|
163 |
| - /* Need to do this to make the new heap visible. */ |
| 173 | + /* To flush the filled new heap (and the statistics about it). */ |
164 | 174 | CommandCounterIncrement();
|
165 | 175 |
|
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); |
168 | 179 |
|
169 | 180 | /*
|
170 | 181 | * make this really happen. Flush all the buffers.
|
| 182 | + * (Believe me, it is necessary ... ended up in a mess without it.) |
171 | 183 | */
|
172 | 184 | CommitTransactionCommand();
|
173 | 185 | 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 |
| - */ |
181 | 186 |
|
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); |
190 | 190 |
|
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. |
194 | 198 | */
|
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(); |
205 | 201 | }
|
206 | 202 |
|
207 | 203 | Relation
|
@@ -362,6 +358,7 @@ rebuildheap(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
|
362 | 358 | pfree(ScanResult);
|
363 | 359 | ReleaseBuffer(LocalBuffer);
|
364 | 360 | }
|
| 361 | + index_endscan(ScanDesc); |
365 | 362 |
|
366 | 363 | index_close(LocalOldIndex);
|
367 | 364 | heap_close(LocalOldHeap);
|
|
0 commit comments