Report index name on CLUSTER failure. Also, suggest ALTER TABLE
authorBruce Momjian <bruce@momjian.us>
Tue, 10 May 2005 13:16:26 +0000 (13:16 +0000)
committerBruce Momjian <bruce@momjian.us>
Tue, 10 May 2005 13:16:26 +0000 (13:16 +0000)
WITHOUT CLUSTER for cluster failure of a single table in a full db
cluster.

src/backend/commands/cluster.c
src/backend/commands/tablecmds.c
src/include/commands/cluster.h

index 9979afaab85632c28ecf331fea4b191404446b52..9e31b4cba59302a5282f4a583c47e73fb4779766 100644 (file)
@@ -292,7 +292,7 @@ cluster_rel(RelToCluster *rvtc, bool recheck)
        OldHeap = heap_open(rvtc->tableOid, AccessExclusiveLock);
 
        /* Check index is valid to cluster on */
-       check_index_is_clusterable(OldHeap, rvtc->indexOid);
+       check_index_is_clusterable(OldHeap, rvtc->indexOid, recheck);
 
        /* rebuild_relation does all the dirty work */
        rebuild_relation(OldHeap, rvtc->indexOid);
@@ -309,7 +309,7 @@ cluster_rel(RelToCluster *rvtc, bool recheck)
  * definition can't change under us.
  */
 void
-check_index_is_clusterable(Relation OldHeap, Oid indexOid)
+check_index_is_clusterable(Relation OldHeap, Oid indexOid, bool recheck)
 {
        Relation        OldIndex;
 
@@ -336,7 +336,9 @@ check_index_is_clusterable(Relation OldHeap, Oid indexOid)
        if (!heap_attisnull(OldIndex->rd_indextuple, Anum_pg_index_indpred))
                ereport(ERROR,
                                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                                errmsg("cannot cluster on partial index")));
+                                errmsg("cannot cluster on partial index \"%s\"",
+                                               RelationGetRelationName(OldIndex))));
+       
        if (!OldIndex->rd_am->amindexnulls)
        {
                AttrNumber      colno;
@@ -354,21 +356,25 @@ check_index_is_clusterable(Relation OldHeap, Oid indexOid)
                        if (!OldHeap->rd_att->attrs[colno - 1]->attnotnull)
                                ereport(ERROR,
                                                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                                                errmsg("cannot cluster when index access method does not handle null values"),
-                                                errhint("You may be able to work around this by marking column \"%s\" NOT NULL.",
-                                 NameStr(OldHeap->rd_att->attrs[colno - 1]->attname))));
+                                                errmsg("cannot cluster on index \"%s\" because access method\n"
+                                                               "does not handle null values",
+                                                         RelationGetRelationName(OldIndex)),
+                                                errhint("You may be able to work around this by marking column \"%s\" NOT NULL%s",
+                                                       NameStr(OldHeap->rd_att->attrs[colno - 1]->attname),
+                                                       recheck ? ",\nor use ALTER TABLE ... SET WITHOUT CLUSTER to remove the cluster\n"
+                                                                       "specification from the table." : ".")));
                }
                else if (colno < 0)
                {
                        /* system column --- okay, always non-null */
                }
                else
-               {
                        /* index expression, lose... */
                        ereport(ERROR,
                                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                                        errmsg("cannot cluster on expressional index when index access method does not handle null values")));
-               }
+                                        errmsg("cannot cluster on expressional index \"%s\" because its index access\n"
+                                                       "method does not handle null values",
+                                               RelationGetRelationName(OldIndex))));
        }
 
        /*
index 8ea8b254286df392e5cfb31f8a50610a10f121b4..b76c28baef6f22b354a53ceacf00754371d9fa92 100644 (file)
@@ -5464,7 +5464,7 @@ ATExecClusterOn(Relation rel, const char *indexName)
                                                indexName, RelationGetRelationName(rel))));
 
        /* Check index is valid to cluster on */
-       check_index_is_clusterable(rel, indexOid);
+       check_index_is_clusterable(rel, indexOid, false);
 
        /* And do the work */
        mark_index_clustered(rel, indexOid);
index 185b324eafb8ee0c85c248a1325892d544c1307e..674fd6795fa57e2c3857b204f30cec2deba5dd87 100644 (file)
@@ -19,7 +19,8 @@
 
 extern void cluster(ClusterStmt *stmt);
 
-extern void check_index_is_clusterable(Relation OldHeap, Oid indexOid);
+extern void check_index_is_clusterable(Relation OldHeap, Oid indexOid,
+                         bool recheck);
 extern void mark_index_clustered(Relation rel, Oid indexOid);
 extern Oid make_new_heap(Oid OIDOldHeap, const char *NewName,
                          Oid NewTableSpace);