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

Commit41b54ba

Browse files
committed
Allow existing VACUUM options to take a Boolean argument.
This makes VACUUM work more like EXPLAIN already does without changingthe meaning of any commands that already work. It is intended tofacilitate the addition of future VACUUM options that may takenon-Boolean parameters or that default to false.Masahiko Sawada, reviewed by me.Discussion:http://postgr.es/m/CA+TgmobpYrXr5sUaEe_T0boabV0DSm=utSOZzwCUNqfLEEm8Mw@mail.gmail.comDiscussion:http://postgr.es/m/CAD21AoBaFcKBAeL5_++j+Vzir2vBBcF4juW7qH8b3HsQY=Q6+w@mail.gmail.com
1 parentc900c15 commit41b54ba

File tree

4 files changed

+53
-16
lines changed

4 files changed

+53
-16
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ <replaceable class="paramet
2626

2727
<phrase>where <replaceable class="parameter">option</replaceable> can be one of:</phrase>
2828

29-
FULL
30-
FREEZE
31-
VERBOSE
32-
ANALYZE
33-
DISABLE_PAGE_SKIPPING
34-
SKIP_LOCKED
29+
FULL [ <replaceable class="parameter">boolean</replaceable> ]
30+
FREEZE [ <replaceable class="parameter">boolean</replaceable> ]
31+
VERBOSE [ <replaceable class="parameter">boolean</replaceable> ]
32+
ANALYZE [ <replaceable class="parameter">boolean</replaceable> ]
33+
DISABLE_PAGE_SKIPPING [ <replaceable class="parameter">boolean</replaceable> ]
34+
SKIP_LOCKED [ <replaceable class="parameter">boolean</replaceable> ]
3535

3636
<phrase>and <replaceable class="parameter">table_and_columns</replaceable> is:</phrase>
3737

@@ -181,6 +181,20 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ <replaceable class="paramet
181181
</listitem>
182182
</varlistentry>
183183

184+
<varlistentry>
185+
<term><replaceable class="parameter">boolean</replaceable></term>
186+
<listitem>
187+
<para>
188+
Specifies whether the selected option should be turned on or off.
189+
You can write <literal>TRUE</literal>, <literal>ON</literal>, or
190+
<literal>1</literal> to enable the option, and <literal>FALSE</literal>,
191+
<literal>OFF</literal>, or <literal>0</literal> to disable it. The
192+
<replaceable class="parameter">boolean</replaceable> value can also
193+
be omitted, in which case <literal>TRUE</literal> is assumed.
194+
</para>
195+
</listitem>
196+
</varlistentry>
197+
184198
<varlistentry>
185199
<term><replaceable class="parameter">table_name</replaceable></term>
186200
<listitem>

