Add missing tab completion for VACUUM and ANALYZE with ONLY option

Started by Umar Hayat11 months ago14 messages
#1Umar Hayat
postgresql.wizard@gmail.com
1 attachment(s)

Hi,
Recently the ONLY option is introduced [1]/messages/by-id/CADofcAWATx_haD=QkSxHbnTsAe6+e0Aw8Eh4H8cXyogGvn_kOg@mail.gmail.com for VACUUM and ANALYZE
commands. Attach provides improved tab completion for this new option
for both commands.

Along with this also added starting parenthesis "(" auto-complete as
multiple existing commands provide it and it makes it easier to
separate command options (VERBOSE, FREEZE, ... ) from table list.

[1]: /messages/by-id/CADofcAWATx_haD=QkSxHbnTsAe6+e0Aw8Eh4H8cXyogGvn_kOg@mail.gmail.com

Regards
--
Umar Hayat
Bitnine (https://bitnine.net/)

Attachments:

v0-psql-vacuum-analyze-only-option.patchapplication/octet-stream; name=v0-psql-vacuum-analyze-only-option.patchDownload
From 60e66c0d634d4f917827bf5693e0c3d07b03cbb8 Mon Sep 17 00:00:00 2001
From: Umar Hayat <postgresql.wizard@gmail.com>
Date: Thu, 6 Feb 2025 19:44:16 +0900
Subject: [PATCH] psql: Tab completion for VACUUM and ANALYZE ... ONLY option

Improve psql tab completion for VACUUM and ANALYZE with ONLY option introduced in 62ddf7e
---
 src/bin/psql/tab-complete.in.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 81cbf10aa2..4f36989864 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -3039,12 +3039,12 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
 
 /*
- * ANALYZE [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
- * ANALYZE [ VERBOSE ] [ table_and_columns [, ...] ]
+ * ANALYZE [ ( option [, ...] ) ] [ [ONLY] table_and_columns [, ...] ]
+ * ANALYZE [ VERBOSE ] [ [ONLY] table_and_columns [, ...] ]
  */
 	else if (Matches("ANALYZE"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_analyzables,
-										"VERBOSE");
+										"VERBOSE", "ONLY", "(");
 	else if (HeadMatches("ANALYZE", "(*") &&
 			 !HeadMatches("ANALYZE", "(*)"))
 	{
@@ -3061,8 +3061,10 @@ match_previous_words(int pattern_id,
 	else if (Matches("ANALYZE", MatchAnyN, "("))
 		/* "ANALYZE (" should be caught above, so assume we want columns */
 		COMPLETE_WITH_ATTR(prev2_wd);
-	else if (HeadMatches("ANALYZE"))
+	else if (HeadMatches("ANALYZE") && TailMatches("ONLY"))
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_analyzables);
+	else if (HeadMatches("ANALYZE"))
+		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_analyzables, "ONLY");
 
 /* BEGIN */
 	else if (Matches("BEGIN"))
@@ -5096,30 +5098,35 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH("OPTIONS");
 
 /*
- * VACUUM [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
- * VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ table_and_columns [, ...] ]
+ * VACUUM [ ( option [, ...] ) ] [ [ONLY] table_and_columns [, ...] ]
+ * VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ [ONLY] table_and_columns [, ...] ]
  */
 	else if (Matches("VACUUM"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
 										"FULL",
 										"FREEZE",
 										"ANALYZE",
-										"VERBOSE");
+										"VERBOSE",
+										"ONLY",
+										"(");
 	else if (Matches("VACUUM", "FULL"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
 										"FREEZE",
 										"ANALYZE",
-										"VERBOSE");
+										"VERBOSE",
+										"ONLY");
 	else if (Matches("VACUUM", "FREEZE") ||
 			 Matches("VACUUM", "FULL", "FREEZE"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
 										"VERBOSE",
-										"ANALYZE");
+										"ANALYZE",
+										"ONLY");
 	else if (Matches("VACUUM", "VERBOSE") ||
 			 Matches("VACUUM", "FULL|FREEZE", "VERBOSE") ||
 			 Matches("VACUUM", "FULL", "FREEZE", "VERBOSE"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
-										"ANALYZE");
+										"ANALYZE",
+										"ONLY");
 	else if (HeadMatches("VACUUM", "(*") &&
 			 !HeadMatches("VACUUM", "(*)"))
 	{
@@ -5142,8 +5149,10 @@ match_previous_words(int pattern_id,
 	else if (Matches("VACUUM", MatchAnyN, "("))
 		/* "VACUUM (" should be caught above, so assume we want columns */
 		COMPLETE_WITH_ATTR(prev2_wd);
-	else if (HeadMatches("VACUUM"))
+	else if (HeadMatches("VACUUM") && TailMatches("ONLY"))
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_vacuumables);
+	else if (HeadMatches("VACUUM"))
+		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables, "ONLY");
 
 /* WITH [RECURSIVE] */
 
-- 
2.31.0

#2vignesh C
vignesh21@gmail.com
In reply to: Umar Hayat (#1)
Re: Add missing tab completion for VACUUM and ANALYZE with ONLY option

On Thu, 6 Feb 2025 at 16:29, Umar Hayat <postgresql.wizard@gmail.com> wrote:

Hi,
Recently the ONLY option is introduced [1] for VACUUM and ANALYZE
commands. Attach provides improved tab completion for this new option
for both commands.

Along with this also added starting parenthesis "(" auto-complete as
multiple existing commands provide it and it makes it easier to
separate command options (VERBOSE, FREEZE, ... ) from table list.

This will include "ONLY" also when we display the tables too:
+ else if (HeadMatches("ANALYZE"))
+
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_analyzables,
"ONLY");

like below:
postgres=# analyze only t1
information_schema. ONLY public. t1

The same issue exists with vacuum too:
postgres=# vacuum only t1
information_schema. ONLY public. t1

Regards,
Vignesh

#3vignesh C
vignesh21@gmail.com
In reply to: vignesh C (#2)
1 attachment(s)
Re: Add missing tab completion for VACUUM and ANALYZE with ONLY option

On Thu, 27 Feb 2025 at 11:42, vignesh C <vignesh21@gmail.com> wrote:

On Thu, 6 Feb 2025 at 16:29, Umar Hayat <postgresql.wizard@gmail.com> wrote:

This will include "ONLY" also when we display the tables too:
+ else if (HeadMatches("ANALYZE"))
+
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_analyzables,
"ONLY");

like below:
postgres=# analyze only t1
information_schema. ONLY public. t1

The same issue exists with vacuum too:
postgres=# vacuum only t1
information_schema. ONLY public. t1

The attached patch has the fixes for the above issue.

Regards,
Vignesh

Attachments:

v1-0001-psql-Tab-completion-for-VACUUM-and-ANALYZE-.-ONLY.patchtext/x-patch; charset=US-ASCII; name=v1-0001-psql-Tab-completion-for-VACUUM-and-ANALYZE-.-ONLY.patchDownload
From 305827648a77048b2f1317d5f9632313d77b8b85 Mon Sep 17 00:00:00 2001
From: Umar Hayat <postgresql.wizard@gmail.com>
Date: Thu, 6 Feb 2025 19:44:16 +0900
Subject: [PATCH v1] psql: Tab completion for VACUUM and ANALYZE ... ONLY
 option

Improve psql tab completion for VACUUM and ANALYZE with ONLY option introduced in 62ddf7e
---
 src/bin/psql/tab-complete.in.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 9a4d993e2bc..02d1ab3d9a0 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -3069,12 +3069,12 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
 
 /*
- * ANALYZE [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
- * ANALYZE [ VERBOSE ] [ table_and_columns [, ...] ]
+ * ANALYZE [ ( option [, ...] ) ] [ [ONLY] table_and_columns [, ...] ]
+ * ANALYZE [ VERBOSE ] [ [ONLY] table_and_columns [, ...] ]
  */
 	else if (Matches("ANALYZE"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_analyzables,
-										"VERBOSE");
+										"VERBOSE", "ONLY", "(");
 	else if (HeadMatches("ANALYZE", "(*") &&
 			 !HeadMatches("ANALYZE", "(*)"))
 	{
@@ -5128,30 +5128,35 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH("OPTIONS");
 
 /*
- * VACUUM [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
- * VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ table_and_columns [, ...] ]
+ * VACUUM [ ( option [, ...] ) ] [ [ONLY] table_and_columns [, ...] ]
+ * VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ [ONLY] table_and_columns [, ...] ]
  */
 	else if (Matches("VACUUM"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
 										"FULL",
 										"FREEZE",
 										"ANALYZE",
-										"VERBOSE");
+										"VERBOSE",
+										"ONLY",
+										"(");
 	else if (Matches("VACUUM", "FULL"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
 										"FREEZE",
 										"ANALYZE",
-										"VERBOSE");
+										"VERBOSE",
+										"ONLY");
 	else if (Matches("VACUUM", "FREEZE") ||
 			 Matches("VACUUM", "FULL", "FREEZE"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
 										"VERBOSE",
-										"ANALYZE");
+										"ANALYZE",
+										"ONLY");
 	else if (Matches("VACUUM", "VERBOSE") ||
 			 Matches("VACUUM", "FULL|FREEZE", "VERBOSE") ||
 			 Matches("VACUUM", "FULL", "FREEZE", "VERBOSE"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
-										"ANALYZE");
+										"ANALYZE",
+										"ONLY");
 	else if (HeadMatches("VACUUM", "(*") &&
 			 !HeadMatches("VACUUM", "(*)"))
 	{
-- 
2.43.0

#4Ilia Evdokimov
ilya.evdokimov@tantorlabs.com
In reply to: vignesh C (#3)
Re: Add missing tab completion for VACUUM and ANALYZE with ONLY option

On 18.03.2025 15:25, vignesh C wrote:

On Thu, 27 Feb 2025 at 11:42, vignesh C <vignesh21@gmail.com> wrote:

On Thu, 6 Feb 2025 at 16:29, Umar Hayat <postgresql.wizard@gmail.com> wrote:

This will include "ONLY" also when we display the tables too:
+ else if (HeadMatches("ANALYZE"))
+
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_analyzables,
"ONLY");

like below:
postgres=# analyze only t1
information_schema. ONLY public. t1

The same issue exists with vacuum too:
postgres=# vacuum only t1
information_schema. ONLY public. t1

The attached patch has the fixes for the above issue.

Regards,
Vignesh

Hi,

Thank you for the patch. However, Is it ok if I can't tab 'ONLY' in
VACUUM ANALYZE command?

CREATE TABLE only_parted (a int, b text) PARTITION BY LIST (a);
CREATE TABLE only_parted1 PARTITION OF only_parted FOR VALUES IN (1);
INSERT INTO only_parted VALUES (1, 'a');

VACUUM ANALYZE {Press Tab}

information_schema.  only_parted          only_parted1 public.

-----------------------------------------------------------------------------

Although it works:

postgres=# VACUUM ANALYZE ONLY only_parted;
WARNING:  VACUUM ONLY of partitioned table "only_parted" has no effect
VACUUM
postgres=#

--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC.

#5Ilia Evdokimov
ilya.evdokimov@tantorlabs.com
In reply to: Ilia Evdokimov (#4)
Re: Add missing tab completion for VACUUM and ANALYZE with ONLY option

On 18.03.2025 17:57, Ilia Evdokimov wrote:

Hi,

Thank you for the patch. However, Is it ok if I can't tab 'ONLY' in
VACUUM ANALYZE command?

CREATE TABLE only_parted (a int, b text) PARTITION BY LIST (a);
CREATE TABLE only_parted1 PARTITION OF only_parted FOR VALUES IN (1);
INSERT INTO only_parted VALUES (1, 'a');

VACUUM ANALYZE {Press Tab}

information_schema.  only_parted          only_parted1 public.

-----------------------------------------------------------------------------

Although it works:

postgres=# VACUUM ANALYZE ONLY only_parted;
WARNING:  VACUUM ONLY of partitioned table "only_parted" has no effect
VACUUM
postgres=#

--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC.

Umar, Vignesh, sorry for not adding you to CC earlier!

--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC.

#6vignesh C
vignesh21@gmail.com
In reply to: Ilia Evdokimov (#5)
1 attachment(s)
Re: Add missing tab completion for VACUUM and ANALYZE with ONLY option

On Tue, 18 Mar 2025 at 20:43, Ilia Evdokimov
<ilya.evdokimov@tantorlabs.com> wrote:

On 18.03.2025 17:57, Ilia Evdokimov wrote:

Hi,

Thank you for the patch. However, Is it ok if I can't tab 'ONLY' in
VACUUM ANALYZE command?

How about we handle it like in the attached patch?
Apart from this, similar handling was required for "ANALYZE VERBOSE" also.

Regards,
Vignesh

Attachments:

v2-0001-psql-Tab-completion-for-VACUUM-and-ANALYZE-.-ONLY.patchapplication/octet-stream; name=v2-0001-psql-Tab-completion-for-VACUUM-and-ANALYZE-.-ONLY.patchDownload
From f2cf38691c1741c7b3073f87f31490ee712aedbc Mon Sep 17 00:00:00 2001
From: Umar Hayat <postgresql.wizard@gmail.com>
Date: Thu, 6 Feb 2025 19:44:16 +0900
Subject: [PATCH v2] psql: Tab completion for VACUUM and ANALYZE ... ONLY
 option

Improve psql tab completion for VACUUM and ANALYZE with ONLY option introduced in 62ddf7e

Author: Umar Hayat <postgresql.wizard@gmail.com>
Reviewed-by: Vignesh C <vignesh21@gmail.com>
Reviewed-by: Ilia Evdokimov <ilya.evdokimov@tantorlabs.com>
Discussion: https://www.postgresql.org/message-id/CAD68Dp3L6yW_nWs%2BMWBs6s8tKLRzXaQdQgVRm4byZe0L-hRD8g%40mail.gmail.com
---
 src/bin/psql/tab-complete.in.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 9a4d993e2bc..7052d8df9ad 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -3069,12 +3069,14 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
 
 /*
- * ANALYZE [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
- * ANALYZE [ VERBOSE ] [ table_and_columns [, ...] ]
+ * ANALYZE [ ( option [, ...] ) ] [ [ONLY] table_and_columns [, ...] ]
+ * ANALYZE [ VERBOSE ] [ [ONLY] table_and_columns [, ...] ]
  */
 	else if (Matches("ANALYZE"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_analyzables,
-										"VERBOSE");
+										"VERBOSE", "ONLY", "(");
+	else if (Matches("ANALYZE", "VERBOSE"))
+		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_analyzables, "ONLY");
 	else if (HeadMatches("ANALYZE", "(*") &&
 			 !HeadMatches("ANALYZE", "(*)"))
 	{
@@ -5128,30 +5130,38 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH("OPTIONS");
 
 /*
- * VACUUM [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
- * VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ table_and_columns [, ...] ]
+ * VACUUM [ ( option [, ...] ) ] [ [ONLY] table_and_columns [, ...] ]
+ * VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ [ONLY] table_and_columns [, ...] ]
  */
 	else if (Matches("VACUUM"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
 										"FULL",
 										"FREEZE",
 										"ANALYZE",
-										"VERBOSE");
+										"VERBOSE",
+										"ONLY",
+										"(");
 	else if (Matches("VACUUM", "FULL"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
 										"FREEZE",
 										"ANALYZE",
-										"VERBOSE");
+										"VERBOSE",
+										"ONLY");
+	else if (Matches("VACUUM", "ANALYZE"))
+		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
+										"ONLY");
 	else if (Matches("VACUUM", "FREEZE") ||
 			 Matches("VACUUM", "FULL", "FREEZE"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
 										"VERBOSE",
-										"ANALYZE");
+										"ANALYZE",
+										"ONLY");
 	else if (Matches("VACUUM", "VERBOSE") ||
 			 Matches("VACUUM", "FULL|FREEZE", "VERBOSE") ||
 			 Matches("VACUUM", "FULL", "FREEZE", "VERBOSE"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
-										"ANALYZE");
+										"ANALYZE",
+										"ONLY");
 	else if (HeadMatches("VACUUM", "(*") &&
 			 !HeadMatches("VACUUM", "(*)"))
 	{
-- 
2.43.0

#7Ilia Evdokimov
ilya.evdokimov@tantorlabs.com
In reply to: vignesh C (#6)
Re: Add missing tab completion for VACUUM and ANALYZE with ONLY option

On 19.03.2025 08:12, vignesh C wrote:

How about we handle it like in the attached patch?
Apart from this, similar handling was required for "ANALYZE VERBOSE" also.

Regards,
Vignesh

It would be nice if this works with VACUUM VERBOSE ANALYZE ONLY table;

--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC.

#8vignesh C
vignesh21@gmail.com
In reply to: Ilia Evdokimov (#7)
1 attachment(s)
Re: Add missing tab completion for VACUUM and ANALYZE with ONLY option

On Wed, 19 Mar 2025 at 13:27, Ilia Evdokimov
<ilya.evdokimov@tantorlabs.com> wrote:

It would be nice if this works with VACUUM VERBOSE ANALYZE ONLY table;

Thanks for the comment, here is an updated v3 version with the change
for the same.

Regards,
Vignesh

Attachments:

v3-0001-psql-Tab-completion-for-VACUUM-and-ANALYZE-.-ONLY.patchapplication/octet-stream; name=v3-0001-psql-Tab-completion-for-VACUUM-and-ANALYZE-.-ONLY.patchDownload
From f88737801f84589611e767ebcd1d315f383ea2cf Mon Sep 17 00:00:00 2001
From: Umar Hayat <postgresql.wizard@gmail.com>
Date: Thu, 6 Feb 2025 19:44:16 +0900
Subject: [PATCH v3] psql: Tab completion for VACUUM and ANALYZE ... ONLY
 option

Improve psql tab completion for VACUUM and ANALYZE with ONLY option introduced in 62ddf7e

Author: Umar Hayat <postgresql.wizard@gmail.com>
Reviewed-by: Vignesh C <vignesh21@gmail.com>
Reviewed-by: Ilia Evdokimov <ilya.evdokimov@tantorlabs.com>
Discussion: https://www.postgresql.org/message-id/CAD68Dp3L6yW_nWs%2BMWBs6s8tKLRzXaQdQgVRm4byZe0L-hRD8g%40mail.gmail.com
---
 src/bin/psql/tab-complete.in.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c
index 9a4d993e2bc..b2db8fc9556 100644
--- a/src/bin/psql/tab-complete.in.c
+++ b/src/bin/psql/tab-complete.in.c
@@ -3069,12 +3069,14 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
 
 /*
- * ANALYZE [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
- * ANALYZE [ VERBOSE ] [ table_and_columns [, ...] ]
+ * ANALYZE [ ( option [, ...] ) ] [ [ONLY] table_and_columns [, ...] ]
+ * ANALYZE [ VERBOSE ] [ [ONLY] table_and_columns [, ...] ]
  */
 	else if (Matches("ANALYZE"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_analyzables,
-										"VERBOSE");
+										"VERBOSE", "ONLY", "(");
+	else if (Matches("ANALYZE", "VERBOSE"))
+		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_analyzables, "ONLY");
 	else if (HeadMatches("ANALYZE", "(*") &&
 			 !HeadMatches("ANALYZE", "(*)"))
 	{
@@ -5128,30 +5130,39 @@ match_previous_words(int pattern_id,
 		COMPLETE_WITH("OPTIONS");
 
 /*
- * VACUUM [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
- * VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ table_and_columns [, ...] ]
+ * VACUUM [ ( option [, ...] ) ] [ [ONLY] table_and_columns [, ...] ]
+ * VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ [ONLY] table_and_columns [, ...] ]
  */
 	else if (Matches("VACUUM"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
 										"FULL",
 										"FREEZE",
 										"ANALYZE",
-										"VERBOSE");
+										"VERBOSE",
+										"ONLY",
+										"(");
 	else if (Matches("VACUUM", "FULL"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
 										"FREEZE",
 										"ANALYZE",
-										"VERBOSE");
+										"VERBOSE",
+										"ONLY");
+	else if (Matches("VACUUM", "ANALYZE") ||
+			 Matches("VACUUM", "VERBOSE", "ANALYZE"))
+		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
+										"ONLY");
 	else if (Matches("VACUUM", "FREEZE") ||
 			 Matches("VACUUM", "FULL", "FREEZE"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
 										"VERBOSE",
-										"ANALYZE");
+										"ANALYZE",
+										"ONLY");
 	else if (Matches("VACUUM", "VERBOSE") ||
 			 Matches("VACUUM", "FULL|FREEZE", "VERBOSE") ||
 			 Matches("VACUUM", "FULL", "FREEZE", "VERBOSE"))
 		COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_vacuumables,
-										"ANALYZE");
+										"ANALYZE",
+										"ONLY");
 	else if (HeadMatches("VACUUM", "(*") &&
 			 !HeadMatches("VACUUM", "(*)"))
 	{
-- 
2.43.0

#9Ilia Evdokimov
ilya.evdokimov@tantorlabs.com
In reply to: vignesh C (#6)
Re: Add missing tab completion for VACUUM and ANALYZE with ONLY option

On 19.03.2025 08:12, vignesh C wrote:

How about we handle it like in the attached patch?
Apart from this, similar handling was required for "ANALYZE VERBOSE" also.

Looks good overall. However, after pressing Tab, ONLY appears in the
completion list, but it doesn't autocomplete after typing the first letter.

--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC.

#10vignesh C
vignesh21@gmail.com
In reply to: Ilia Evdokimov (#9)
Re: Add missing tab completion for VACUUM and ANALYZE with ONLY option

On Wed, 19 Mar 2025 at 14:46, Ilia Evdokimov
<ilya.evdokimov@tantorlabs.com> wrote:

Looks good overall. However, after pressing Tab, ONLY appears in the completion list, but it doesn't autocomplete after typing the first letter.

In which case you noticed this?

Regards,
Vignesh

#11Ilia Evdokimov
ilya.evdokimov@tantorlabs.com
In reply to: vignesh C (#10)
Re: Add missing tab completion for VACUUM and ANALYZE with ONLY option

On 19.03.2025 12:55, vignesh C wrote:

Looks good overall. However, after pressing Tab, ONLY appears in the completion list, but it doesn't autocomplete after typing the first letter.

In which case you noticed this?

Ah, I just tested it using these examples from the regression tests:

CREATE TABLE only_parted (a int, b text) PARTITION BY LIST (a);
CREATE TABLE only_parted1 PARTITION OF only_parted FOR VALUES IN (1);

ONLY doesn't autocomplete here because the table names begin with
"only...", which conflicts with autocompletion—this was my oversight.

----------

Everything seems fine with the ANALYZE command autocompletion. Regarding
VACUUM, I'm not entirely convinced we should provide autocompletion in
every case. I'd prefer to keep the behavior from the v3 patch because
the original intention behind adding the ONLY keyword was specifically
for collecting statistics exclusively from parent tables. Therefore,
autocompletion makes sense primarily for the ANALYZE case.

Any thoughts?

--
Best regaards,
Ilia Evdokimov,
Tantor Labs LLC.

#12David Rowley
dgrowleyml@gmail.com
In reply to: Ilia Evdokimov (#11)
Re: Add missing tab completion for VACUUM and ANALYZE with ONLY option

On Wed, 19 Mar 2025 at 23:22, Ilia Evdokimov
<ilya.evdokimov@tantorlabs.com> wrote:

Everything seems fine with the ANALYZE command autocompletion. Regarding VACUUM, I'm not entirely convinced we should provide autocompletion in every case. I'd prefer to keep the behavior from the v3 patch because the original intention behind adding the ONLY keyword was specifically for collecting statistics exclusively from parent tables. Therefore, autocompletion makes sense primarily for the ANALYZE case.

While VACUUM ONLY on a partitioned table has no effect, the same isn't
true for inheritance parents. 62ddf7ee9 did change the behaviour of
VACUUM for these so that vacuuming the inheritance parent now vacuums
all of its children, unless ONLY is used. So, I'd say if the tab
completion is only added to ANALYZE, then it'd be incomplete still.
(I've not looked at the v3 patch to see which of those it handles.)

David

#13vignesh C
vignesh21@gmail.com
In reply to: David Rowley (#12)
Re: Add missing tab completion for VACUUM and ANALYZE with ONLY option

On Wed, 19 Mar 2025 at 18:12, David Rowley <dgrowleyml@gmail.com> wrote:

On Wed, 19 Mar 2025 at 23:22, Ilia Evdokimov
<ilya.evdokimov@tantorlabs.com> wrote:

Everything seems fine with the ANALYZE command autocompletion. Regarding VACUUM, I'm not entirely convinced we should provide autocompletion in every case. I'd prefer to keep the behavior from the v3 patch because the original intention behind adding the ONLY keyword was specifically for collecting statistics exclusively from parent tables. Therefore, autocompletion makes sense primarily for the ANALYZE case.

While VACUUM ONLY on a partitioned table has no effect, the same isn't
true for inheritance parents. 62ddf7ee9 did change the behaviour of
VACUUM for these so that vacuuming the inheritance parent now vacuums
all of its children, unless ONLY is used. So, I'd say if the tab
completion is only added to ANALYZE, then it'd be incomplete still.
(I've not looked at the v3 patch to see which of those it handles.)

I also felt it is necessary for both ANALYZE and VACUUM, and the v3
patch includes changes for both.

Regards,
Vignesh

#14Tom Lane
tgl@sss.pgh.pa.us
In reply to: vignesh C (#13)
Re: Add missing tab completion for VACUUM and ANALYZE with ONLY option

vignesh C <vignesh21@gmail.com> writes:

On Wed, 19 Mar 2025 at 18:12, David Rowley <dgrowleyml@gmail.com> wrote:

While VACUUM ONLY on a partitioned table has no effect, the same isn't
true for inheritance parents. 62ddf7ee9 did change the behaviour of
VACUUM for these so that vacuuming the inheritance parent now vacuums
all of its children, unless ONLY is used. So, I'd say if the tab
completion is only added to ANALYZE, then it'd be incomplete still.
(I've not looked at the v3 patch to see which of those it handles.)

I also felt it is necessary for both ANALYZE and VACUUM, and the v3
patch includes changes for both.

Agreed.

Pushed with some cosmetic adjustments. I made the order of the
options match the syntax diagrams in the comments, which is just
neatnik-ism (it changes no behavior) but seemed to read better.
I also realized that we could simplify the match patterns for the
various VACUUM cases by using MatchAnyN --- the existing code was
getting rather contorted there. That wasn't something your patch
introduced, but might as well fix it while we're here.

regards, tom lane