mirror of
https://github.com/postgres/postgres.git
synced 2025-07-21 16:02:15 +03:00
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:
@ -13,7 +13,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 */
|
/* 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);
|
const char *stmttype);
|
||||||
static void vac_truncate_clog(TransactionId frozenXID);
|
static void vac_truncate_clog(TransactionId frozenXID);
|
||||||
static void vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind,
|
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.
|
* Primary entry point for VACUUM and ANALYZE commands.
|
||||||
*
|
*
|
||||||
* relids is normally NIL; if it is not, then it provides the list of
|
* relid is normally InvalidOid; if it is not, then it provides the relation
|
||||||
* relation OIDs to be processed, and vacstmt->relation is ignored.
|
* OID to be processed, and vacstmt->relation is ignored. (The non-invalid
|
||||||
* (The non-NIL case is currently only used by autovacuum.)
|
* case is currently only used by autovacuum.)
|
||||||
*
|
*
|
||||||
* for_wraparound is used by autovacuum to let us know when it's forcing
|
* for_wraparound is used by autovacuum to let us know when it's forcing
|
||||||
* a vacuum for wraparound, which should not be auto-cancelled.
|
* 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.
|
* 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
|
* (if given) be allocated in a memory context that won't disappear
|
||||||
* at transaction commit.
|
* at transaction commit.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
vacuum(VacuumStmt *vacstmt, List *relids,
|
vacuum(VacuumStmt *vacstmt, Oid relid,
|
||||||
BufferAccessStrategy bstrategy, bool for_wraparound, bool isTopLevel)
|
BufferAccessStrategy bstrategy, bool for_wraparound, bool isTopLevel)
|
||||||
{
|
{
|
||||||
const char *stmttype = vacstmt->vacuum ? "VACUUM" : "ANALYZE";
|
const char *stmttype = vacstmt->vacuum ? "VACUUM" : "ANALYZE";
|
||||||
@ -351,13 +351,13 @@ vacuum(VacuumStmt *vacstmt, List *relids,
|
|||||||
vac_strategy = bstrategy;
|
vac_strategy = bstrategy;
|
||||||
|
|
||||||
/* Remember whether we are processing everything in the DB */
|
/* 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 list of relations to process, unless caller gave us one. (If we
|
||||||
* build one, we put it in vac_context for safekeeping.)
|
* 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.
|
* Decide whether we need to start/commit our own transactions.
|
||||||
@ -531,16 +531,19 @@ vacuum(VacuumStmt *vacstmt, List *relids,
|
|||||||
* per-relation transactions.
|
* per-relation transactions.
|
||||||
*/
|
*/
|
||||||
static List *
|
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;
|
List *oid_list = NIL;
|
||||||
MemoryContext oldcontext;
|
MemoryContext oldcontext;
|
||||||
|
|
||||||
/* List supplied by VACUUM's caller? */
|
/* OID supplied by VACUUM's caller? */
|
||||||
if (relids)
|
if (OidIsValid(relid))
|
||||||
return relids;
|
{
|
||||||
|
oldcontext = MemoryContextSwitchTo(vac_context);
|
||||||
if (vacrel)
|
oid_list = lappend_oid(oid_list, relid);
|
||||||
|
MemoryContextSwitchTo(oldcontext);
|
||||||
|
}
|
||||||
|
else if (vacrel)
|
||||||
{
|
{
|
||||||
/* Process a specific relation */
|
/* Process a specific relation */
|
||||||
Oid relid;
|
Oid relid;
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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.
|
* left to do_start_worker.
|
||||||
*
|
*
|
||||||
* This routine is also expected to insert an entry into the database list if
|
* 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
|
* the selected database was previously absent from the list.
|
||||||
* new database list.
|
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
launch_worker(TimestampTz now)
|
launch_worker(TimestampTz now)
|
||||||
@ -2601,8 +2600,6 @@ autovacuum_do_vac_analyze(Oid relid, bool dovacuum, bool doanalyze,
|
|||||||
BufferAccessStrategy bstrategy)
|
BufferAccessStrategy bstrategy)
|
||||||
{
|
{
|
||||||
VacuumStmt vacstmt;
|
VacuumStmt vacstmt;
|
||||||
List *relids;
|
|
||||||
MemoryContext old_cxt;
|
|
||||||
|
|
||||||
/* Set up command parameters --- use a local variable instead of palloc */
|
/* Set up command parameters --- use a local variable instead of palloc */
|
||||||
MemSet(&vacstmt, 0, sizeof(vacstmt));
|
MemSet(&vacstmt, 0, sizeof(vacstmt));
|
||||||
@ -2613,21 +2610,13 @@ autovacuum_do_vac_analyze(Oid relid, bool dovacuum, bool doanalyze,
|
|||||||
vacstmt.analyze = doanalyze;
|
vacstmt.analyze = doanalyze;
|
||||||
vacstmt.freeze_min_age = freeze_min_age;
|
vacstmt.freeze_min_age = freeze_min_age;
|
||||||
vacstmt.verbose = false;
|
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;
|
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 */
|
/* Let pgstat know what we're doing */
|
||||||
autovac_report_activity(&vacstmt, relid);
|
autovac_report_activity(&vacstmt, relid);
|
||||||
|
|
||||||
vacuum(&vacstmt, relids, bstrategy, for_wraparound, true);
|
vacuum(&vacstmt, relid, bstrategy, for_wraparound, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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;
|
break;
|
||||||
|
|
||||||
case T_VacuumStmt:
|
case T_VacuumStmt:
|
||||||
vacuum((VacuumStmt *) parsetree, NIL, NULL, false, isTopLevel);
|
vacuum((VacuumStmt *) parsetree, InvalidOid, NULL, false,
|
||||||
|
isTopLevel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case T_ExplainStmt:
|
case T_ExplainStmt:
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* 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 */
|
/* 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);
|
BufferAccessStrategy bstrategy, bool for_wraparound, bool isTopLevel);
|
||||||
extern void vac_open_indexes(Relation relation, LOCKMODE lockmode,
|
extern void vac_open_indexes(Relation relation, LOCKMODE lockmode,
|
||||||
int *nindexes, Relation **Irel);
|
int *nindexes, Relation **Irel);
|
||||||
|
Reference in New Issue
Block a user