diff options
| author | Robert Haas <rhaas@postgresql.org> | 2011-01-20 22:44:10 -0500 |
|---|---|---|
| committer | Robert Haas <rhaas@postgresql.org> | 2011-01-20 22:48:29 -0500 |
| commit | 39b5e5f3370258cae843e8cc83eccd59ddb532dd (patch) | |
| tree | 54a4bcee6167e5051a32bd634e9da668ca760c8a /src/backend/commands/cluster.c | |
| parent | ba3afc88d2b81fc609cda8504ee7b54c54b379d7 (diff) | |
Make ALTER TABLE revalidate uniqueness and exclusion constraints.
Failure to do so can lead to constraint violations. This was broken by
commit 1ddc2703a936d03953657f43345460b9242bbed1 on 2010-02-07, so
back-patch to 9.0.
Noah Misch. Regression test by me.
Diffstat (limited to 'src/backend/commands/cluster.c')
| -rw-r--r-- | src/backend/commands/cluster.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 7a1b8e885be..61020dcbe74 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -607,7 +607,7 @@ rebuild_relation(Relation OldHeap, Oid indexOid, * rebuild the target's indexes and throw away the transient table. */ finish_heap_swap(tableOid, OIDNewHeap, is_system_catalog, - swap_toast_by_content, frozenXid); + swap_toast_by_content, false, frozenXid); } @@ -1326,10 +1326,12 @@ void finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, bool is_system_catalog, bool swap_toast_by_content, + bool check_constraints, TransactionId frozenXid) { ObjectAddress object; Oid mapped_tables[4]; + int reindex_flags; int i; /* Zero out possible results from swapped_relation_files */ @@ -1359,7 +1361,10 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, * so no chance to reclaim disk space before commit. We do not need a * final CommandCounterIncrement() because reindex_relation does it. */ - reindex_relation(OIDOldHeap, false, true); + reindex_flags = REINDEX_SUPPRESS_INDEX_USE; + if (check_constraints) + reindex_flags |= REINDEX_CHECK_CONSTRAINTS; + reindex_relation(OIDOldHeap, false, reindex_flags); /* Destroy new heap with old filenode */ object.classId = RelationRelationId; |
