Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion doc/src/sgml/ref/analyze.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ PostgreSQL documentation

<refsynopsisdiv>
<synopsis>
ANALYZE [ VERBOSE ] [ <replaceable class="PARAMETER">table_name</replaceable> [ ( <replaceable class="PARAMETER">column_name</replaceable> [, ...] ) ] ]
ANALYZE [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] [ <replaceable class="parameter">table_and_columns</replaceable> [, ...] ]
ANALYZE [ VERBOSE ] [ <replaceable class="parameter">table_and_columns</replaceable> [, ...] ]

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

VERBOSE

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

<replaceable class="parameter">table_name</replaceable> [ ( <replaceable class="parameter">column_name</replaceable> [, ...] ) ]
</synopsis>
</refsynopsisdiv>

Expand All @@ -43,6 +52,13 @@ ANALYZE [ VERBOSE ] [ <replaceable class="PARAMETER">table_name</replaceable> [
only that table. It is further possible to give a list of column names,
in which case only the statistics for those columns are collected.
</para>

<para>
When the option list is surrounded by parentheses, the options can be
written in any order. The parenthesized syntax was added in
<productname>PostgreSQL</productname> 11; the unparenthesized syntax
is deprecated.
</para>
</refsect1>

<refsect1>
Expand Down
18 changes: 17 additions & 1 deletion src/backend/parser/gram.y
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ static Node *makeIsNotDistinctFromNode(Node *expr, int position);

%type <ival> opt_lock lock_type cast_context
%type <ival> vacuum_option_list vacuum_option_elem
%type <boolean> opt_force opt_or_replace
analyze_option_list analyze_option_elem
%type <boolean> opt_or_replace opt_force
opt_grant_grant_option opt_grant_admin_option
opt_nowait opt_if_exists opt_with_data opt_masteronly

Expand Down Expand Up @@ -11498,6 +11499,21 @@ AnalyzeStmt:
n->va_cols = $6;
$$ = (Node *)n;
}
| analyze_keyword '(' analyze_option_list ')'
{
VacuumStmt *n = makeNode(VacuumStmt);
n->options = VACOPT_ANALYZE | $3;
$$ = (Node *) n;
}
;

analyze_option_list:
analyze_option_elem { $$ = $1; }
| analyze_option_list ',' analyze_option_elem { $$ = $1 | $3; }
;

analyze_option_elem:
VERBOSE { $$ = VACOPT_VERBOSE; }
;

analyze_keyword:
Expand Down
30 changes: 30 additions & 0 deletions src/test/regress/expected/vacuum.out
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,35 @@ VACUUM ANALYZE vaccluster(i,i);
ERROR: column "i" of relation "vaccluster" appears more than once
ANALYZE vaccluster(i,i);
ERROR: column "i" of relation "vaccluster" appears more than once
VACUUM ANALYZE vacparted(a,b,a);
ERROR: column "a" of relation "vacparted" appears more than once
ANALYZE vacparted(a,b,b);
ERROR: column "b" of relation "vacparted" appears more than once
-- multiple tables specified
VACUUM vaccluster, vactst;
VACUUM vacparted, does_not_exist;
ERROR: relation "does_not_exist" does not exist
VACUUM (FREEZE) vacparted, vaccluster, vactst;
VACUUM (FREEZE) does_not_exist, vaccluster;
ERROR: relation "does_not_exist" does not exist
VACUUM ANALYZE vactst, vacparted (a);
VACUUM ANALYZE vactst (does_not_exist), vacparted (b);
ERROR: column "does_not_exist" of relation "vactst" does not exist
VACUUM FULL vacparted, vactst;
VACUUM FULL vactst, vacparted (a, b), vaccluster (i);
ERROR: ANALYZE option must be specified when a column list is provided
ANALYZE vactst, vacparted;
ANALYZE vacparted (b), vactst;
ANALYZE vactst, does_not_exist, vacparted;
ERROR: relation "does_not_exist" does not exist
ANALYZE vactst (i), vacparted (does_not_exist);
ERROR: column "does_not_exist" of relation "vacparted" does not exist
-- parenthesized syntax for ANALYZE
ANALYZE (VERBOSE) does_not_exist;
ERROR: relation "does_not_exist" does not exist
ANALYZE (nonexistant-arg) does_not_exist;
ERROR: syntax error at or near "nonexistant"
LINE 1: ANALYZE (nonexistant-arg) does_not_exist;
^
DROP TABLE vaccluster;
DROP TABLE vactst;
4 changes: 4 additions & 0 deletions src/test/regress/sql/vacuum.sql
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,9 @@ VACUUM FULL vactst;
VACUUM ANALYZE vaccluster(i,i);
ANALYZE vaccluster(i,i);

-- parenthesized syntax for ANALYZE
ANALYZE (VERBOSE) does_not_exist;
ANALYZE (nonexistant-arg) does_not_exist;

DROP TABLE vaccluster;
DROP TABLE vactst;
Loading