Skip to content

Commit 9319fd8

Browse files
committed
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.
1 parent f23b791 commit 9319fd8

File tree

4 files changed

+27
-34
lines changed

4 files changed

+27
-34
lines changed

src/backend/commands/vacuum.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.374 2008/05/15 00:17:39 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.375 2008/06/05 15:47:32 alvherre Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -210,7 +210,7 @@ static BufferAccessStrategy vac_strategy;
210210

211211

212212
/* non-export function prototypes */
213-
static List *get_rel_oids(List *relids, const RangeVar *vacrel,
213+
static List *get_rel_oids(Oid relid, const RangeVar *vacrel,
214214
const char *stmttype);
215215
static void vac_truncate_clog(TransactionId frozenXID);
216216
static void vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind,
@@ -264,9 +264,9 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
264264
/*
265265
* Primary entry point for VACUUM and ANALYZE commands.
266266
*
267-
* relids is normally NIL; if it is not, then it provides the list of
268-
* relation OIDs to be processed, and vacstmt->relation is ignored.
269-
* (The non-NIL case is currently only used by autovacuum.)
267+
* relid is normally InvalidOid; if it is not, then it provides the relation
268+
* OID to be processed, and vacstmt->relation is ignored. (The non-invalid
269+
* case is currently only used by autovacuum.)
270270
*
271271
* for_wraparound is used by autovacuum to let us know when it's forcing
272272
* a vacuum for wraparound, which should not be auto-cancelled.
@@ -276,12 +276,12 @@ static Size PageGetFreeSpaceWithFillFactor(Relation relation, Page page);
276276
*
277277
* isTopLevel should be passed down from ProcessUtility.
278278
*
279-
* It is the caller's responsibility that vacstmt, relids, and bstrategy
279+
* It is the caller's responsibility that vacstmt and bstrategy
280280
* (if given) be allocated in a memory context that won't disappear
281281
* at transaction commit.
282282
*/
283283
void
284-
vacuum(VacuumStmt *vacstmt, List *relids,
284+
vacuum(VacuumStmt *vacstmt, Oid relid,
285285
BufferAccessStrategy bstrategy, bool for_wraparound, bool isTopLevel)
286286
{
287287
const char *stmttype = vacstmt->vacuum ? "VACUUM" : "ANALYZE";
@@ -351,13 +351,13 @@ vacuum(VacuumStmt *vacstmt, List *relids,
351351
vac_strategy = bstrategy;
352352

353353
/* Remember whether we are processing everything in the DB */
354-
all_rels = (relids == NIL && vacstmt->relation == NULL);
354+
all_rels = (!OidIsValid(relid) && vacstmt->relation == NULL);
355355

356356
/*
357357
* Build list of relations to process, unless caller gave us one. (If we
358358
* build one, we put it in vac_context for safekeeping.)
359359
*/
360-
relations = get_rel_oids(relids, vacstmt->relation, stmttype);
360+
relations = get_rel_oids(relid, vacstmt->relation, stmttype);
361361

362362
/*
363363
* Decide whether we need to start/commit our own transactions.
@@ -531,16 +531,19 @@ vacuum(VacuumStmt *vacstmt, List *relids,
531531
* per-relation transactions.
532532
*/
533533
static List *
534-
get_rel_oids(List *relids, const RangeVar *vacrel, const char *stmttype)
534+
get_rel_oids(Oid relid, const RangeVar *vacrel, const char *stmttype)
535535
{
536536
List *oid_list = NIL;
537537
MemoryContext oldcontext;
538538

539-
/* List supplied by VACUUM's caller? */
540-
if (relids)
541-
return relids;
542-
543-
if (vacrel)
539+
/* OID supplied by VACUUM's caller? */
540+
if (OidIsValid(relid))
541+
{
542+
oldcontext = MemoryContextSwitchTo(vac_context);
543+
oid_list = lappend_oid(oid_list, relid);
544+
MemoryContextSwitchTo(oldcontext);
545+
}
546+
else if (vacrel)
544547
{
545548
/* Process a specific relation */
546549
Oid relid;

src/backend/postmaster/autovacuum.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*
5656
*
5757
* IDENTIFICATION
58-
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.78 2008/05/15 00:17:40 tgl Exp $
58+
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.79 2008/06/05 15:47:32 alvherre Exp $
5959
*
6060
*-------------------------------------------------------------------------
6161
*/
@@ -1244,8 +1244,7 @@ do_start_worker(void)
12441244
* left to do_start_worker.
12451245
*
12461246
* This routine is also expected to insert an entry into the database list if
1247-
* the selected database was previously absent from the list. It returns the
1248-
* new database list.
1247+
* the selected database was previously absent from the list.
12491248
*/
12501249
static void
12511250
launch_worker(TimestampTz now)
@@ -2601,8 +2600,6 @@ autovacuum_do_vac_analyze(Oid relid, bool dovacuum, bool doanalyze,
26012600
BufferAccessStrategy bstrategy)
26022601
{
26032602
VacuumStmt vacstmt;
2604-
List *relids;
2605-
MemoryContext old_cxt;
26062603

26072604
/* Set up command parameters --- use a local variable instead of palloc */
26082605
MemSet(&vacstmt, 0, sizeof(vacstmt));
@@ -2613,21 +2610,13 @@ autovacuum_do_vac_analyze(Oid relid, bool dovacuum, bool doanalyze,
26132610
vacstmt.analyze = doanalyze;
26142611
vacstmt.freeze_min_age = freeze_min_age;
26152612
vacstmt.verbose = false;
2616-
vacstmt.relation = NULL; /* not used since we pass a relids list */
2613+
vacstmt.relation = NULL; /* not used since we pass a relid */
26172614
vacstmt.va_cols = NIL;
26182615

2619-
/*
2620-
* The list must survive transaction boundaries, so make sure we create it
2621-
* in a long-lived context
2622-
*/
2623-
old_cxt = MemoryContextSwitchTo(AutovacMemCxt);
2624-
relids = list_make1_oid(relid);
2625-
MemoryContextSwitchTo(old_cxt);
2626-
26272616
/* Let pgstat know what we're doing */
26282617
autovac_report_activity(&vacstmt, relid);
26292618

2630-
vacuum(&vacstmt, relids, bstrategy, for_wraparound, true);
2619+
vacuum(&vacstmt, relid, bstrategy, for_wraparound, true);
26312620
}
26322621

26332622
/*

src/backend/tcop/utility.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.291 2008/03/19 18:38:30 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.292 2008/06/05 15:47:32 alvherre Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -1032,7 +1032,8 @@ ProcessUtility(Node *parsetree,
10321032
break;
10331033

10341034
case T_VacuumStmt:
1035-
vacuum((VacuumStmt *) parsetree, NIL, NULL, false, isTopLevel);
1035+
vacuum((VacuumStmt *) parsetree, InvalidOid, NULL, false,
1036+
isTopLevel);
10361037
break;
10371038

10381039
case T_ExplainStmt:

src/include/commands/vacuum.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.76 2008/03/14 17:25:59 alvherre Exp $
10+
* $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.77 2008/06/05 15:47:32 alvherre Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -113,7 +113,7 @@ extern int vacuum_freeze_min_age;
113113

114114

115115
/* in commands/vacuum.c */
116-
extern void vacuum(VacuumStmt *vacstmt, List *relids,
116+
extern void vacuum(VacuumStmt *vacstmt, Oid relid,
117117
BufferAccessStrategy bstrategy, bool for_wraparound, bool isTopLevel);
118118
extern void vac_open_indexes(Relation relation, LOCKMODE lockmode,
119119
int *nindexes, Relation **Irel);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy