1313 *
1414 *
1515 * IDENTIFICATION
16- * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.375 2008/06/05 15:47:32 alvherre Exp $
16+ * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.376 2008/08/13 00:07:50 alvherre Exp $
1717 *
1818 *-------------------------------------------------------------------------
1919 */
@@ -213,8 +213,8 @@ static BufferAccessStrategy vac_strategy;
213213static List * get_rel_oids (Oid relid ,const RangeVar * vacrel ,
214214const char * stmttype );
215215static void vac_truncate_clog (TransactionId frozenXID );
216- static void vacuum_rel (Oid relid ,VacuumStmt * vacstmt ,char expected_relkind ,
217- bool for_wraparound );
216+ static void vacuum_rel (Oid relid ,VacuumStmt * vacstmt ,bool do_toast ,
217+ bool for_wraparound );
218218static void full_vacuum_rel (Relation onerel ,VacuumStmt * vacstmt );
219219static void scan_heap (VRelStats * vacrelstats ,Relation onerel ,
220220VacPageList vacuum_pages ,VacPageList fraged_pages );
@@ -268,6 +268,9 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
268268 * OID to be processed, and vacstmt->relation is ignored. (The non-invalid
269269 * case is currently only used by autovacuum.)
270270 *
271+ * do_toast is passed as FALSE by autovacuum, because it processes TOAST
272+ * tables separately.
273+ *
271274 * for_wraparound is used by autovacuum to let us know when it's forcing
272275 * a vacuum for wraparound, which should not be auto-cancelled.
273276 *
@@ -281,7 +284,7 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
281284 * at transaction commit.
282285 */
283286void
284- vacuum (VacuumStmt * vacstmt ,Oid relid ,
287+ vacuum (VacuumStmt * vacstmt ,Oid relid ,bool do_toast ,
285288BufferAccessStrategy bstrategy ,bool for_wraparound ,bool isTopLevel )
286289{
287290const char * stmttype = vacstmt -> vacuum ?"VACUUM" :"ANALYZE" ;
@@ -433,7 +436,7 @@ vacuum(VacuumStmt *vacstmt, Oid relid,
433436Oid relid = lfirst_oid (cur );
434437
435438if (vacstmt -> vacuum )
436- vacuum_rel (relid ,vacstmt ,RELKIND_RELATION ,for_wraparound );
439+ vacuum_rel (relid ,vacstmt ,do_toast ,for_wraparound );
437440
438441if (vacstmt -> analyze )
439442{
@@ -975,8 +978,7 @@ vac_truncate_clog(TransactionId frozenXID)
975978 *At entry and exit, we are not inside a transaction.
976979 */
977980static void
978- vacuum_rel (Oid relid ,VacuumStmt * vacstmt ,char expected_relkind ,
979- bool for_wraparound )
981+ vacuum_rel (Oid relid ,VacuumStmt * vacstmt ,bool do_toast ,bool for_wraparound )
980982{
981983LOCKMODE lmode ;
982984Relation onerel ;
@@ -1013,8 +1015,8 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind,
10131015 * by autovacuum; it's used to avoid cancelling a vacuum that was
10141016 * invoked in an emergency.
10151017 *
1016- * Note:this flag remains set until CommitTransaction or
1017- * AbortTransaction. We don't want to clearit until we reset
1018+ * Note:these flags remain set until CommitTransaction or
1019+ * AbortTransaction. We don't want to clearthem until we reset
10181020 * MyProc->xid/xmin, else OldestXmin might appear to go backwards,
10191021 * which is probably Not Good.
10201022 */
@@ -1087,10 +1089,11 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind,
10871089}
10881090
10891091/*
1090- * Check that it's aplain table; we used to do this in get_rel_oids() but
1091- * seems safer to check after we've locked the relation.
1092+ * Check that it's avacuumable table; we used to do this in get_rel_oids()
1093+ *but seems safer to check after we've locked the relation.
10921094 */
1093- if (onerel -> rd_rel -> relkind != expected_relkind )
1095+ if (onerel -> rd_rel -> relkind != RELKIND_RELATION &&
1096+ onerel -> rd_rel -> relkind != RELKIND_TOASTVALUE )
10941097{
10951098ereport (WARNING ,
10961099(errmsg ("skipping \"%s\" --- cannot vacuum indexes, views, or special system tables" ,
@@ -1132,9 +1135,13 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind,
11321135LockRelationIdForSession (& onerelid ,lmode );
11331136
11341137/*
1135- * Remember the relation's TOAST relation for later
1138+ * Remember the relation's TOAST relation for later, if the caller asked
1139+ * us to process it.
11361140 */
1137- toast_relid = onerel -> rd_rel -> reltoastrelid ;
1141+ if (do_toast )
1142+ toast_relid = onerel -> rd_rel -> reltoastrelid ;
1143+ else
1144+ toast_relid = InvalidOid ;
11381145
11391146/*
11401147 * Switch to the table owner's userid, so that any index functions are
@@ -1173,7 +1180,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind,
11731180 * totally unimportant for toast relations.
11741181 */
11751182if (toast_relid != InvalidOid )
1176- vacuum_rel (toast_relid ,vacstmt ,RELKIND_TOASTVALUE ,for_wraparound );
1183+ vacuum_rel (toast_relid ,vacstmt ,false ,for_wraparound );
11771184
11781185/*
11791186 * Now release the session-level lock on the master table.