|
11 | 11 | *
|
12 | 12 | *
|
13 | 13 | * IDENTIFICATION
|
14 |
| - * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.177 2008/06/19 00:46:04 alvherre Exp $ |
| 14 | + * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.178 2008/10/14 17:19:50 alvherre Exp $ |
15 | 15 | *
|
16 | 16 | *-------------------------------------------------------------------------
|
17 | 17 | */
|
|
29 | 29 | #include"catalog/index.h"
|
30 | 30 | #include"catalog/indexing.h"
|
31 | 31 | #include"catalog/namespace.h"
|
| 32 | +#include"catalog/pg_namespace.h" |
32 | 33 | #include"catalog/toasting.h"
|
33 | 34 | #include"commands/cluster.h"
|
34 | 35 | #include"commands/tablecmds.h"
|
@@ -568,6 +569,7 @@ rebuild_relation(Relation OldHeap, Oid indexOid)
|
568 | 569 | charNewHeapName[NAMEDATALEN];
|
569 | 570 | TransactionIdfrozenXid;
|
570 | 571 | ObjectAddressobject;
|
| 572 | +Relationnewrel; |
571 | 573 |
|
572 | 574 | /* Mark the correct index as clustered */
|
573 | 575 | mark_index_clustered(OldHeap,indexOid);
|
@@ -622,6 +624,35 @@ rebuild_relation(Relation OldHeap, Oid indexOid)
|
622 | 624 | * because reindex_relation does it.
|
623 | 625 | */
|
624 | 626 | reindex_relation(tableOid, false);
|
| 627 | + |
| 628 | +/* |
| 629 | + * At this point, everything is kosher except that the toast table's name |
| 630 | + * corresponds to the temporary table. The name is irrelevant to |
| 631 | + * the backend because it's referenced by OID, but users looking at the |
| 632 | + * catalogs could be confused. Rename it to prevent this problem. |
| 633 | + * |
| 634 | + * Note no lock required on the relation, because we already hold an |
| 635 | + * exclusive lock on it. |
| 636 | + */ |
| 637 | +newrel=heap_open(tableOid,NoLock); |
| 638 | +if (OidIsValid(newrel->rd_rel->reltoastrelid)) |
| 639 | +{ |
| 640 | +charNewToastName[NAMEDATALEN]; |
| 641 | +Relationtoastrel; |
| 642 | + |
| 643 | +/* rename the toast table ... */ |
| 644 | +snprintf(NewToastName,NAMEDATALEN,"pg_toast_%u",tableOid); |
| 645 | +RenameRelationInternal(newrel->rd_rel->reltoastrelid,NewToastName, |
| 646 | +PG_TOAST_NAMESPACE); |
| 647 | + |
| 648 | +/* ... and its index too */ |
| 649 | +toastrel=relation_open(newrel->rd_rel->reltoastrelid,AccessShareLock); |
| 650 | +snprintf(NewToastName,NAMEDATALEN,"pg_toast_%u_index",tableOid); |
| 651 | +RenameRelationInternal(toastrel->rd_rel->reltoastidxid,NewToastName, |
| 652 | +PG_TOAST_NAMESPACE); |
| 653 | +relation_close(toastrel,AccessShareLock); |
| 654 | +} |
| 655 | +relation_close(newrel,NoLock); |
625 | 656 | }
|
626 | 657 |
|
627 | 658 | /*
|
|