Modify vacuum() to accept a single relation OID instead of a list (which we

always pass as a single element anyway.)  In passing, fix an outdated comment.
This commit is contained in:
Alvaro Herrera 2008-06-05 15:47:32 +00:00
parent f23b79147b
commit 9319fd89e1
4 changed files with 27 additions and 34 deletions

View File

@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.374 2008/05/15 00:17:39 tgl Exp $
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.375 2008/06/05 15:47:32 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@ -210,7 +210,7 @@ static BufferAccessStrategy vac_strategy;
/* non-export function prototypes */
static List *get_rel_oids(List *relids, const RangeVar *vacrel,
static List *get_rel_oids(Oid relid, const RangeVar *vacrel,
const char *stmttype);
static void vac_truncate_clog(TransactionId frozenXID);
static void vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind,
@ -264,9 +264,9 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
/*
* Primary entry point for VACUUM and ANALYZE commands.
*
* relids is normally NIL; if it is not, then it provides the list of
* relation OIDs to be processed, and vacstmt->relation is ignored.
* (The non-NIL case is currently only used by autovacuum.)
* relid is normally InvalidOid; if it is not, then it provides the relation
* OID to be processed, and vacstmt->relation is ignored. (The non-invalid
* case is currently only used by autovacuum.)
*
* for_wraparound is used by autovacuum to let us know when it's forcing
* a vacuum for wraparound, which should not be auto-cancelled.
@ -276,12 +276,12 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
*
* isTopLevel should be passed down from ProcessUtility.
*
* It is the caller's responsibility that vacstmt, relids, and bstrategy
* It is the caller's responsibility that vacstmt and bstrategy
* (if given) be allocated in a memory context that won't disappear
* at transaction commit.
*/
void
vacuum(VacuumStmt *vacstmt, List *relids,
vacuum(VacuumStmt *vacstmt, Oid relid,
BufferAccessStrategy bstrategy, bool for_wraparound, bool isTopLevel)
{
const char *stmttype = vacstmt->vacuum ? "VACUUM" : "ANALYZE";
@ -351,13 +351,13 @@ vacuum(VacuumStmt *vacstmt, List *relids,
vac_strategy = bstrategy;
/* Remember whether we are processing everything in the DB */
all_rels = (relids == NIL && vacstmt->relation == NULL);
all_rels = (!OidIsValid(relid) && vacstmt->relation == NULL);
/*
* Build list of relations to process, unless caller gave us one. (If we
* build one, we put it in vac_context for safekeeping.)
*/
relations = get_rel_oids(relids, vacstmt->relation, stmttype);
relations = get_rel_oids(relid, vacstmt->relation, stmttype);
/*
* Decide whether we need to start/commit our own transactions.
@ -531,16 +531,19 @@ vacuum(VacuumStmt *vacstmt, List *relids,
* per-relation transactions.
*/
static List *
get_rel_oids(List *relids, const RangeVar *vacrel, const char *stmttype)
get_rel_oids(Oid relid, const RangeVar *vacrel, const char *stmttype)
{
List *oid_list = NIL;
MemoryContext oldcontext;
/* List supplied by VACUUM's caller? */
if (relids)
return relids;
if (vacrel)
/* OID supplied by VACUUM's caller? */
if (OidIsValid(relid))
{
oldcontext = MemoryContextSwitchTo(vac_context);
oid_list = lappend_oid(oid_list, relid);
MemoryContextSwitchTo(oldcontext);
}
else if (vacrel)
{
/* Process a specific relation */
Oid relid;

View File

@ -55,7 +55,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.78 2008/05/15 00:17:40 tgl Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.79 2008/06/05 15:47:32 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@ -1244,8 +1244,7 @@ do_start_worker(void)
* left to do_start_worker.
*
* This routine is also expected to insert an entry into the database list if
* the selected database was previously absent from the list. It returns the
* new database list.
* the selected database was previously absent from the list.
*/
static void
launch_worker(TimestampTz now)
@ -2601,8 +2600,6 @@ autovacuum_do_vac_analyze(Oid relid, bool dovacuum, bool doanalyze,
BufferAccessStrategy bstrategy)
{
VacuumStmt vacstmt;
List *relids;
MemoryContext old_cxt;
/* Set up command parameters --- use a local variable instead of palloc */
MemSet(&vacstmt, 0, sizeof(vacstmt));
@ -2613,21 +2610,13 @@ autovacuum_do_vac_analyze(Oid relid, bool dovacuum, bool doanalyze,
vacstmt.analyze = doanalyze;
vacstmt.freeze_min_age = freeze_min_age;
vacstmt.verbose = false;
vacstmt.relation = NULL; /* not used since we pass a relids list */
vacstmt.relation = NULL; /* not used since we pass a relid */
vacstmt.va_cols = NIL;
/*
* The list must survive transaction boundaries, so make sure we create it
* in a long-lived context
*/
old_cxt = MemoryContextSwitchTo(AutovacMemCxt);
relids = list_make1_oid(relid);
MemoryContextSwitchTo(old_cxt);
/* Let pgstat know what we're doing */
autovac_report_activity(&vacstmt, relid);
vacuum(&vacstmt, relids, bstrategy, for_wraparound, true);
vacuum(&vacstmt, relid, bstrategy, for_wraparound, true);
}
/*

View File

@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.291 2008/03/19 18:38:30 tgl Exp $
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.292 2008/06/05 15:47:32 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@ -1032,7 +1032,8 @@ ProcessUtility(Node *parsetree,
break;
case T_VacuumStmt:
vacuum((VacuumStmt *) parsetree, NIL, NULL, false, isTopLevel);
vacuum((VacuumStmt *) parsetree, InvalidOid, NULL, false,
isTopLevel);
break;
case T_ExplainStmt:

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.76 2008/03/14 17:25:59 alvherre Exp $
* $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.77 2008/06/05 15:47:32 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@ -113,7 +113,7 @@ extern int vacuum_freeze_min_age;
/* in commands/vacuum.c */
extern void vacuum(VacuumStmt *vacstmt, List *relids,
extern void vacuum(VacuumStmt *vacstmt, Oid relid,
BufferAccessStrategy bstrategy, bool for_wraparound, bool isTopLevel);
extern void vac_open_indexes(Relation relation, LOCKMODE lockmode,
int *nindexes, Relation **Irel);