From 854dd8cff523bc17972d34772b0e39ad3d6d46a4 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Mon, 5 Mar 2018 16:21:05 -0800 Subject: [PATCH] Add parenthesized options syntax for ANALYZE. 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 | 14 +++++++++++++- src/backend/parser/gram.y | 17 +++++++++++++++++ src/test/regress/expected/vacuum.out | 7 +++++++ src/test/regress/sql/vacuum.sql | 4 ++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/doc/src/sgml/ref/analyze.sgml b/doc/src/sgml/ref/analyze.sgml index 83b07a0300..10b3a9a673 100644 --- a/doc/src/sgml/ref/analyze.sgml +++ b/doc/src/sgml/ref/analyze.sgml @@ -21,9 +21,14 @@ PostgreSQL documentation +ANALYZE [ ( option [, ...] ) ] [ table_and_columns [, ...] ] ANALYZE [ VERBOSE ] [ table_and_columns [, ...] ] -where table_and_columns is: +where option can be one of: + + VERBOSE + +and table_and_columns is: table_name [ ( column_name [, ...] ) ] @@ -49,6 +54,13 @@ ANALYZE [ VERBOSE ] [ table_and_columns + + + When the option list is surrounded by parentheses, the options can be + written in any order. The parenthesized syntax was added in + PostgreSQL 11; the unparenthesized syntax + is deprecated. + diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 8a2e52acb4..06c03dff3c 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -306,6 +306,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); %type opt_lock lock_type cast_context %type vacuum_option_list vacuum_option_elem + analyze_option_list analyze_option_elem %type 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: diff --git a/src/test/regress/expected/vacuum.out b/src/test/regress/expected/vacuum.out index c440c7ea58..d66e2aa3b7 100644 --- a/src/test/regress/expected/vacuum.out +++ b/src/test/regress/expected/vacuum.out @@ -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; diff --git a/src/test/regress/sql/vacuum.sql b/src/test/regress/sql/vacuum.sql index 92eaca2a93..275ce2e270 100644 --- a/src/test/regress/sql/vacuum.sql +++ b/src/test/regress/sql/vacuum.sql @@ -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;