Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5e66a51

Browse files
committed
Provide a parenthesized-options syntax for VACUUM, analogous to that recently
adopted for EXPLAIN. This will allow additional options to be implementedin future without having to make them fully-reserved keywords. The old syntaxremains available for existing options, however.Itagaki Takahiro
1 parent49ed392 commit5e66a51

File tree

13 files changed

+146
-74
lines changed

13 files changed

+146
-74
lines changed

‎doc/src/sgml/maintenance.sgml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.96 2009/08/07 20:54:31 alvherre Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.97 2009/11/16 21:32:06 tgl Exp $ -->
22

33
<chapter id="maintenance">
44
<title>Routine Database Maintenance Tasks</title>
@@ -502,8 +502,9 @@ SELECT datname, age(datfrozenxid) FROM pg_database;
502502
only scans pages that have been modified since the last vacuum, but
503503
<structfield>relfrozenxid</> can only be advanced when the whole table is
504504
scanned. The whole table is scanned when <structfield>relfrozenxid</> is
505-
more than <varname>vacuum_freeze_table_age</> transactions old, when the
506-
<command>VACUUM FREEZE</> command is used, or when all pages happen to
505+
more than <varname>vacuum_freeze_table_age</> transactions old, when
506+
<command>VACUUM</>'s <literal>FREEZE</> option is used, or when all pages
507+
happen to
507508
require vacuuming to remove dead row versions. When <command>VACUUM</>
508509
scans the whole table, after it's finished <literal>age(relfrozenxid)</>
509510
should be a little more than the <varname>vacuum_freeze_min_age</> setting

‎doc/src/sgml/ref/vacuum.sgml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/vacuum.sgml,v 1.55 2009/03/24 20:17:08 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/vacuum.sgml,v 1.56 2009/11/16 21:32:06 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -21,6 +21,7 @@ PostgreSQL documentation
2121

