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 1fNS9p-0004F8-Vy for pgsql-hackers@arkaria.postgresql.org; Tue, 29 May 2018 00:06:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fNS9o-00061y-M8 for pgsql-hackers@arkaria.postgresql.org; Tue, 29 May 2018 00:06:32 +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 1fNS9o-00061o-CC for pgsql-hackers@lists.postgresql.org; Tue, 29 May 2018 00:06:32 +0000 Received: from mail-it0-x233.google.com ([2607:f8b0:4001:c0b::233]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fNS9k-00084x-GP for pgsql-hackers@postgresql.org; Tue, 29 May 2018 00:06:31 +0000 Received: by mail-it0-x233.google.com with SMTP id q4-v6so16469442ite.3 for ; Mon, 28 May 2018 17:06:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=pSFL1SBDIgoHXaUYjyEt3ufy2fLcylw/Pk1yMNNnYRM=; b=wWVz9hSqlsXUUUbmgEami/Ci4oKqV/S0Kp0Y3JnyLYCZvV9TMn1Afp3Z/c34HDZxqE 31CSF4lZUB2zxcE5uDJMF96CsqiFoRqOyZ4pEyeCFFtuXUVxiDJWcpQd6DKY7NWSuw5G DaM+ijK+uR/mhEj2GrEqO/1Tpkv6zim+TbLFE5ghECwKirFcLne7GpEuUVcZIYbbSVbC 2NnNWjK6AA5zOHpIrB9JMQGt7l2+elDXm3R8PBYjMQ/r6FTnB5MZS6F2HBG4dAjY6zkv IL9dHIDNFmPDKt1BNoDjIDnKPcY5TVI7TFa4wT0uikMVQIwG6Q1ayg0dOwRwQ0uoFWzc cJUQ== 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:subject:message-id:mime-version :content-disposition:user-agent; bh=pSFL1SBDIgoHXaUYjyEt3ufy2fLcylw/Pk1yMNNnYRM=; b=Z+RWuolqEHytHJbjHDYC9sS8c6OnUu3Ka6GW9dXcbZhmjvI69TcP8SKlDN/MDnJI7W F0oWKwNIBshbWVv03KtqE2qa+xFPJfEGgYg33xdWQPekPEgXt7i+2/9qMTYLGHs6i+nh Kj/GjjYMvLcYFsx2gz18iqGMVfdfmSGEAitIOBcIDthvRigoyiplccJRQzYoE6VcaYMZ K8w4URRfyPShOxLL7LNoszG9BB+etm8DrFpm4CBApBJM336TDG03G006jmKrrj/M0J5c T0QXdlpehAEdXYl4tGGVoZ3qU5kGbwUBr2ZsZYyogVEl6KvTYw3Rlq5tG+eC3u9L1hz8 rdQQ== X-Gm-Message-State: ALKqPwdFA0qrVb79mVUxh+vRyDBWEorQvonOUhT+KdJskI3sHCdvNerr NiO311ZuRHWQNn/GKSRrjoAEECQVbxA= X-Google-Smtp-Source: ADUXVKIDA5Zt0L8Za8vMygGUl/YX30VU+ZYeM9CzmvMEK/avm4TxFfQnB3hYtQTIHZ3Qlv5l4UWUdA== X-Received: by 2002:a24:b510:: with SMTP id v16-v6mr13102751ite.87.1527552385137; Mon, 28 May 2018 17:06:25 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id e204-v6sm5320931ioa.34.2018.05.28.17.06.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 May 2018 17:06:24 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 6108D8019C8; Mon, 28 May 2018 19:06:23 -0500 (CDT) Date: Mon, 28 May 2018 19:06:23 -0500 From: Justin Pryzby To: PostgreSQL Hackers Subject: adding tab completions Message-ID: <20180529000623.GA21896@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="d6Gm4EdcadzBjdND" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --d6Gm4EdcadzBjdND Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --d6Gm4EdcadzBjdND Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-tab-complete-partitions 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 */ --d6Gm4EdcadzBjdND--