aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/cluster.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-09-29 18:05:20 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-09-29 18:05:20 +0000
commitf6a54b8c42f4900e4c159a8119c096c6ffb7377c (patch)
tree5a1766199a7d0cbecaf2c7fcad44c0c724ab12d0 /src/backend/commands/cluster.c
parent34b44c3ba29a3d3b3e33322118a01b76e6fd2cfd (diff)
downloadpostgresql-f6a54b8c42f4900e4c159a8119c096c6ffb7377c.tar.gz
postgresql-f6a54b8c42f4900e4c159a8119c096c6ffb7377c.zip
Disallow CLUSTER using an invalid index (that is, one left over from a failed
CREATE INDEX CONCURRENTLY). Such an index might not have entries for every heap row and thus clustering with it would result in silent data loss. The scenario requires a pretty foolish DBA, but still ...
Diffstat (limited to 'src/backend/commands/cluster.c')
-rw-r--r--src/backend/commands/cluster.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index d781f79b641..736e74882de 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.163 2007/09/10 21:59:37 alvherre Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.164 2007/09/29 18:05:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -422,6 +422,20 @@ check_index_is_clusterable(Relation OldHeap, Oid indexOid, bool recheck)
}
/*
+ * Disallow if index is left over from a failed CREATE INDEX CONCURRENTLY;
+ * it might well not contain entries for every heap row, or might not even
+ * be internally consistent. (But note that we don't check indcheckxmin;
+ * the worst consequence of following broken HOT chains would be that we
+ * might put recently-dead tuples out-of-order in the new table, and there
+ * is little harm in that.)
+ */
+ if (!OldIndex->rd_index->indisvalid)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot cluster on invalid index \"%s\"",
+ RelationGetRelationName(OldIndex))));
+
+ /*
* Disallow clustering system relations. This will definitely NOT work
* for shared relations (we have no way to update pg_class rows in other
* databases), nor for nailed-in-cache relations (the relfilenode values