2222
<refsynopsisdiv>
2323
<synopsis>
24+
VACUUM [ ( { FULL | FREEZE | VERBOSE | ANALYZE } [, ...] ) ] [ <replaceable class="PARAMETER">table</replaceable> [ (<replaceable class="PARAMETER">column</replaceable> [, ...] ) ] ]
2425
VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ <replaceable class="PARAMETER">table</replaceable> ]
2526
VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] ANALYZE [ <replaceable class="PARAMETER">table</replaceable> [ (<replaceable class="PARAMETER">column</replaceable> [, ...] ) ] ]
2627
</synopsis>
@@ -63,6 +64,15 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] ANALYZE [ <replaceable class="PARAMETER">
6364
blocks. This form is much slower and requires an exclusive lock on each
6465
table while it is being processed.
6566
</para>
67+
68+
<para>
69+
When the option list is surrounded by parentheses, the options can be
70+
written in any order. Without parentheses, options must be specified
71+
in exactly the order shown above.
72+
Prior to <productname>PostgreSQL</productname> 8.5, the unparenthesized
73+
syntax was the only one supported. It is expected that all new options
74+
will be supported only in the parenthesized syntax.
75+
</para>
6676
</refsect1>
6777

6878
<refsect1>
@@ -127,6 +137,7 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] ANALYZE [ <replaceable class="PARAMETER">
127137
<listitem>
128138
<para>
129139
The name of a specific column to analyze. Defaults to all columns.
140+
If a column list is specified, <literal>ANALYZE</> is implied.
130141
</para>
131142
</listitem>
132143
</varlistentry>
@@ -214,7 +225,7 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] ANALYZE [ <replaceable class="PARAMETER">
214225
table in the regression database:
215226

216227
<programlisting>
217-
regression=# VACUUM VERBOSE ANALYZE onek;
228+
regression=# VACUUM(VERBOSE, ANALYZE) onek;
218229
INFO: vacuuming "public.onek"
219230
INFO: index "onek_unique1" now contains 1000 tuples in 14 pages
220231
DETAIL: 3000 index tuples were removed.

‎src/backend/commands/analyze.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.141 2009/08/12 18:23:49 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.142 2009/11/16 21:32:06 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -135,7 +135,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt,
135135
Oidsave_userid;
136136
boolsave_secdefcxt;
137137

138-
if (vacstmt->verbose)
138+
if (vacstmt->options&VACOPT_VERBOSE)
139139
elevel=INFO;
140140
else
141141
elevel=DEBUG2;
@@ -173,7 +173,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt,
173173
(pg_database_ownercheck(MyDatabaseId,GetUserId())&& !onerel->rd_rel->relisshared)))
174174
{
175175
/* No need for a WARNING if we already complained during VACUUM */
176-
if (!vacstmt->vacuum)
176+
if (!(vacstmt->options&VACOPT_VACUUM))
177177
{
178178
if (onerel->rd_rel->relisshared)
179179
ereport(WARNING,
@@ -199,7 +199,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt,
199199
if (onerel->rd_rel->relkind!=RELKIND_RELATION)
200200
{
201201
/* No need for a WARNING if we already complained during VACUUM */
202-
if (!vacstmt->vacuum)
202+
if (!(vacstmt->options&VACOPT_VACUUM))
203203
ereport(WARNING,
204204
(errmsg("skipping \"%s\" --- cannot analyze indexes, views, or special system tables",
205205
RelationGetRelationName(onerel))));
@@ -475,7 +475,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt,
475475
* VACUUM ANALYZE, don't overwrite the accurate count already inserted by
476476
* VACUUM.
477477
*/
478-
if (!vacstmt->vacuum)
478+
if (!(vacstmt->options&VACOPT_VACUUM))
479479
{
480480
for (ind=0;ind<nindexes;ind++)
481481
{
@@ -493,7 +493,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt,
493493
cleanup:
494494

495495
/* If this isn't part of VACUUM ANALYZE, let index AMs do cleanup */
496-
if (!vacstmt->vacuum)
496+
if (!(vacstmt->options&VACOPT_VACUUM))
497497
{
498498
for (ind=0;ind<nindexes;ind++)
499499
{

‎src/backend/commands/vacuum.c

Lines changed: 26 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.395 2009/11/10 18:00:06alvherre Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.396 2009/11/16 21:32:06tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -289,14 +289,22 @@ void
289289
vacuum(VacuumStmt*vacstmt,Oidrelid,booldo_toast,
290290
BufferAccessStrategybstrategy,boolfor_wraparound,boolisTopLevel)
291291
{
292-
constchar*stmttype=vacstmt->vacuum ?"VACUUM" :"ANALYZE";
292+
constchar*stmttype;
293293
volatileMemoryContextanl_context=NULL;
294294
volatileboolall_rels,
295295
in_outer_xact,
296296
use_own_xacts;
297297
List*relations;
298298

299-
if (vacstmt->verbose)
299+
/* sanity checks on options */
300+
Assert(vacstmt->options& (VACOPT_VACUUM |VACOPT_ANALYZE));
301+
Assert((vacstmt->options&VACOPT_VACUUM)||
302+
!(vacstmt->options& (VACOPT_FULL |VACOPT_FREEZE)));
303+
Assert((vacstmt->options&VACOPT_ANALYZE)||vacstmt->va_cols==NIL);
304+
305+
stmttype= (vacstmt->options&VACOPT_VACUUM) ?"VACUUM" :"ANALYZE";
306+
307+
if (vacstmt->options&VACOPT_VERBOSE)
300308
elevel=INFO;
301309
else
302310
elevel=DEBUG2;
@@ -315,7 +323,7 @@ vacuum(VacuumStmt *vacstmt, Oid relid, bool do_toast,
315323
*
316324
* ANALYZE (without VACUUM) can run either way.
317325
*/
318-
if (vacstmt->vacuum)
326+
if (vacstmt->options&VACOPT_VACUUM)
319327
{
320328
PreventTransactionChain(isTopLevel,stmttype);
321329
in_outer_xact= false;
@@ -327,7 +335,7 @@ vacuum(VacuumStmt *vacstmt, Oid relid, bool do_toast,
327335
* Send info about dead objects to the statistics collector, unless we are
328336
* in autovacuum --- autovacuum.c does this for itself.
329337
*/
330-
if (vacstmt->vacuum&& !IsAutoVacuumWorkerProcess())
338+
if ((vacstmt->options&VACOPT_VACUUM)&& !IsAutoVacuumWorkerProcess())
331339
pgstat_vacuum_stat();
332340

333341
/*
@@ -378,11 +386,11 @@ vacuum(VacuumStmt *vacstmt, Oid relid, bool do_toast,
378386
* transaction block, and also in an autovacuum worker, use own
379387
* transactions so we can release locks sooner.
380388
*/
381-
if (vacstmt->vacuum)
389+
if (vacstmt->options&VACOPT_VACUUM)
382390
use_own_xacts= true;
383391
else
384392
{
385-
Assert(vacstmt->analyze);
393+
Assert(vacstmt->options&VACOPT_ANALYZE);
386394
if (IsAutoVacuumWorkerProcess())
387395
use_own_xacts= true;
388396
elseif (in_outer_xact)
@@ -438,11 +446,11 @@ vacuum(VacuumStmt *vacstmt, Oid relid, bool do_toast,
438446
Oidrelid=lfirst_oid(cur);
439447
boolscanned_all= false;
440448

441-
if (vacstmt->vacuum)
449+
if (vacstmt->options&VACOPT_VACUUM)
442450
vacuum_rel(relid,vacstmt,do_toast,for_wraparound,
443451
&scanned_all);
444452

445-
if (vacstmt->analyze)
453+
if (vacstmt->options&VACOPT_ANALYZE)
446454
{
447455
MemoryContextold_context=NULL;
448456

@@ -502,7 +510,7 @@ vacuum(VacuumStmt *vacstmt, Oid relid, bool do_toast,
502510
StartTransactionCommand();
503511
}
504512

505-
if (vacstmt->vacuum&& !IsAutoVacuumWorkerProcess())
513+
if ((vacstmt->options&VACOPT_VACUUM)&& !IsAutoVacuumWorkerProcess())
506514
{
507515
/*
508516
* Update pg_database.datfrozenxid, and truncate pg_clog if possible.
@@ -1034,7 +1042,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, bool do_toast, bool for_wraparound,
10341042
*/
10351043
PushActiveSnapshot(GetTransactionSnapshot());
10361044

1037-
if (!vacstmt->full)
1045+
if (!(vacstmt->options&VACOPT_FULL))
10381046
{
10391047
/*
10401048
* In lazy vacuum, we can set the PROC_IN_VACUUM flag, which lets
@@ -1074,7 +1082,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, bool do_toast, bool for_wraparound,
10741082
* vacuum, but just ShareUpdateExclusiveLock for concurrent vacuum. Either
10751083
* way, we can be sure that no other backend is vacuuming the same table.
10761084
*/
1077-
lmode=vacstmt->full ?AccessExclusiveLock :ShareUpdateExclusiveLock;
1085+
lmode=(vacstmt->options&VACOPT_FULL) ?AccessExclusiveLock :ShareUpdateExclusiveLock;
10781086

10791087
/*
10801088
* Open the relation and get the appropriate lock on it.
@@ -1186,7 +1194,7 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, bool do_toast, bool for_wraparound,
11861194
/*
11871195
* Do the actual work --- either FULL or "lazy" vacuum
11881196
*/
1189-
if (vacstmt->full)
1197+
if (vacstmt->options&VACOPT_FULL)
11901198
heldoff=full_vacuum_rel(onerel,vacstmt);
11911199
else
11921200
heldoff=lazy_vacuum_rel(onerel,vacstmt,vac_strategy,scanned_all);
@@ -1331,8 +1339,11 @@ full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
13311339
vacrelstats->hasindex,FreezeLimit);
13321340

13331341
/* report results to the stats collector, too */
1334-
pgstat_report_vacuum(RelationGetRelid(onerel),onerel->rd_rel->relisshared,
1335-
true,vacstmt->analyze,vacrelstats->rel_tuples);
1342+
pgstat_report_vacuum(RelationGetRelid(onerel),
1343+
onerel->rd_rel->relisshared,
1344+
true,
1345+
(vacstmt->options&VACOPT_ANALYZE)!=0,
1346+
vacrelstats->rel_tuples);
13361347

13371348
returnheldoff;
13381349
}

‎src/backend/commands/vacuumlazy.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
*
3131
* IDENTIFICATION
32-
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.123 2009/11/10 18:00:06alvherre Exp $
32+
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.124 2009/11/16 21:32:06tgl Exp $
3333
*
3434
*-------------------------------------------------------------------------
3535
*/
@@ -164,7 +164,7 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
164164
if (IsAutoVacuumWorkerProcess()&&Log_autovacuum_min_duration>0)
165165
starttime=GetCurrentTimestamp();
166166

167-
if (vacstmt->verbose)
167+
if (vacstmt->options&VACOPT_VERBOSE)
168168
elevel=INFO;
169169
else
170170
elevel=DEBUG2;
@@ -236,7 +236,8 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
236236
pgstat_report_vacuum(RelationGetRelid(onerel),
237237
onerel->rd_rel->relisshared,
238238
vacrelstats->scanned_all,
239-
vacstmt->analyze,vacrelstats->rel_tuples);
239+
(vacstmt->options&VACOPT_ANALYZE)!=0,
240+
vacrelstats->rel_tuples);
240241

241242
/* and log the action if appropriate */
242243
if (IsAutoVacuumWorkerProcess()&&Log_autovacuum_min_duration >=0)

‎src/backend/nodes/copyfuncs.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.450 2009/10/28 14:55:38 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.451 2009/11/16 21:32:06 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -2957,10 +2957,7 @@ _copyVacuumStmt(VacuumStmt *from)
29572957
{
29582958
VacuumStmt*newnode=makeNode(VacuumStmt);
29592959

2960-
COPY_SCALAR_FIELD(vacuum);
2961-
COPY_SCALAR_FIELD(full);
2962-
COPY_SCALAR_FIELD(analyze);
2963-
COPY_SCALAR_FIELD(verbose);
2960+
COPY_SCALAR_FIELD(options);
29642961
COPY_SCALAR_FIELD(freeze_min_age);
29652962
COPY_SCALAR_FIELD(freeze_table_age);
29662963
COPY_NODE_FIELD(relation);

‎src/backend/nodes/equalfuncs.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Portions Copyright (c) 1994, Regents of the University of California
2323
*
2424
* IDENTIFICATION
25-
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.372 2009/10/28 14:55:38 tgl Exp $
25+
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.373 2009/11/16 21:32:06 tgl Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -1483,10 +1483,7 @@ _equalDropdbStmt(DropdbStmt *a, DropdbStmt *b)
14831483
staticbool
14841484
_equalVacuumStmt(VacuumStmt*a,VacuumStmt*b)
14851485
{
1486-
COMPARE_SCALAR_FIELD(vacuum);
1487-
COMPARE_SCALAR_FIELD(full);
1488-
COMPARE_SCALAR_FIELD(analyze);
1489-
COMPARE_SCALAR_FIELD(verbose);
1486+
COMPARE_SCALAR_FIELD(options);
14901487
COMPARE_SCALAR_FIELD(freeze_min_age);
14911488
COMPARE_SCALAR_FIELD(freeze_table_age);
14921489
COMPARE_NODE_FIELD(relation);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp