Add parenthesized options syntax for ANALYZE.
authorAndres Freund <andres@anarazel.de>
Tue, 6 Mar 2018 00:21:05 +0000 (16:21 -0800)
committerAndres Freund <andres@anarazel.de>
Tue, 6 Mar 2018 00:21:05 +0000 (16:21 -0800)
This is analogous to the syntax allowed for VACUUM. This allows us to
avoid making new options reserved keywords and makes it easier to
allow arbitrary argument order. Oh, and it's consistent with the other
commands, too.

Author: Nathan Bossart
Reviewed-By: Michael Paquier, Masahiko Sawada
Discussion: https://postgr.es/m/D3FC73E2-9B1A-4DB4-8180-55F57D116B4E@amazon.com

doc/src/sgml/ref/analyze.sgml
src/backend/parser/gram.y
src/test/regress/expected/vacuum.out
src/test/regress/sql/vacuum.sql

index 83b07a03003f9b2c5b5b150c6f2ea4fc5bed9dd6..10b3a9a67339594257cba3e536f91fa4656a5670 100644 (file)
@@ -21,9 +21,14 @@ PostgreSQL documentation
 
  <refsynopsisdiv>
 <synopsis>
+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">table_and_columns</replaceable> is:</phrase>
+<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>
@@ -49,6 +54,13 @@ ANALYZE [ VERBOSE ] [ <replaceable class="parameter">table_and_columns</replacea
    It is further possible to give a list of column names for a table,
    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>
index 8a2e52acb45d59cb02ce22afdaeda284f7c00812..06c03dff3cea1b69fe15322cd87f86ece9597cb1 100644 (file)
@@ -306,6 +306,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
 
 %type <ival>   opt_lock lock_type cast_context
 %type <ival>   vacuum_option_list vacuum_option_elem
+               analyze_option_list analyze_option_elem
 %type <boolean>    opt_or_replace
                opt_grant_grant_option opt_grant_admin_option
                opt_nowait opt_if_exists opt_with_data
@@ -10551,6 +10552,22 @@ AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
                    n->rels = $3;
                    $$ = (Node *)n;
                }
+           | analyze_keyword '(' analyze_option_list ')' opt_vacuum_relation_list
+               {
+                   VacuumStmt *n = makeNode(VacuumStmt);
+                   n->options = VACOPT_ANALYZE | $3;
+                   n->rels = $5;
+                   $$ = (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:
index c440c7ea58f36741d96cd0963cd40511e38f6e71..d66e2aa3b70f3e4ff80e4561399d15839af3854e 100644 (file)
@@ -112,6 +112,13 @@ 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;
 DROP TABLE vacparted;
index 92eaca2a93b06dba575f08da544de721c16aa293..275ce2e270f7325e4dc025fe8d581d63b38c3936 100644 (file)
@@ -89,6 +89,10 @@ ANALYZE vacparted (b), vactst;
 ANALYZE vactst, does_not_exist, vacparted;
 ANALYZE vactst (i), vacparted (does_not_exist);
 
+-- parenthesized syntax for ANALYZE
+ANALYZE (VERBOSE) does_not_exist;
+ANALYZE (nonexistant-arg) does_not_exist;
+
 DROP TABLE vaccluster;
 DROP TABLE vactst;
 DROP TABLE vacparted;