On Fri, Jul 22, 2022 at 11:54:27PM -0400, Tom Lane wrote:
> That does not seem like an improvement.  In v15:
> 
> regression=# REINDEX SYSTEM CONCURRENTLY db;
> ERROR:  cannot reindex system catalogs concurrently
> 
> As of HEAD:
> 
> regression=# REINDEX SYSTEM CONCURRENTLY db;
> ERROR:  syntax error at or near "CONCURRENTLY"
> LINE 1: REINDEX SYSTEM CONCURRENTLY db;
>                        ^
> 
> That is not a very helpful error, not even if the man page
> doesn't show the syntax as legal.

As the problem comes down to the fact that INDEX/TABLE, SCHEMA and
DATABASE/SYSTEM need to handle names for different object types each,
I think that we could do something like the attached, removing one
block on the way at the cost of an extra parser node.

By the way, it seems that 83011ce also broke the case of "REINDEX
DATABASE CONCURRENTLY", where the parser missed the addition of a
DefElem for "concurrently" in this case.
--
Michael
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index ace4fb5c77..dfb0d85d66 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -564,7 +564,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
 %type <defelt>	generic_option_elem alter_generic_option_elem
 %type <list>	generic_option_list alter_generic_option_list
 
-%type <ival>	reindex_target_type
+%type <ival>	reindex_target_relation reindex_target_all
 %type <list>	opt_reindex_option_list
 
 %type <node>	copy_generic_opt_arg copy_generic_opt_arg_list_item
@@ -9092,13 +9092,12 @@ DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_d
  *
  *		QUERY:
  *
- *		REINDEX [ (options) ] {TABLE | INDEX | SCHEMA} [CONCURRENTLY] <name>
- *		REINDEX [ (options) ] DATABASE [CONCURRENTLY] [<name>]
- *		REINDEX [ (options) ] SYSTEM [<name>]
+ *		REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
+ *		REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
  *****************************************************************************/
 
 ReindexStmt:
-			REINDEX opt_reindex_option_list reindex_target_type opt_concurrently qualified_name
+			REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
 				{
 					ReindexStmt *n = makeNode(ReindexStmt);
 
@@ -9124,29 +9123,27 @@ ReindexStmt:
 											makeDefElem("concurrently", NULL, @4));
 					$$ = (Node *) n;
 				}
-			| REINDEX opt_reindex_option_list DATABASE opt_concurrently opt_single_name
+			| REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
 				{
 					ReindexStmt *n = makeNode(ReindexStmt);
-					n->kind = REINDEX_OBJECT_DATABASE;
-					n->name = NULL;
-					n->relation = NULL;
-					n->params = $2;
-					$$ = (Node *) n;
-				}
-			| REINDEX opt_reindex_option_list SYSTEM_P opt_single_name
-				{
-					ReindexStmt *n = makeNode(ReindexStmt);
-					n->kind = REINDEX_OBJECT_SYSTEM;
-					n->name = NULL;
+					n->kind = $3;
+					n->name = $5;
 					n->relation = NULL;
 					n->params = $2;
+					if ($4)
+						n->params = lappend(n->params,
+											makeDefElem("concurrently", NULL, @4));
 					$$ = (Node *) n;
 				}
 		;
-reindex_target_type:
+reindex_target_relation:
 			INDEX					{ $$ = REINDEX_OBJECT_INDEX; }
 			| TABLE					{ $$ = REINDEX_OBJECT_TABLE; }
 		;
+reindex_target_all:
+			SYSTEM_P				{ $$ = REINDEX_OBJECT_SYSTEM; }
+			| DATABASE				{ $$ = REINDEX_OBJECT_DATABASE; }
+		;
 opt_reindex_option_list:
 			'(' utility_option_list ')'				{ $$ = $2; }
 			| /* EMPTY */							{ $$ = NULL; }
diff --git a/src/test/regress/expected/create_index.out b/src/test/regress/expected/create_index.out
index a913a1846f..801b396398 100644
--- a/src/test/regress/expected/create_index.out
+++ b/src/test/regress/expected/create_index.out
@@ -2521,9 +2521,7 @@ ERROR:  cannot reindex system catalogs concurrently
 REINDEX INDEX CONCURRENTLY pg_toast.pg_toast_1260_index; -- no catalog toast index
 ERROR:  cannot reindex system catalogs concurrently
 REINDEX SYSTEM CONCURRENTLY postgres; -- not allowed for SYSTEM
-ERROR:  syntax error at or near "CONCURRENTLY"
-LINE 1: REINDEX SYSTEM CONCURRENTLY postgres;
-                       ^
+ERROR:  cannot reindex system catalogs concurrently
 REINDEX (CONCURRENTLY) SYSTEM postgres; -- ditto
 ERROR:  cannot reindex system catalogs concurrently
 REINDEX (CONCURRENTLY) SYSTEM;  -- ditto
diff --git a/doc/src/sgml/ref/reindex.sgml b/doc/src/sgml/ref/reindex.sgml
index 6750eb6e47..fcbda88149 100644
--- a/doc/src/sgml/ref/reindex.sgml
+++ b/doc/src/sgml/ref/reindex.sgml
@@ -22,8 +22,7 @@ PostgreSQL documentation
  <refsynopsisdiv>
 <synopsis>
 REINDEX [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] { INDEX | TABLE | SCHEMA } [ CONCURRENTLY ] <replaceable class="parameter">name</replaceable>
-REINDEX [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] DATABASE [ CONCURRENTLY ] [ <replaceable class="parameter">name</replaceable> ]
-REINDEX [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] SYSTEM [ <replaceable class="parameter">name</replaceable> ]
+REINDEX [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] { DATABASE | SYSTEM } [ CONCURRENTLY ] [ <replaceable class="parameter">name</replaceable> ]
 
 <phrase>where <replaceable class="parameter">option</replaceable> can be one of:</phrase>
 

Attachment: signature.asc
Description: PGP signature

Reply via email to