/*
* heap_vacuum_rel - Vacuum a single heap relation.
*
* Parameters:
* onerel: relation to vacuum
* vacuum_full: true for full VACUUM, false for lazy VACUUM
* do_toast: true to process the TOAST table, if any
* vacuum_stat: if not NULL, don't update statistics here
*
* Returns: the number of indexes updated.
*
* NOTE: if do_toast is true, then the caller should be holding an exclusive
* lock on the relation, whereas if do_toast is false, the caller had better
* be holding at least a Share lock on the relation to prevent other
* backends from deleting the visible tuples out from under us.
*
* NOTE: this routine does not start or commit a transaction.
*/
int
heap_vacuum_rel(Relation onerel, bool vacuum_full, bool do_toast,
VacuumStmt *vacuum_stat)
{
int num_index_scans = 0;
PGRUsage ru0;
pg_rusage_init(&ru0);
/* Open all indexes of the relation */
vacuum_set_xid_limits(onerel, vacuum_full, &OldestXmin, &FreezeLimit,
&MultiXactCutoff, &ProcArrayOldestXmin);
vacuum_delay_point();
/*
* Scan the relation, processing all live tuples (removing dead ones). If
* it's a toast table, however, we don't need to process toast live
* tuples for this.
*/
if (!do_toast)
num_index_scans += heap_vacuum_scan(onerel, vacuum_full, vacuum_stat);
/* Open the toast relation and process it too if necessary */
if (do_toast)
{
Relation toastrel;
/*
* Even if we didn't find any indexes, we need to open the toast
* relation to check for toast chains.
*/
toastrel = table_open(toast_relation_id, AccessShareLock);
num_index_scans += toast_vacuum_rel(toastrel, vacuum_full,
vacuum_stat);
table_close(toastrel, AccessShareLock);
}
/*
* Done with indexes. Now truncate off any space at the end of the heap
* that we can.
*/
heap_truncate(onerel);
/* Update the shared free space counter */
VacuumStmt::vacuum_stat->num_index_scans += num_index_scans;
VacuumStmt::vacuum_stat->num_pages = RelationGetNumberOfBlocks(onerel);
VacuumStmt::vacuum_stat->old_live_count = -1; /* not valid */
VacuumStmt::vacuum_stat->new_live_count = -1; /* not valid */
VacuumStmt::vacuum_stat->is_wraparound = false;
VacuumStmt::vacuum_stat->is_full_analyze = false;
/*
* Update the relation's pg_class entry to show the new size.
*
* Note:
评论已关闭