Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fjwH1-0002fB-QO for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Jul 2018 00:42:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fjwGz-0008QI-4G for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Jul 2018 00:42:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fjwGy-0008Q5-PG for pgsql-hackers@lists.postgresql.org; Mon, 30 Jul 2018 00:42:52 +0000 Received: from mail-io0-x235.google.com ([2607:f8b0:4001:c06::235]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fjwGu-0006N0-Ec for pgsql-hackers@postgresql.org; Mon, 30 Jul 2018 00:42:52 +0000 Received: by mail-io0-x235.google.com with SMTP id z20-v6so8491152iol.0 for ; Sun, 29 Jul 2018 17:42:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=8LZunVuXoj/PL1YWDp1AUsPgqLm/GqIHrfzNJdPnKaw=; b=qPnieQFI+r4p/bBPpnvuVqTheF+pfYPHZXCZe+xCWwIZ+ZM6ArcITRtt3SXTooe42i R8jiL5dLcmLTi4X9Swc7Nl84pvRBADADYlIjzv95Y/WtOUfh29Orw5smGwwPSydVpIOM eWHZKdIgroSeCAqyyUCG/DjLhIeSU8QWQmRqr5Fxj5aMUwdIpikxK0VEHBiwGqLBgLG2 CiWsPFvuG6kn1E9TONI2As6K8ro8pFf4Eg7NWXDWSXws4nni4xIbjn3LfePL3GBwsJZb lufqyF04+dDOupbSbgrPTwLoBg31SKLzN4LwgIMO9NlHU4CXYm5jkndCrEymmq02MhkS CP3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=8LZunVuXoj/PL1YWDp1AUsPgqLm/GqIHrfzNJdPnKaw=; b=ca4YEfQmhuube8ap9BS/dIRheCaltpWqhQycHXdLipnwxT69EpKh40kxXLgLDcn220 uVFvB9z2iXQSbIgIHko2DHgWZ4odIujjYliVvpLQMNozZHOOsDrwxgyfduwBXfXL3u9k uTjZgQp9P1GSETbYzTmHOBxlQdku9AKH9We/OYptw4cQGW6bG6JT9JpivEoOo2jpY7a5 w7ZmWBlusxOfWLuKz/xYQg2AWx5a5Yx9UxbkpMcBN6vS7CFwClPBwcy9JdjpOMbwjlZH l0rN2dPlIBS8ud4E0imZQEsfTwXnR3NzGFv2zCqN9ktYRLu9SbRr5Cml+Ssam2gQ6dYa LheA== X-Gm-Message-State: AOUpUlHtBQvFl+fWs1vlVBwiiW1FetA4iO9wFxRqr/I1oHHr57IdUePu IFJFbxO/V5AnwiVAkm9u35s6Dg== X-Google-Smtp-Source: AAOMgpe+3+q/2c0b9x4WvG6cHIVtBUeIbLkg4uxnPredFAl9rPfieqeMpwvOXtWBenEf0jn8oXiNIg== X-Received: by 2002:a6b:1491:: with SMTP id 139-v6mr12578821iou.103.1532911365493; Sun, 29 Jul 2018 17:42:45 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id 134-v6sm5927478itw.23.2018.07.29.17.42.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Jul 2018 17:42:44 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 52192800E1C; Sun, 29 Jul 2018 19:42:43 -0500 (CDT) Date: Sun, 29 Jul 2018 19:42:43 -0500 From: Justin Pryzby To: Arthur Zakirov Cc: Edmund Horner , PostgreSQL Hackers Subject: Re: adding tab completions Message-ID: <20180730004243.GE3222@telsasoft.com> References: <20180529141227.ygpfqiat5rzikjzx@alvherre.pgsql> <20180529092726.GA6535@zakirov.localdomain> <20180603231859.GV5164@telsasoft.com> <20180604033922.GW5164@telsasoft.com> <20180605142941.GA25460@zakirov.localdomain> <20180609234212.GT10885@telsasoft.com> <20180611203547.GA18675@artur-book.localdomain> <20180627201051.GG3554@telsasoft.com> <20180628112037.GA6937@zakirov.localdomain> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="EuxKj2iCbKjpUGkD" Content-Disposition: inline In-Reply-To: <20180628112037.GA6937@zakirov.localdomain> User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --EuxKj2iCbKjpUGkD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --EuxKj2iCbKjpUGkD Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v11-tab-complete-partitions 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 */ --EuxKj2iCbKjpUGkD--