Commit a4dde3bf authored by Bruce Momjian's avatar Bruce Momjian

Report index name on CLUSTER failure. Also, suggest ALTER TABLE

WITHOUT CLUSTER for cluster failure of a single table in a full db
cluster.
parent dc5ebcfc
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.137 2005/05/06 17:24:53 tgl Exp $ * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.138 2005/05/10 13:16:26 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -292,7 +292,7 @@ cluster_rel(RelToCluster *rvtc, bool recheck) ...@@ -292,7 +292,7 @@ cluster_rel(RelToCluster *rvtc, bool recheck)
OldHeap = heap_open(rvtc->tableOid, AccessExclusiveLock); OldHeap = heap_open(rvtc->tableOid, AccessExclusiveLock);
/* Check index is valid to cluster on */ /* 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 does all the dirty work */
rebuild_relation(OldHeap, rvtc->indexOid); rebuild_relation(OldHeap, rvtc->indexOid);
...@@ -309,7 +309,7 @@ cluster_rel(RelToCluster *rvtc, bool recheck) ...@@ -309,7 +309,7 @@ cluster_rel(RelToCluster *rvtc, bool recheck)
* definition can't change under us. * definition can't change under us.
*/ */
void void
check_index_is_clusterable(Relation OldHeap, Oid indexOid) check_index_is_clusterable(Relation OldHeap, Oid indexOid, bool recheck)
{ {
Relation OldIndex; Relation OldIndex;
...@@ -336,7 +336,9 @@ check_index_is_clusterable(Relation OldHeap, Oid indexOid) ...@@ -336,7 +336,9 @@ check_index_is_clusterable(Relation OldHeap, Oid indexOid)
if (!heap_attisnull(OldIndex->rd_indextuple, Anum_pg_index_indpred)) if (!heap_attisnull(OldIndex->rd_indextuple, Anum_pg_index_indpred))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (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) if (!OldIndex->rd_am->amindexnulls)
{ {
AttrNumber colno; AttrNumber colno;
...@@ -354,21 +356,25 @@ check_index_is_clusterable(Relation OldHeap, Oid indexOid) ...@@ -354,21 +356,25 @@ check_index_is_clusterable(Relation OldHeap, Oid indexOid)
if (!OldHeap->rd_att->attrs[colno - 1]->attnotnull) if (!OldHeap->rd_att->attrs[colno - 1]->attnotnull)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot cluster when index access method does not handle null values"), errmsg("cannot cluster on index \"%s\" because access method\n"
errhint("You may be able to work around this by marking column \"%s\" NOT NULL.", "does not handle null values",
NameStr(OldHeap->rd_att->attrs[colno - 1]->attname)))); 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) else if (colno < 0)
{ {
/* system column --- okay, always non-null */ /* system column --- okay, always non-null */
} }
else else
{
/* index expression, lose... */ /* index expression, lose... */
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (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))));
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.156 2005/05/06 17:24:53 tgl Exp $ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.157 2005/05/10 13:16:26 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -5464,7 +5464,7 @@ ATExecClusterOn(Relation rel, const char *indexName) ...@@ -5464,7 +5464,7 @@ ATExecClusterOn(Relation rel, const char *indexName)
indexName, RelationGetRelationName(rel)))); indexName, RelationGetRelationName(rel))));
/* Check index is valid to cluster on */ /* Check index is valid to cluster on */
check_index_is_clusterable(rel, indexOid); check_index_is_clusterable(rel, indexOid, false);
/* And do the work */ /* And do the work */
mark_index_clustered(rel, indexOid); mark_index_clustered(rel, indexOid);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994-5, Regents of the University of California * Portions Copyright (c) 1994-5, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/commands/cluster.h,v 1.27 2004/12/31 22:03:28 pgsql Exp $ * $PostgreSQL: pgsql/src/include/commands/cluster.h,v 1.28 2005/05/10 13:16:26 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
extern void cluster(ClusterStmt *stmt); 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 void mark_index_clustered(Relation rel, Oid indexOid);
extern Oid make_new_heap(Oid OIDOldHeap, const char *NewName, extern Oid make_new_heap(Oid OIDOldHeap, const char *NewName,
Oid NewTableSpace); Oid NewTableSpace);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment