aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/cluster.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2011-01-20 22:44:10 -0500
committerRobert Haas <rhaas@postgresql.org>2011-01-20 22:44:10 -0500
commit8ceb24568054232696dddc1166a8563bc78c900a (patch)
treea9921588da9066933ddf723e79345471909de5e5 /src/backend/commands/cluster.c
parent14b9f69cb2077c65a09df78d167d45c35b1d7973 (diff)
downloadpostgresql-8ceb24568054232696dddc1166a8563bc78c900a.tar.gz
postgresql-8ceb24568054232696dddc1166a8563bc78c900a.zip
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.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index 19c3cf9674c..59a439413e1 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -565,7 +565,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);
}
@@ -1362,10 +1362,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 */
@@ -1395,7 +1397,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;