1111 *
1212 *
1313 * IDENTIFICATION
14- * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.137 2005/05/06 17:24:53 tgl Exp $
14+ * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.138 2005/05/10 13:16:26 momjian Exp $
1515 *
1616 *-------------------------------------------------------------------------
1717 */
@@ -292,7 +292,7 @@ cluster_rel(RelToCluster *rvtc, bool recheck)
292292 OldHeap = heap_open (rvtc -> tableOid , AccessExclusiveLock );
293293
294294 /* Check index is valid to cluster on */
295- check_index_is_clusterable (OldHeap , rvtc -> indexOid );
295+ check_index_is_clusterable (OldHeap , rvtc -> indexOid , recheck );
296296
297297 /* rebuild_relation does all the dirty work */
298298 rebuild_relation (OldHeap , rvtc -> indexOid );
@@ -309,7 +309,7 @@ cluster_rel(RelToCluster *rvtc, bool recheck)
309309 * definition can't change under us.
310310 */
311311void
312- check_index_is_clusterable (Relation OldHeap , Oid indexOid )
312+ check_index_is_clusterable (Relation OldHeap , Oid indexOid , bool recheck )
313313{
314314 Relation OldIndex ;
315315
@@ -336,7 +336,9 @@ check_index_is_clusterable(Relation OldHeap, Oid indexOid)
336336 if (!heap_attisnull (OldIndex -> rd_indextuple , Anum_pg_index_indpred ))
337337 ereport (ERROR ,
338338 (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
339- errmsg ("cannot cluster on partial index" )));
339+ errmsg ("cannot cluster on partial index \"%s\"" ,
340+ RelationGetRelationName (OldIndex ))));
341+
340342 if (!OldIndex -> rd_am -> amindexnulls )
341343 {
342344 AttrNumber colno ;
@@ -354,21 +356,25 @@ check_index_is_clusterable(Relation OldHeap, Oid indexOid)
354356 if (!OldHeap -> rd_att -> attrs [colno - 1 ]-> attnotnull )
355357 ereport (ERROR ,
356358 (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
357- errmsg ("cannot cluster when index access method does not handle null values" ),
358- errhint ("You may be able to work around this by marking column \"%s\" NOT NULL." ,
359- NameStr (OldHeap -> rd_att -> attrs [colno - 1 ]-> attname ))));
359+ errmsg ("cannot cluster on index \"%s\" because access method\n"
360+ "does not handle null values" ,
361+ RelationGetRelationName (OldIndex )),
362+ errhint ("You may be able to work around this by marking column \"%s\" NOT NULL%s" ,
363+ NameStr (OldHeap -> rd_att -> attrs [colno - 1 ]-> attname ),
364+ recheck ? ",\nor use ALTER TABLE ... SET WITHOUT CLUSTER to remove the cluster\n"
365+ "specification from the table." : "." )));
360366 }
361367 else if (colno < 0 )
362368 {
363369 /* system column --- okay, always non-null */
364370 }
365371 else
366- {
367372 /* index expression, lose... */
368373 ereport (ERROR ,
369374 (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
370- errmsg ("cannot cluster on expressional index when index access method does not handle null values" )));
371- }
375+ errmsg ("cannot cluster on expressional index \"%s\" because its index access\n"
376+ "method does not handle null values" ,
377+ RelationGetRelationName (OldIndex ))));
372378 }
373379
374380 /*
0 commit comments