13
13
*
14
14
*
15
15
* 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 $
17
17
*
18
18
*-------------------------------------------------------------------------
19
19
*/
@@ -213,8 +213,8 @@ static BufferAccessStrategy vac_strategy;
213
213
static List * get_rel_oids (Oid relid , const RangeVar * vacrel ,
214
214
const char * stmttype );
215
215
static 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 );
218
218
static void full_vacuum_rel (Relation onerel , VacuumStmt * vacstmt );
219
219
static void scan_heap (VRelStats * vacrelstats , Relation onerel ,
220
220
VacPageList vacuum_pages , VacPageList fraged_pages );
@@ -268,6 +268,9 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
268
268
* OID to be processed, and vacstmt->relation is ignored. (The non-invalid
269
269
* case is currently only used by autovacuum.)
270
270
*
271
+ * do_toast is passed as FALSE by autovacuum, because it processes TOAST
272
+ * tables separately.
273
+ *
271
274
* for_wraparound is used by autovacuum to let us know when it's forcing
272
275
* a vacuum for wraparound, which should not be auto-cancelled.
273
276
*
@@ -281,7 +284,7 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
281
284
* at transaction commit.
282
285
*/
283
286
void
284
- vacuum (VacuumStmt * vacstmt , Oid relid ,
287
+ vacuum (VacuumStmt * vacstmt , Oid relid , bool do_toast ,
285
288
BufferAccessStrategy bstrategy , bool for_wraparound , bool isTopLevel )
286
289
{
287
290
const char * stmttype = vacstmt -> vacuum ? "VACUUM" : "ANALYZE" ;
@@ -433,7 +436,7 @@ vacuum(VacuumStmt *vacstmt, Oid relid,
433
436
Oid relid = lfirst_oid (cur );
434
437
435
438
if (vacstmt -> vacuum )
436
- vacuum_rel (relid , vacstmt , RELKIND_RELATION , for_wraparound );
439
+ vacuum_rel (relid , vacstmt , do_toast , for_wraparound );
437
440
438
441
if (vacstmt -> analyze )
439
442
{
@@ -975,8 +978,7 @@ vac_truncate_clog(TransactionId frozenXID)
975
978
* At entry and exit, we are not inside a transaction.
976
979
*/
977
980
static 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 )
980
982
{
981
983
LOCKMODE lmode ;
982
984
Relation onerel ;
@@ -1013,8 +1015,8 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind,
1013
1015
* by autovacuum; it's used to avoid cancelling a vacuum that was
1014
1016
* invoked in an emergency.
1015
1017
*
1016
- * Note: this flag remains set until CommitTransaction or
1017
- * AbortTransaction. We don't want to clear it until we reset
1018
+ * Note: these flags remain set until CommitTransaction or
1019
+ * AbortTransaction. We don't want to clear them until we reset
1018
1020
* MyProc->xid/xmin, else OldestXmin might appear to go backwards,
1019
1021
* which is probably Not Good.
1020
1022
*/
@@ -1087,10 +1089,11 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind,
1087
1089
}
1088
1090
1089
1091
/*
1090
- * Check that it's a plain 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 a vacuumable table; we used to do this in get_rel_oids()
1093
+ * but seems safer to check after we've locked the relation.
1092
1094
*/
1093
- if (onerel -> rd_rel -> relkind != expected_relkind )
1095
+ if (onerel -> rd_rel -> relkind != RELKIND_RELATION &&
1096
+ onerel -> rd_rel -> relkind != RELKIND_TOASTVALUE )
1094
1097
{
1095
1098
ereport (WARNING ,
1096
1099
(errmsg ("skipping \"%s\" --- cannot vacuum indexes, views, or special system tables" ,
@@ -1132,9 +1135,13 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind,
1132
1135
LockRelationIdForSession (& onerelid , lmode );
1133
1136
1134
1137
/*
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.
1136
1140
*/
1137
- toast_relid = onerel -> rd_rel -> reltoastrelid ;
1141
+ if (do_toast )
1142
+ toast_relid = onerel -> rd_rel -> reltoastrelid ;
1143
+ else
1144
+ toast_relid = InvalidOid ;
1138
1145
1139
1146
/*
1140
1147
* 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,
1173
1180
* totally unimportant for toast relations.
1174
1181
*/
1175
1182
if (toast_relid != InvalidOid )
1176
- vacuum_rel (toast_relid , vacstmt , RELKIND_TOASTVALUE , for_wraparound );
1183
+ vacuum_rel (toast_relid , vacstmt , false , for_wraparound );
1177
1184
1178
1185
/*
1179
1186
* Now release the session-level lock on the master table.
0 commit comments