‎src/backend/commands/vacuum.c‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include"catalog/pg_inherits.h"
3737
#include"catalog/pg_namespace.h"
3838
#include"commands/cluster.h"
39+
#include"commands/defrem.h"
3940
#include"commands/vacuum.h"
4041
#include"miscadmin.h"
4142
#include"nodes/makefuncs.h"
@@ -86,20 +87,24 @@ void
8687
ExecVacuum(ParseState*pstate,VacuumStmt*vacstmt,boolisTopLevel)
8788
{
8889
VacuumParamsparams;
90+
boolverbose= false;
91+
boolskip_locked= false;
92+
boolanalyze= false;
93+
boolfreeze= false;
94+
boolfull= false;
95+
booldisable_page_skipping= false;
8996
ListCell*lc;
9097

91-
params.options=vacstmt->is_vacuumcmd ?VACOPT_VACUUM :VACOPT_ANALYZE;
92-
9398
/* Parse options list */
9499
foreach(lc,vacstmt->options)
95100
{
96101
DefElem*opt= (DefElem*)lfirst(lc);
97102

98103
/* Parse common options for VACUUM and ANALYZE */
99104
if (strcmp(opt->defname,"verbose")==0)
100-
params.options |=VACOPT_VERBOSE;
105+
verbose=defGetBoolean(opt);
101106
elseif (strcmp(opt->defname,"skip_locked")==0)
102-
params.options |=VACOPT_SKIP_LOCKED;
107+
skip_locked=defGetBoolean(opt);
103108
elseif (!vacstmt->is_vacuumcmd)
104109
ereport(ERROR,
105110
(errcode(ERRCODE_SYNTAX_ERROR),
@@ -108,20 +113,30 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
108113

109114
/* Parse options available on VACUUM */
110115
elseif (strcmp(opt->defname,"analyze")==0)
111-
params.options |=VACOPT_ANALYZE;
116+
analyze=defGetBoolean(opt);
112117
elseif (strcmp(opt->defname,"freeze")==0)
113-
params.options |=VACOPT_FREEZE;
118+
freeze=defGetBoolean(opt);
114119
elseif (strcmp(opt->defname,"full")==0)
115-
params.options |=VACOPT_FULL;
120+
full=defGetBoolean(opt);
116121
elseif (strcmp(opt->defname,"disable_page_skipping")==0)
117-
params.options |=VACOPT_DISABLE_PAGE_SKIPPING;
122+
disable_page_skipping=defGetBoolean(opt);
118123
else
119124
ereport(ERROR,
120125
(errcode(ERRCODE_SYNTAX_ERROR),
121126
errmsg("unrecognized VACUUM option \"%s\"",opt->defname),
122127
parser_errposition(pstate,opt->location)));
123128
}
124129

130+
/* Set vacuum options */
131+
params.options=
132+
(vacstmt->is_vacuumcmd ?VACOPT_VACUUM :VACOPT_ANALYZE) |
133+
(verbose ?VACOPT_VERBOSE :0) |
134+
(skip_locked ?VACOPT_SKIP_LOCKED :0) |
135+
(analyze ?VACOPT_ANALYZE :0) |
136+
(freeze ?VACOPT_FREEZE :0) |
137+
(full ?VACOPT_FULL :0) |
138+
(disable_page_skipping ?VACOPT_DISABLE_PAGE_SKIPPING :0);
139+
125140
/* sanity checks on options */
126141
Assert(params.options& (VACOPT_VACUUM |VACOPT_ANALYZE));
127142
Assert((params.options&VACOPT_VACUUM)||

‎src/backend/parser/gram.y‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
309309
%type<str>vac_analyze_option_name
310310
%type<defelt>vac_analyze_option_elem
311311
%type<list>vac_analyze_option_list
312+
%type<node>vac_analyze_option_arg
312313
%type<boolean>opt_or_replace
313314
opt_grant_grant_optionopt_grant_admin_option
314315
opt_nowaitopt_if_existsopt_with_data
@@ -10543,9 +10544,9 @@ analyze_keyword:
1054310544
;
1054410545

1054510546
vac_analyze_option_elem:
10546-
vac_analyze_option_name
10547+
vac_analyze_option_namevac_analyze_option_arg
1054710548
{
10548-
$$ = makeDefElem($1,NULL,@1);
10549+
$$ = makeDefElem($1,$2,@1);
1054910550
}
1055010551
;
1055110552

@@ -10554,6 +10555,11 @@ vac_analyze_option_name:
1055410555
|analyze_keyword{$$ ="analyze"; }
1055510556
;
1055610557

10558+
vac_analyze_option_arg:
10559+
opt_boolean_or_string{$$ = (Node *) makeString($1); }
10560+
|/* EMPTY*/ {$$ =NULL; }
10561+
;
10562+
1055710563
opt_analyze:
1055810564
analyze_keyword{$$ =true; }
1055910565
|/*EMPTY*/{$$ =false; }

‎src/bin/psql/tab-complete.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,6 +3444,8 @@ psql_completion(const char *text, int start, int end)
34443444
if (ends_with(prev_wd,'(')||ends_with(prev_wd,','))
34453445
COMPLETE_WITH("FULL","FREEZE","ANALYZE","VERBOSE",
34463446
"DISABLE_PAGE_SKIPPING","SKIP_LOCKED");
3447+
elseif (TailMatches("FULL|FREEZE|ANALYZE|VERBOSE|DISABLE_PAGE_SKIPPING|SKIP_LOCKED"))
3448+
COMPLETE_WITH("ON","OFF");
34473449
}
34483450
elseif (HeadMatches("VACUUM")&&TailMatches("("))
34493451
/* "VACUUM (" should be caught above, so assume we want columns */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp