|
15 | 15 | *
|
16 | 16 | *
|
17 | 17 | * IDENTIFICATION
|
18 |
| - * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.60 2000/11/16 22:30:18 tgl Exp $ |
| 18 | + * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.61 2001/01/01 21:35:00 tgl Exp $ |
19 | 19 | *
|
20 | 20 | *-------------------------------------------------------------------------
|
21 | 21 | */
|
|
29 | 29 | #include "catalog/pg_index.h"
|
30 | 30 | #include "catalog/pg_proc.h"
|
31 | 31 | #include "commands/cluster.h"
|
| 32 | +#include "commands/command.h" |
32 | 33 | #include "commands/rename.h"
|
33 | 34 | #include "miscadmin.h"
|
34 | 35 | #include "utils/builtins.h"
|
@@ -106,8 +107,7 @@ cluster(char *oldrelname, char *oldindexname)
|
106 | 107 |
|
107 | 108 | OIDNewHeap = copy_heap(OIDOldHeap, NewHeapName);
|
108 | 109 |
|
109 |
| - /* To make the new heap visible (which is until now empty). */ |
110 |
| - CommandCounterIncrement(); |
| 110 | + /* We do not need CommandCounterIncrement() because copy_heap did it. */ |
111 | 111 |
|
112 | 112 | /*
|
113 | 113 | * Copy the heap data into the new table in the desired order.
|
@@ -150,16 +150,27 @@ copy_heap(Oid OIDOldHeap, char *NewName)
|
150 | 150 |
|
151 | 151 | /*
|
152 | 152 | * Need to make a copy of the tuple descriptor,
|
153 |
| - * heap_create_with_catalog modifies it. |
| 153 | + * since heap_create_with_catalog modifies it. |
154 | 154 | */
|
155 | 155 | tupdesc = CreateTupleDescCopy(OldHeapDesc);
|
156 | 156 |
|
157 | 157 | OIDNewHeap = heap_create_with_catalog(NewName, tupdesc,
|
158 | 158 | RELKIND_RELATION, false,
|
159 | 159 | allowSystemTableMods);
|
160 | 160 |
|
161 |
| - if (!OidIsValid(OIDNewHeap)) |
162 |
| - elog(ERROR, "copy_heap: cannot create temporary heap relation"); |
| 161 | + /* |
| 162 | + * Advance command counter so that the newly-created |
| 163 | + * relation's catalog tuples will be visible to heap_open. |
| 164 | + */ |
| 165 | + CommandCounterIncrement(); |
| 166 | + |
| 167 | + /* |
| 168 | + * If necessary, create a TOAST table for the new relation. |
| 169 | + * Note that AlterTableCreateToastTable ends with |
| 170 | + * CommandCounterIncrement(), so that the TOAST table will |
| 171 | + * be visible for insertion. |
| 172 | + */ |
| 173 | + AlterTableCreateToastTable(NewName, true); |
163 | 174 |
|
164 | 175 | heap_close(OldHeap, NoLock);
|
165 | 176 |
|
|
0 commit comments