pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Justin Pryzby <pryzby@telsasoft.com>
To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: adding tab completions
Date: Mon, 28 May 2018 19:06:23 -0500
Message-ID: <20180529000623.GA21896@telsasoft.com> (raw)

Find attached tab completion for the following:

"... Also, recursively perform VACUUM and ANALYZE on partitions when the
command is applied to a partitioned table."
3c3bb99330aa9b4c2f6258bfa0265d806bf365c3

Add parenthesized options syntax for ANALYZE.
854dd8cff523bc17972d34772b0e39ad3d6d46a4

Add VACUUM (DISABLE_PAGE_SKIPPING) for emergencies.
ede62e56fbe809baa1a7bc3873d82f12ffe7540b

Allow multiple tables to be specified in one VACUUM or ANALYZE command.
11d8d72c27a64ea4e30adce11cf6c4f3dd3e60db
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 7bb47ea..2d7b264 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -717,6 +717,26 @@ static const SchemaQuery Query_for_list_of_tmf = {
 	NULL
 };
 
+static const SchemaQuery Query_for_list_of_tpmf = {
+	/* min_server_version */
+	0,
+	/* catname */
+	"pg_catalog.pg_class c",
+	/* selcondition */
+	"c.relkind IN (" CppAsString2(RELKIND_RELATION) ", "
+	CppAsString2(RELKIND_MATVIEW) ", "
+	CppAsString2(RELKIND_PARTITIONED_TABLE) ", "
+	CppAsString2(RELKIND_FOREIGN_TABLE) ")",
+	/* viscondition */
+	"pg_catalog.pg_table_is_visible(c.oid)",
+	/* namespace */
+	"c.relnamespace",
+	/* result */
+	"pg_catalog.quote_ident(c.relname)",
+	/* qualresult */
+	NULL
+};
+
 static const SchemaQuery Query_for_list_of_tpm = {
 	/* min_server_version */
 	0,
@@ -3563,33 +3583,41 @@ psql_completion(const char *text, int start, int end)
 		COMPLETE_WITH_CONST("OPTIONS");
 
 /*
- * VACUUM [ FULL | FREEZE ] [ VERBOSE ] [ table ]
- * VACUUM [ FULL | FREEZE ] [ VERBOSE ] ANALYZE [ table [ (column [, ...] ) ] ]
+ * VACUUM [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
+ * VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ table_and_columns [, ...] ]
  */
 	else if (Matches1("VACUUM"))
-		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf,
 								   " UNION SELECT 'FULL'"
 								   " UNION SELECT 'FREEZE'"
 								   " UNION SELECT 'ANALYZE'"
+								   " UNION SELECT '('"
 								   " UNION SELECT 'VERBOSE'");
-	else if (Matches2("VACUUM", "FULL|FREEZE"))
-		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
+	else if (Matches2("VACUUM", "FULL"))
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf,
+								   " UNION SELECT 'FREEZE'"
 								   " UNION SELECT 'ANALYZE'"
 								   " UNION SELECT 'VERBOSE'");
-	else if (Matches3("VACUUM", "FULL|FREEZE", "ANALYZE"))
-		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
+	else if (Matches3("VACUUM", "FULL|FREEZE|FULL FREEZE", "ANALYZE"))
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf,
 								   " UNION SELECT 'VERBOSE'");
-	else if (Matches3("VACUUM", "FULL|FREEZE", "VERBOSE"))
-		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
+	else if (Matches3("VACUUM", "FULL|FREEZE|FULL FREEZE", "VERBOSE"))
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf,
 								   " UNION SELECT 'ANALYZE'");
 	else if (Matches2("VACUUM", "VERBOSE"))
-		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf,
 								   " UNION SELECT 'ANALYZE'");
 	else if (Matches2("VACUUM", "ANALYZE"))
-		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf,
 								   " UNION SELECT 'VERBOSE'");
+	else if (HeadMatches2("VACUUM", "(") && !ends_with(prev_wd, ',') && !ends_with(prev_wd, '('))
+			COMPLETE_WITH_LIST2(",", ")");
+	else if (HeadMatches2("VACUUM", "(") && !ends_with(prev_wd, ')'))
+			COMPLETE_WITH_LIST5("FULL", "FREEZE", "ANALYZE", "VERBOSE", "DISABLE_PAGE_SKIPPING" );
+	else if (HeadMatches1("VACUUM") && !ends_with(prev_wd, ',') && !ends_with(prev_wd, ')'))
+			COMPLETE_WITH_CONST(",");
 	else if (HeadMatches1("VACUUM"))
-		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, NULL);
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf, NULL);
 
 /* WITH [RECURSIVE] */
 
@@ -3600,10 +3628,24 @@ psql_completion(const char *text, int start, int end)
 	else if (Matches1("WITH"))
 		COMPLETE_WITH_CONST("RECURSIVE");
 
-/* ANALYZE */
+/*
+ * ANALYZE [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
+ * ANALYZE [ VERBOSE ] [ table_and_columns [, ...] ]
+ */
 	/* Complete with list of tables */
+	else if (Matches2("ANALYZE", "("))
+		COMPLETE_WITH_CONST("VERBOSE)");
 	else if (Matches1("ANALYZE"))
