@ -67,10 +67,13 @@ typedef struct
} RelToCluster ;
} RelToCluster ;
static void rebuild_relation ( Relation OldHeap , Oid indexOid , bool verbose ) ;
static void rebuild_relation ( Relation OldHeap , Oid indexOid ,
bool isTopLevel , bool verbose ) ;
static void copy_table_data ( Oid OIDNewHeap , Oid OIDOldHeap , Oid OIDOldIndex ,
static void copy_table_data ( Oid OIDNewHeap , Oid OIDOldHeap , Oid OIDOldIndex ,
bool verbose , bool * pSwapToastByContent ,
bool isTopLevel , bool verbose ,
TransactionId * pFreezeXid , MultiXactId * pCutoffMulti ) ;
bool * pSwapToastByContent ,
TransactionId * pFreezeXid ,
MultiXactId * pCutoffMulti ) ;
static List * get_tables_to_cluster ( MemoryContext cluster_context ) ;
static List * get_tables_to_cluster ( MemoryContext cluster_context ) ;
@ -170,7 +173,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
table_close ( rel , NoLock ) ;
table_close ( rel , NoLock ) ;
/* Do the job. */
/* Do the job. */
cluster_rel ( tableOid , indexOid , stmt - > options ) ;
cluster_rel ( tableOid , indexOid , stmt - > options , isTopLevel ) ;
}
}
else
else
{
{
@ -219,7 +222,8 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
PushActiveSnapshot ( GetTransactionSnapshot ( ) ) ;
PushActiveSnapshot ( GetTransactionSnapshot ( ) ) ;
/* Do the job. */
/* Do the job. */
cluster_rel ( rvtc - > tableOid , rvtc - > indexOid ,
cluster_rel ( rvtc - > tableOid , rvtc - > indexOid ,
stmt - > options | CLUOPT_RECHECK ) ;
stmt - > options | CLUOPT_RECHECK ,
isTopLevel ) ;
PopActiveSnapshot ( ) ;
PopActiveSnapshot ( ) ;
CommitTransactionCommand ( ) ;
CommitTransactionCommand ( ) ;
}
}
@ -250,7 +254,7 @@ cluster(ClusterStmt *stmt, bool isTopLevel)
* and error messages should refer to the operation as VACUUM not CLUSTER .
* and error messages should refer to the operation as VACUUM not CLUSTER .
*/
*/
void
void
cluster_rel ( Oid tableOid , Oid indexOid , int options )
cluster_rel ( Oid tableOid , Oid indexOid , int options , bool isTopLevel )
{
{
Relation OldHeap ;
Relation OldHeap ;
bool verbose = ( ( options & CLUOPT_VERBOSE ) ! = 0 ) ;
bool verbose = ( ( options & CLUOPT_VERBOSE ) ! = 0 ) ;
@ -400,7 +404,7 @@ cluster_rel(Oid tableOid, Oid indexOid, int options)
TransferPredicateLocksToHeapRelation ( OldHeap ) ;
TransferPredicateLocksToHeapRelation ( OldHeap ) ;
/* rebuild_relation does all the dirty work */
/* rebuild_relation does all the dirty work */
rebuild_relation ( OldHeap , indexOid , verbose ) ;
rebuild_relation ( OldHeap , indexOid , isTopLevel , verbose ) ;
/* NB: rebuild_relation does table_close() on OldHeap */
/* NB: rebuild_relation does table_close() on OldHeap */
@ -545,11 +549,12 @@ mark_index_clustered(Relation rel, Oid indexOid, bool is_internal)
*
*
* OldHeap : table to rebuild - - - must be opened and exclusive - locked !
* OldHeap : table to rebuild - - - must be opened and exclusive - locked !
* indexOid : index to cluster by , or InvalidOid to rewrite in physical order .
* indexOid : index to cluster by , or InvalidOid to rewrite in physical order .
* isTopLevel : should be passed down from ProcessUtility .
*
*
* NB : this routine closes OldHeap at the right time ; caller should not .
* NB : this routine closes OldHeap at the right time ; caller should not .
*/
*/
static void
static void
rebuild_relation ( Relation OldHeap , Oid indexOid , bool verbose )
rebuild_relation ( Relation OldHeap , Oid indexOid , bool isTopLevel , bool verbose )
{
{
Oid tableOid = RelationGetRelid ( OldHeap ) ;
Oid tableOid = RelationGetRelid ( OldHeap ) ;
Oid tableSpace = OldHeap - > rd_rel - > reltablespace ;
Oid tableSpace = OldHeap - > rd_rel - > reltablespace ;
@ -577,7 +582,7 @@ rebuild_relation(Relation OldHeap, Oid indexOid, bool verbose)
AccessExclusiveLock ) ;
AccessExclusiveLock ) ;
/* Copy the heap data into the new table in the desired order */
/* Copy the heap data into the new table in the desired order */
copy_table_data ( OIDNewHeap , tableOid , indexOid , verbose ,
copy_table_data ( OIDNewHeap , tableOid , indexOid , isTopLevel , verbose ,
& swap_toast_by_content , & frozenXid , & cutoffMulti ) ;
& swap_toast_by_content , & frozenXid , & cutoffMulti ) ;
/*
/*
@ -728,7 +733,8 @@ make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, char relpersistence,
* * pCutoffMulti receives the MultiXactId used as a cutoff point .
* * pCutoffMulti receives the MultiXactId used as a cutoff point .
*/
*/
static void
static void
copy_table_data ( Oid OIDNewHeap , Oid OIDOldHeap , Oid OIDOldIndex , bool verbose ,
copy_table_data ( Oid OIDNewHeap , Oid OIDOldHeap , Oid OIDOldIndex ,
bool isTopLevel , bool verbose ,
bool * pSwapToastByContent , TransactionId * pFreezeXid ,
bool * pSwapToastByContent , TransactionId * pFreezeXid ,
MultiXactId * pCutoffMulti )
MultiXactId * pCutoffMulti )
{
{
@ -826,7 +832,7 @@ copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
* Since we ' re going to rewrite the whole table anyway , there ' s no reason
* Since we ' re going to rewrite the whole table anyway , there ' s no reason
* not to be aggressive about this .
* not to be aggressive about this .
*/
*/
vacuum_set_xid_limits ( OldHeap , 0 , 0 , 0 , 0 ,
vacuum_set_xid_limits ( OldHeap , 0 , 0 , 0 , 0 , isTopLevel ,
& OldestXmin , & FreezeXid , NULL , & MultiXactCutoff ,
& OldestXmin , & FreezeXid , NULL , & MultiXactCutoff ,
NULL ) ;
NULL ) ;