Sorry for the delay..this got lost while catching up after being out of town..
On Thu, Jun 28, 2018 at 02:20:39PM +0300, Arthur Zakirov wrote:
> Thank you for the new version.
>
> On Wed, Jun 27, 2018 at 03:10:51PM -0500, Justin Pryzby wrote:
> > Thanks - I've done this in the attached. It works well for having minimal
> > logic.
>
> I think everthing is OK. But I didn't notice in previous version of the
> patch that there is no braces in EXPLAIN and VACUUM conditions. I attached
> diff file to show it.
>
> Also I included TEXT, XML, JSON, YAML items for FORMAT option in the
> diff file. The patch shows ",", ")", "ON", "OFF" for all options, but
> FORMAT requires format type to be specified. Please consider this change
> only as a suggestion.
Your suggestion is good, so attached updated patch.
> > Actually..another thought: since toast tables may be VACUUM-ed, should I
> > introduce Query_for_list_of_tpmt ?
I didn't include this one yet though.
Feel free to bump to next CF.
Justin
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 7bb47ea..1d235a3 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -705,6 +705,7 @@ static const SchemaQuery Query_for_list_of_tmf = {
"pg_catalog.pg_class c",
/* selcondition */
"c.relkind IN (" CppAsString2(RELKIND_RELATION) ", "
+ CppAsString2(RELKIND_PARTITIONED_TABLE) ", "
CppAsString2(RELKIND_MATVIEW) ", "
CppAsString2(RELKIND_FOREIGN_TABLE) ")",
/* viscondition */
@@ -2222,6 +2223,7 @@ psql_completion(const char *text, int start, int end)
"fillfactor",
"parallel_workers",
"log_autovacuum_min_duration",
+ "toast_tuple_target",
"toast.autovacuum_enabled",
"toast.autovacuum_freeze_max_age",
"toast.autovacuum_freeze_min_age",
@@ -2703,7 +2705,7 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_LIST2("TABLE", "MATERIALIZED VIEW");
/* Complete PARTITION BY with RANGE ( or LIST ( or ... */
else if (TailMatches2("PARTITION", "BY"))
- COMPLETE_WITH_LIST2("RANGE (", "LIST (");
+ COMPLETE_WITH_LIST3("RANGE (", "LIST (", "HASH (");
/* If we have xxx PARTITION OF, provide a list of partitioned tables */
else if (TailMatches2("PARTITION", "OF"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_partitioned_tables, "");
@@ -2996,14 +2998,27 @@ psql_completion(const char *text, int start, int end)
else if (Matches1("EXECUTE"))
COMPLETE_WITH_QUERY(Query_for_list_of_prepared_statements);
-/* EXPLAIN */
-
- /*
- * Complete EXPLAIN [ANALYZE] [VERBOSE] with list of EXPLAIN-able
commands
- */
+/*
+ * EXPLAIN [ ( option [, ...] ) ] statement
+ * EXPLAIN [ ANALYZE ] [ VERBOSE ] statement
+ */
else if (Matches1("EXPLAIN"))
- COMPLETE_WITH_LIST7("SELECT", "INSERT", "DELETE", "UPDATE",
"DECLARE",
- "ANALYZE", "VERBOSE");
+ COMPLETE_WITH_LIST8("SELECT", "INSERT", "DELETE", "UPDATE",
"DECLARE",
+ "ANALYZE", "VERBOSE",
"(");
+ else if (HeadMatches2("EXPLAIN", "("))
+ {
+ if (ends_with(prev_wd, '(') || ends_with(prev_wd, ','))
+ COMPLETE_WITH_LIST7("ANALYZE", "VERBOSE", "COSTS",
"BUFFERS", "TIMING", "SUMMARY", "FORMAT");
+ else if (TailMatches1("FORMAT"))
+ COMPLETE_WITH_LIST4("TEXT", "XML", "JSON", "YAML");
+ else if
(TailMatches1("ANALYZE|VERBOSE|COSTS|BUFFERS|TIMING|SUMMARY"))
+ COMPLETE_WITH_LIST4(",", ")", "ON", "OFF");
+ else
+ COMPLETE_WITH_LIST2(",", ")");
+ }
+ else if (HeadMatches2("EXPLAIN", MatchAny) && ends_with(prev_wd, ')'))
+ /* If the parenthesis are balanced, the list is apparently
parsed as a single word */
+ COMPLETE_WITH_LIST5("SELECT", "INSERT", "DELETE", "UPDATE",
"DECLARE");
else if (Matches2("EXPLAIN", "ANALYZE"))
COMPLETE_WITH_LIST6("SELECT", "INSERT", "DELETE", "UPDATE",
"DECLARE",
"VERBOSE");
@@ -3563,33 +3578,48 @@ 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_tpm,
" UNION
SELECT 'FULL'"
" UNION
SELECT 'FREEZE'"
" UNION
SELECT 'ANALYZE'"
" 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_tpm,
+ " 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,
- " UNION
SELECT 'VERBOSE'");
- else if (Matches3("VACUUM", "FULL|FREEZE", "VERBOSE"))
- COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
+ else if (Matches2("VACUUM", "FULL|FREEZE") ||
+ Matches3("VACUUM", "FULL", "FREEZE"))
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpm,
+ " UNION
SELECT 'VERBOSE'"
" UNION
SELECT 'ANALYZE'");
- else if (Matches2("VACUUM", "VERBOSE"))
- COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
+ else if (Matches2("VACUUM", "VERBOSE") ||
+ Matches3("VACUUM", "FULL|FREEZE",
"VERBOSE") ||
+ Matches4("VACUUM", "FULL", "FREEZE",
"VERBOSE"))
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpm,
" UNION
SELECT 'ANALYZE'");
- else if (Matches2("VACUUM", "ANALYZE"))
- COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm,
- " UNION
SELECT 'VERBOSE'");
+ else if (HeadMatches2("VACUUM", "("))
+ {
+ if (ends_with(prev_wd, ',') || ends_with(prev_wd, '('))
+ COMPLETE_WITH_LIST5("FULL", "FREEZE", "ANALYZE",
"VERBOSE", "DISABLE_PAGE_SKIPPING");
+ else
+ COMPLETE_WITH_LIST2(",", ")");
+ }
+ else if (HeadMatches1("VACUUM") && TailMatches1("("))
+ /* "VACUUM (" should be caught above */
+ COMPLETE_WITH_ATTR(prev2_wd, "");
+ else if (HeadMatches2("VACUUM", MatchAny) && !ends_with(prev_wd, ',') &&
+ !TailMatches1("ANALYZE") &&
+ !(previous_words_count==2 && prev_wd[0]=='(' &&
ends_with(prev_wd, ')')))
+ /* Comma to support vacuuming multiple tables */
+ /* Parens to support analyzing a partial column list */
+ COMPLETE_WITH_LIST3(",", "(", ")");
else if (HeadMatches1("VACUUM"))
- COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, NULL);
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tpm, "");
/* WITH [RECURSIVE] */
@@ -3600,9 +3630,28 @@ psql_completion(const char *text, int start, int end)
else if (Matches1("WITH"))
COMPLETE_WITH_CONST("RECURSIVE");
-/* ANALYZE */
- /* Complete with list of tables */
+/*
+ * ANALYZE [ ( option [, ...] ) ] [ table_and_columns [, ...] ]
+ * ANALYZE [ VERBOSE ] [ table_and_columns [, ...] ]
+ */
+ else if (Matches2("ANALYZE", "("))
+ COMPLETE_WITH_CONST("VERBOSE)");
else if (Matches1("ANALYZE"))
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tmf,
+ " UNION SELECT 'VERBOSE'"
+ " UNION SELECT '('"
+ );
+ else if (HeadMatches1("ANALYZE") && TailMatches1("("))
+ /* "ANALYZE (" should be caught above */
+ COMPLETE_WITH_ATTR(prev2_wd, "");
+ else if (HeadMatches2("ANALYZE", MatchAny) &&
+ !ends_with(prev_wd, ',') &&
+ !(previous_words_count==2 &&
prev_wd[0]=='(' && ends_with(prev_wd, ')')) &&
+ !TailMatches1("VERBOSE"))
+ /* Support analyze of multiple tables */
+ /* or analyze table(column1, column2) */
+ COMPLETE_WITH_LIST3(",", "(", ")");
+ else if (HeadMatches1("ANALYZE"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tmf, NULL);
/* WHERE */