Support parenthesized syntax for CLUSTER without a table name.
authorNathan Bossart <[email protected]>
Wed, 19 Jul 2023 22:26:52 +0000 (15:26 -0700)
committerNathan Bossart <[email protected]>
Wed, 19 Jul 2023 22:26:52 +0000 (15:26 -0700)
b5913f6120 added a parenthesized syntax for CLUSTER, but it
requires specifying a table name.  This is unlike commands such as
VACUUM and ANALYZE, which do not require specifying a table in the
parenthesized syntax.  This change resolves this inconsistency.
This is preparatory work for a follow-up commit that will move the
unparenthesized syntax to the "Compatibility" section of the
CLUSTER documentation.

Reviewed-by: Melanie Plageman, Michael Paquier
Discussion: https://postgr.es/m/CAAKRu_bc5uHieG1976kGqJKxyWtyQt9yvktjsVX%2Bi7NOigDjOA%40mail.gmail.com

doc/src/sgml/ref/cluster.sgml
src/backend/parser/gram.y

index e308e2ce912ec14acf126c006f8bff82a5ea0250..b6d5655c194359fa7317d171c15186f729975fe0 100644 (file)
@@ -21,7 +21,7 @@ PostgreSQL documentation
 
  <refsynopsisdiv>
 <synopsis>
-CLUSTER [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] <replaceable class="parameter">table_name</replaceable> [ USING <replaceable class="parameter">index_name</replaceable> ]
+CLUSTER [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] [ <replaceable class="parameter">table_name</replaceable> [ USING <replaceable class="parameter">index_name</replaceable> ] ]
 CLUSTER [ VERBOSE ] [ <replaceable class="parameter">table_name</replaceable> [ USING <replaceable class="parameter">index_name</replaceable> ] ]
 
 <phrase>where <replaceable class="parameter">option</replaceable> can be one of:</phrase>
index 91793cb2effb00fc2050e5f5829fcf1fa4385f88..7a44a374e4918126947f0312de3e7cc608023313 100644 (file)
@@ -11553,7 +11553,7 @@ CreateConversionStmt:
 /*****************************************************************************
  *
  *     QUERY:
- *             CLUSTER (options) <qualified_name> [ USING <index_name> ]
+ *             CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
  *             CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
  *             CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
  *
@@ -11569,6 +11569,15 @@ ClusterStmt:
                    n->params = $3;
                    $$ = (Node *) n;
                }
+           | CLUSTER '(' utility_option_list ')'
+               {
+                   ClusterStmt *n = makeNode(ClusterStmt);
+
+                   n->relation = NULL;
+                   n->indexname = NULL;
+                   n->params = $3;
+                   $$ = (Node *) n;
+               }
            /* unparenthesized VERBOSE kept for pre-14 compatibility */
            | CLUSTER opt_verbose qualified_name cluster_index_specification
                {
@@ -11581,6 +11590,7 @@ ClusterStmt:
                        n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
                    $$ = (Node *) n;
                }
+           /* unparenthesized VERBOSE kept for pre-17 compatibility */
            | CLUSTER opt_verbose
                {
                    ClusterStmt *n = makeNode(ClusterStmt);