-		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tmf, NULL);
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf,
+				" UNION SELECT 'VERBOSE'"
+				" UNION SELECT '('"
+				);
+	else if (HeadMatches1("ANALYZE") &&
+			!ends_with(prev_wd, ',') &&
+			!strcasecmp(prev_wd, "VERBOSE"))
+			COMPLETE_WITH_CONST(",");
+	else if (HeadMatches1("ANALYZE"))
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf, NULL);
 
 /* WHERE */
 	/* Simple case of the word before the where being the table name */

Attachments:

v1-tab-complete-partitions (text/plain, 4.2K) download diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 7bb47ea..2d7b264 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -717,6 +717,26 @@ static const SchemaQuery Query_for_list_of_tmf = { NULL }; +static const SchemaQuery Query_for_list_of_tpmf = { + /* min_server_version */ + 0, + /* catname */ + "pg_catalog.pg_class c", + /* selcondition */ + "c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_PARTITIONED_TABLE) ", " + CppAsString2(RELKIND_FOREIGN_TABLE) ")", + /* viscondition */ + "pg_catalog.pg_table_is_visible(c.oid)", + /* namespace */ + "c.relnamespace", + /* result */ + "pg_catalog.quote_ident(c.relname)", + /* qualresult */ + NULL +}; + static const SchemaQuery Query_for_list_of_tpm = { /* min_server_version */ 0, @@ -3563,33 +3583,41 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH_CONST("OPTIONS"); /* - * VACUUM [ FULL | FREEZE ] [ VERBOSE ] [ table ] - * VACUUM [ FULL | FREEZE ] [ VERBOSE ] ANALYZE [ table [ (column [, ...] ) ] ] + * VACUUM [ ( option [, ...] ) ] [ table_and_columns [, ...] ] + * VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ table_and_columns [, ...] ] */ else if (Matches1("VACUUM")) - COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf, " UNION SELECT 'FULL'" " UNION SELECT 'FREEZE'" " UNION SELECT 'ANALYZE'" + " UNION SELECT '('" " UNION SELECT 'VERBOSE'"); - else if (Matches2("VACUUM", "FULL|FREEZE")) - COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, + else if (Matches2("VACUUM", "FULL")) + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf, + " UNION SELECT 'FREEZE'" " UNION SELECT 'ANALYZE'" " UNION SELECT 'VERBOSE'"); - else if (Matches3("VACUUM", "FULL|FREEZE", "ANALYZE")) - COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, + else if (Matches3("VACUUM", "FULL|FREEZE|FULL FREEZE", "ANALYZE")) + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf, " UNION SELECT 'VERBOSE'"); - else if (Matches3("VACUUM", "FULL|FREEZE", "VERBOSE")) - COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, + else if (Matches3("VACUUM", "FULL|FREEZE|FULL FREEZE", "VERBOSE")) + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf, " UNION SELECT 'ANALYZE'"); else if (Matches2("VACUUM", "VERBOSE")) - COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf, " UNION SELECT 'ANALYZE'"); else if (Matches2("VACUUM", "ANALYZE")) - COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf, " UNION SELECT 'VERBOSE'"); + else if (HeadMatches2("VACUUM", "(") && !ends_with(prev_wd, ',') && !ends_with(prev_wd, '(')) + COMPLETE_WITH_LIST2(",", ")"); + else if (HeadMatches2("VACUUM", "(") && !ends_with(prev_wd, ')')) + COMPLETE_WITH_LIST5("FULL", "FREEZE", "ANALYZE", "VERBOSE", "DISABLE_PAGE_SKIPPING" ); + else if (HeadMatches1("VACUUM") && !ends_with(prev_wd, ',') && !ends_with(prev_wd, ')')) + COMPLETE_WITH_CONST(","); else if (HeadMatches1("VACUUM")) - COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, NULL); + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf, NULL); /* WITH [RECURSIVE] */ @@ -3600,10 +3628,24 @@ psql_completion(const char *text, int start, int end) else if (Matches1("WITH")) COMPLETE_WITH_CONST("RECURSIVE"); -/* ANALYZE */ +/* + * ANALYZE [ ( option [, ...] ) ] [ table_and_columns [, ...] ] + * ANALYZE [ VERBOSE ] [ table_and_columns [, ...] ] + */ /* Complete with list of tables */ + else if (Matches2("ANALYZE", "(")) + COMPLETE_WITH_CONST("VERBOSE)"); else if (Matches1("ANALYZE")) - COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tmf, NULL); + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf, + " UNION SELECT 'VERBOSE'" + " UNION SELECT '('" + ); + else if (HeadMatches1("ANALYZE") && + !ends_with(prev_wd, ',') && + !strcasecmp(prev_wd, "VERBOSE")) + COMPLETE_WITH_CONST(","); + else if (HeadMatches1("ANALYZE")) + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpmf, NULL); /* WHERE */ /* Simple case of the word before the where being the table name */

view thread (16+ messages)  latest in thread

Message-ID: <20180529000623.GA21896@telsasoft.com>
Permalink:  ../20180529000623.GA21896@telsasoft.com/
Also on:    postgresql.org/message-id/20180529000623.GA21896@telsasoft.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: pryzby@telsasoft.com
  Subject: Re: adding tab completions
  In-Reply-To: <20180529000623.GA21896@telsasoft.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox