Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kqJd7-0006Ov-JG for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Dec 2020 17:33:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kqJd4-000806-OZ for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Dec 2020 17:33:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kqJd4-0007zy-Bq for pgsql-hackers@lists.postgresql.org; Fri, 18 Dec 2020 17:33:22 +0000 Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kqJd0-0002E1-R0 for pgsql-hackers@postgresql.org; Fri, 18 Dec 2020 17:33:21 +0000 Received: by mail-io1-xd34.google.com with SMTP id o6so2730356iob.10 for ; Fri, 18 Dec 2020 09:33:17 -0800 (PST) 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=eM+yYzrrlkvqO25QIjdx3HIIO/lxpN+WGis9IuJUBwc=; b=IPN6w1cTOMYvgs7tRS03kdiDmhZ6c1+G1u0V3ngpdcbyG1AyAw2psDOPjjGTkftN20 P0ZfSVrS9mlcyg0MaEY0AIbF6+ECP78s3MOu9cRuFuBVlbAJVSV+tVwoQTzE7io2sn0t lMdCkgukD5hzeiFd/N1Nz8Tg7dlAhZxuCwXpUNzBp9uaublt39xLcUo+/SRzFCyvs2kA ukGydIHSWQvsK/PW9LbWte0xRAzQDs2t+a+jc6sk2Bp0SQkENkhoUWrvNMi1EwqsV0uA fBKRZS/0VcqO5Xt1MFoXdImOLq5nYMdrRJYYE0c8S8scBfOyi+7qGlETDrIQkURJi75e N+tg== 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=eM+yYzrrlkvqO25QIjdx3HIIO/lxpN+WGis9IuJUBwc=; b=a67MGIpSnva6hQ77zKtNHH/erLceN/D+gRtPcqoJYuBT7vlP4dJ4X2gPZusEkrMA+i 2B79S8HtD+gPrplX2WTWdSgtx0/G7JLq0+pq6+7lPFUeT9brGoCzxmL74qPj7PVDmJaS sns9S+HnWJoieurPsx3qsLqxLHpuv/yrZzUVr8r+F6NtLBVGYQQAPv+qMYuE3fSjXIBy N1EWH9R7mSp9w30NP2sDkbEWFyebtiuz+zbHkOrZ1E8yD7dIp9GHescjrs1OHUCQMJUA tTsQoEntXbGHPKbLg/yxFXNmoDFf1LWR9/9CNIXjj+T9SijbiCFaDonfo2Up21YuYiTv FMRw== X-Gm-Message-State: AOAM533aUnGxi4IYUwKTRhhQTCzU+h0IEEC/Bt+CDtCH4OB2z4+ugJC+ xw3Iodxm2Wjb8hCS9m+tUsY+MoAK+UdjmWJ5 X-Google-Smtp-Source: ABdhPJyVXoEtyxBkEHIAEeqEI+yhSSk0Dxh3eR9kRfCgF9yEuhckI1sLlH/apnKFAMAim+SczHJ8sQ== X-Received: by 2002:a05:6602:142:: with SMTP id v2mr4832499iot.32.1608312795368; Fri, 18 Dec 2020 09:33:15 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id d5sm6788582ilf.33.2020.12.18.09.33.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Dec 2020 09:33:14 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 4A92880092E; Fri, 18 Dec 2020 11:33:12 -0600 (CST) Date: Fri, 18 Dec 2020 11:33:12 -0600 From: Justin Pryzby To: Laurenz Albe Cc: pgsql-hackers@postgresql.org Subject: Re: allow to \dtS+ pg_toast.* Message-ID: <20201218173312.GZ30237@telsasoft.com> References: <20201130165436.GX24052@telsasoft.com> <1839fe7148f3aa1a7b28da9064a5c2f8b08316c3.camel@cybertec.at> <20201218065808.GY30237@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="RwxaKO075aXzzOz0" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --RwxaKO075aXzzOz0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Dec 18, 2020 at 12:43:07PM +0100, Laurenz Albe wrote: > On Fri, 2020-12-18 at 00:58 -0600, Justin Pryzby wrote: > > On Thu, Dec 17, 2020 at 04:16:52PM +0100, Laurenz Albe wrote: > > > On Mon, 2020-11-30 at 10:54 -0600, Justin Pryzby wrote: > > > > This makes toast tables a bit less special and easier to inspect. > > > > > > > > postgres=# \dtS+ pg_toast.pg_toast_2619 > > > > pg_toast | pg_toast_2619 | toast table | pryzbyj | permanent | heap | 56 kB | > > > > > > > > This follows commit from last year: > > > > | eb5472da9 make \d pg_toast.foo show its indices ; and, \d toast show its main table > > > > > > This would indeed be convenient. > > > > > > While playing around with it, I found the following oddity: > > > > > > regression=# \dtS pg_toast.pg_toast_30701 > > > pg_toast | pg_toast_30701 | toast table | laurenz > > > > > > regression=# \dt pg_toast.pg_toast_30701 > > > Did not find any relation named "pg_toast.pg_toast_30701". > > > > > > Now this doesn't seem right. To my understanding, \dtS should do the same as \dt, > > > except that it should also search in "pg_catalog" if no schema was provided. > > > > You mean that if pg_toast.* should be shown if a matching "pattern" is given, > > even if "S" was not used. I think you're right. The behavior I implemented > > was intended to provide a bit of historic compatibility towards hiding toast > > tables, but I think it's not needed, since they're not shown anyway unless > > someone includes "S", specifies the "pg_toast." schema, or pg_toast is in their > > search path. See attached. > > Yes, exactly. > > I wonder why the modification in "listPartitionedTables" is necessary. > Surely there cannot be any partitioned toast tables, can there? The comment should be removed for consistency. And I changed the code for consistency with listTables (from which I assume listPartitionedTables was derived - I was involved in the last stages of that patch). It doesn't need to exclude pg_catalog or information_schema, either, but it's kept the same for consistency. That part could also be removed. > > > Another thing that is missing is tab completion for > > > regression=# \dtS pg_toast.pg_ > > > This should work just like for \d and \dS. .. > If I want to know how big the TOAST table of relation 87654 is, > I think it is convenient if I can tab to > > \dt+ pg_toast.pg_toast_ I agree that it's nice to complete the schema name, but I'm still not convinced this part should be included. The way to include pg_toast.pg_toast is if toast relations are included, which is exactly what Tom pointed out is usually unhelpful. If you include toast relations, tab completion might give "pg_toast.pg_toast_14..." when you wanted to paste "145678" - you'd need to remove the common suffix that it found. I considered whether "toast table" should be capitalized (as it is for "\d") but I think it should stay lowercase. -- Justin --RwxaKO075aXzzOz0 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Allow-to-dti-pg_toast.patch" From 987bbcb083507426018bfccd1eae7552468c57cb Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Wed, 28 Oct 2020 23:51:39 -0500 Subject: [PATCH] Allow to \dti+ pg_toast.* This reverts commit 81fc5df83. Rather than being consistent by hiding toast tables, instead allow toast tables to be displayed by specifying "S", or their schema, or by including pg_toast in search_path. --- src/bin/psql/describe.c | 24 ++++++------------------ src/bin/psql/tab-complete.c | 13 ++++++++++++- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 8923eee752..b7a8bd4121 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3762,6 +3762,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys " WHEN " CppAsString2(RELKIND_INDEX) " THEN '%s'" " WHEN " CppAsString2(RELKIND_SEQUENCE) " THEN '%s'" " WHEN 's' THEN '%s'" + " WHEN " CppAsString2(RELKIND_TOASTVALUE) " THEN '%s'" " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'" " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'" " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX) " THEN '%s'" @@ -3775,6 +3776,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys gettext_noop("index"), gettext_noop("sequence"), gettext_noop("special"), + gettext_noop("toast table"), gettext_noop("foreign table"), gettext_noop("partitioned table"), gettext_noop("partitioned index"), @@ -3870,6 +3872,8 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys appendPQExpBufferStr(&buf, CppAsString2(RELKIND_SEQUENCE) ","); if (showSystem || pattern) appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL */ + if ((showSystem || pattern) && showTables) + appendPQExpBufferStr(&buf, "'t',"); /* toast tables */ if (showForeign) appendPQExpBufferStr(&buf, CppAsString2(RELKIND_FOREIGN_TABLE) ","); @@ -3878,17 +3882,9 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys if (!showSystem && !pattern) appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n" + " AND n.nspname !~ '^pg_toast'\n" " AND n.nspname <> 'information_schema'\n"); - /* - * TOAST objects are suppressed unconditionally. Since we don't provide - * any way to select RELKIND_TOASTVALUE above, we would never show toast - * tables in any case; it seems a bit confusing to allow their indexes to - * be shown. Use plain \d if you really need to look at a TOAST - * table/index. - */ - appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n"); - processSQLNamePattern(pset.db, &buf, pattern, true, false, "n.nspname", "c.relname", NULL, "pg_catalog.pg_table_is_visible(c.oid)"); @@ -4101,17 +4097,9 @@ listPartitionedTables(const char *reltypes, const char *pattern, bool verbose) if (!pattern) appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n" + " AND n.nspname !~ '^pg_toast'\n" " AND n.nspname <> 'information_schema'\n"); - /* - * TOAST objects are suppressed unconditionally. Since we don't provide - * any way to select RELKIND_TOASTVALUE above, we would never show toast - * tables in any case; it seems a bit confusing to allow their indexes to - * be shown. Use plain \d if you really need to look at a TOAST - * table/index. - */ - appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n"); - processSQLNamePattern(pset.db, &buf, pattern, true, false, "n.nspname", "c.relname", NULL, "pg_catalog.pg_table_is_visible(c.oid)"); diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 8d6f93147e..58b4d55a96 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -453,6 +453,17 @@ static const SchemaQuery Query_for_list_of_tables = { .result = "pg_catalog.quote_ident(c.relname)", }; +static const SchemaQuery Query_for_list_of_tables_with_toast = { + .catname = "pg_catalog.pg_class c", + .selcondition = + "c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_TOASTVALUE) ", " + CppAsString2(RELKIND_PARTITIONED_TABLE) ")", + .viscondition = "pg_catalog.pg_table_is_visible(c.oid)", + .namespace = "c.relnamespace", + .result = "pg_catalog.quote_ident(c.relname)", +}; + static const SchemaQuery Query_for_list_of_partitioned_tables = { .catname = "pg_catalog.pg_class c", .selcondition = "c.relkind IN (" CppAsString2(RELKIND_PARTITIONED_TABLE) ")", @@ -3903,7 +3914,7 @@ psql_completion(const char *text, int start, int end) else if (TailMatchesCS("\\ds*")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences, NULL); else if (TailMatchesCS("\\dt*")) - COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL); + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables_with_toast, NULL); else if (TailMatchesCS("\\dT*")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes, NULL); else if (TailMatchesCS("\\du*") || TailMatchesCS("\\dg*")) -- 2.17.0 --RwxaKO075aXzzOz0--