@ -139,21 +139,9 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
/* We need to find the index that has indisclustered set. */
/* We need to find the index that has indisclustered set. */
foreach ( index , RelationGetIndexList ( rel ) )
foreach ( index , RelationGetIndexList ( rel ) )
{
{
HeapTuple idxtuple ;
Form_pg_index indexForm ;
indexOid = lfirst_oid ( index ) ;
indexOid = lfirst_oid ( index ) ;
idxtuple = SearchSysCache1 ( INDEXRELID ,
if ( get_index_isclustered ( indexOid ) )
ObjectIdGetDatum ( indexOid ) ) ;
if ( ! HeapTupleIsValid ( idxtuple ) )
elog ( ERROR , " cache lookup failed for index %u " , indexOid ) ;
indexForm = ( Form_pg_index ) GETSTRUCT ( idxtuple ) ;
if ( indexForm - > indisclustered )
{
ReleaseSysCache ( idxtuple ) ;
break ;
break ;
}
ReleaseSysCache ( idxtuple ) ;
indexOid = InvalidOid ;
indexOid = InvalidOid ;
}
}
@ -304,9 +292,6 @@ cluster_rel(Oid tableOid, Oid indexOid, int options)
*/
*/
if ( recheck )
if ( recheck )
{
{
HeapTuple tuple ;
Form_pg_index indexForm ;
/* Check that the user still owns the relation */
/* Check that the user still owns the relation */
if ( ! pg_class_ownercheck ( tableOid , GetUserId ( ) ) )
if ( ! pg_class_ownercheck ( tableOid , GetUserId ( ) ) )
{
{
@ -345,22 +330,12 @@ cluster_rel(Oid tableOid, Oid indexOid, int options)
/*
/*
* Check that the index is still the one with indisclustered set .
* Check that the index is still the one with indisclustered set .
*/
*/
tuple = SearchSysCache1 ( INDEXRELID , ObjectIdGetDatum ( indexOid ) ) ;
if ( ! get_index_isclustered ( indexOid ) )
if ( ! HeapTupleIsValid ( tuple ) ) /* probably can't happen */
{
relation_close ( OldHeap , AccessExclusiveLock ) ;
pgstat_progress_end_command ( ) ;
return ;
}
indexForm = ( Form_pg_index ) GETSTRUCT ( tuple ) ;
if ( ! indexForm - > indisclustered )
{
{
ReleaseSysCache ( tuple ) ;
relation_close ( OldHeap , AccessExclusiveLock ) ;
relation_close ( OldHeap , AccessExclusiveLock ) ;
pgstat_progress_end_command ( ) ;
pgstat_progress_end_command ( ) ;
return ;
return ;
}
}
ReleaseSysCache ( tuple ) ;
}
}
}
}
@ -519,20 +494,10 @@ mark_index_clustered(Relation rel, Oid indexOid, bool is_internal)
*/
*/
if ( OidIsValid ( indexOid ) )
if ( OidIsValid ( indexOid ) )
{
{
indexTuple = SearchSysCache1 ( INDEXRELID , ObjectIdGetDatum ( indexOid ) ) ;
if ( get_index_isclustered ( indexOid ) )
if ( ! HeapTupleIsValid ( indexTuple ) )
elog ( ERROR , " cache lookup failed for index %u " , indexOid ) ;
indexForm = ( Form_pg_index ) GETSTRUCT ( indexTuple ) ;
if ( indexForm - > indisclustered )
{
ReleaseSysCache ( indexTuple ) ;
return ;
return ;
}
}
ReleaseSysCache ( indexTuple ) ;
}
/*
/*
* Check each index of the relation and set / clear the bit as needed .
* Check each index of the relation and set / clear the bit as needed .
*/
*/