Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hgdPA-0007x1-DL for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Jun 2019 23:02:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hgdP8-0004X3-WA for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Jun 2019 23:02:10 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hgdP8-0004Ww-I8 for pgsql-hackers@lists.postgresql.org; Thu, 27 Jun 2019 23:02:10 +0000 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hgdP5-0001Th-9g for pgsql-hackers@postgresql.org; Thu, 27 Jun 2019 23:02:09 +0000 Received: by mail-io1-xd31.google.com with SMTP id k8so8516754iot.1 for ; Thu, 27 Jun 2019 16:02:06 -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=Rnz1dn4/kWkhNje7GDio5r2J9FOEkZ7C0oi+a8OTtOg=; b=Z4DtvVz50N7NJybEj85nWm14EKowL6VGbdAZwAaOFp22U5k5XBb//j0GO5QgOjsqSn 6N7S2/b9aJGUl9Bo1CdXPonlGTezzRb0Z37lkCKcz+RbtfAwiXbqEbynoUv4A2CayTiC XkqVM27rvw/L/imMjb1aWlTDMgegwbTa9fGK3nucwQbFsQnGL7PKIK77RqJfS6oCJ+fP 2an9xXPLlrV6b2VuN++VhO5LKsXxSMNG9i/EB46UyPqRfIKOcWYGjVK2RYwQEpqYoZWW eBHscfGxNd8XocW2r3enr+Ze5AjaIVSgaasmidv6tJqRLytxpkE6oNa1neeGU4jqo6QZ ZXrA== 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=Rnz1dn4/kWkhNje7GDio5r2J9FOEkZ7C0oi+a8OTtOg=; b=B7yRQvs7LNVViXa7fl2gqOYxciYLQrWOMdB5o0hIh5TFxWtWNY/j58xpgkIp5iaRNQ Uptp5+JIn823PltZIumhdjv6sLbKarEflUdeFnEyz9QBOKjvMfKVeEpM9ySKdt4Zfz3O mtB0+X/v8UZ0R1ikIgD8/B06b931N2JaaeSbiDGWqy4xw1GsGBikgG5hx8Ch6uYj2gUd KGYKEgZ0PEJJ/klF/zlgvxbWvfD1AHgPkJ8tgFcQWtLe0U+4SC8NAqBC08xVjQfLjpqc WCuJ6Ei+wKvs/VjiTPVlSZds0iVWF7OaxJXNkkRGdbWlu0qkQzndHYUCbH8tU/l0tPON nMNg== X-Gm-Message-State: APjAAAUPBZPabRPQhkjPyXqKQEYWg2Xvbf2zLN8iXEMVA/lETq7lD7yt +4xLeacmYvifeEQrjI9cc/nfTQ== X-Google-Smtp-Source: APXvYqzI1zJjvy4KehIgaPvYvGrK7Ifugwr3DFj+xNF0wXNZFxOfEsTOcmrNuCPLdm7v4x9cdLgjkQ== X-Received: by 2002:a5e:8518:: with SMTP id i24mr7272939ioj.149.1561676524835; Thu, 27 Jun 2019 16:02:04 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id a7sm781353iok.19.2019.06.27.16.02.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Jun 2019 16:02:03 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 22B7B800A33; Thu, 27 Jun 2019 18:02:02 -0500 (CDT) Date: Thu, 27 Jun 2019 18:02:02 -0500 From: Justin Pryzby To: Rafia Sabih Cc: PostgreSQL-development Subject: Re: make \d pg_toast.foo show its indices ; and, \d toast show its main table ; and \d relkind=I show its partitions (and tablespace) Message-ID: <20190627230201.GA9401@telsasoft.com> References: <20190422154902.GH14223@telsasoft.com> <20190503142721.GC3925@telsasoft.com> <20190506162251.GN3925@telsasoft.com> <20190623142546.GE16019@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="AqsLC8rIMeq19msA" Content-Disposition: inline In-Reply-To: <20190623142546.GE16019@telsasoft.com> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --AqsLC8rIMeq19msA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline My previous patch missed a 1-line hunk, so resending. --AqsLC8rIMeq19msA Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0000-print-table-associated-with-given-TOAST-table.patch" From 29e4c0b9700b9dee5f6ff2abc442e08e5221eb93 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Tue, 30 Apr 2019 19:05:53 -0500 Subject: [PATCH v3] print table associated with given TOAST table --- src/bin/psql/describe.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index c65bc82..ff98c4f 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -2153,6 +2153,28 @@ describeOneTableDetails(const char *schemaname, } } + /* print table associated with given TOAST table */ + if (tableinfo.relkind == RELKIND_TOASTVALUE) + { + PGresult *result = NULL; + printfPQExpBuffer(&buf, + "SELECT relnamespace::pg_catalog.regnamespace, relname FROM pg_class WHERE reltoastrelid = '%s'", + oid); + result = PSQLexec(buf.data); + if (!result) { + goto error_return; + } else if (1 != PQntuples(result)) { + PQclear(result); + goto error_return; + } else { + char *schemaname = PQgetvalue(result, 0, 0); + char *relname = PQgetvalue(result, 0, 1); + appendPQExpBuffer(&tmpbuf, _("For table: \"%s.%s\""), + schemaname, relname); + printTableAddFooter(&cont, tmpbuf.data); + } + } + if (tableinfo.relkind == RELKIND_PARTITIONED_TABLE) { /* Get the partition key information */ -- 2.7.4 --AqsLC8rIMeq19msA Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0001-make-d-pg_toast.foo-show-its-indices.patch" From 185d8723bec45824a0db245f69e948080b7fbbb2 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Fri, 3 May 2019 09:24:51 -0500 Subject: [PATCH v3] make \d pg_toast.foo show its indices --- src/bin/psql/describe.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index af2f440..c65bc82 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -2275,6 +2275,7 @@ describeOneTableDetails(const char *schemaname, else if (tableinfo.relkind == RELKIND_RELATION || tableinfo.relkind == RELKIND_MATVIEW || tableinfo.relkind == RELKIND_FOREIGN_TABLE || + tableinfo.relkind == RELKIND_TOASTVALUE || tableinfo.relkind == RELKIND_PARTITIONED_TABLE) { /* Footer information about a table */ -- 2.7.4 --AqsLC8rIMeq19msA Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0002-show-childs-and-tablespaces-of-partitioned-indice.patch" From 7e771e08cee52e506d4df18a1316652ac7e8f516 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Wed, 19 Jun 2019 15:41:25 -0500 Subject: [PATCH v4] show childs and tablespaces of partitioned indices --- src/bin/psql/describe.c | 53 +++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ff98c4f..5ebad24 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3063,6 +3063,7 @@ describeOneTableDetails(const char *schemaname, if (tableinfo.relkind == RELKIND_RELATION || tableinfo.relkind == RELKIND_MATVIEW || tableinfo.relkind == RELKIND_FOREIGN_TABLE || + tableinfo.relkind == RELKIND_PARTITIONED_INDEX || tableinfo.relkind == RELKIND_PARTITIONED_TABLE) { PGresult *result; @@ -3114,6 +3115,7 @@ describeOneTableDetails(const char *schemaname, " FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i" " WHERE c.oid=i.inhparent AND i.inhrelid = '%s'" " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_TABLE) + " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_INDEX) " ORDER BY inhseqno;", oid); result = PSQLexec(buf.data); @@ -3178,7 +3180,8 @@ describeOneTableDetails(const char *schemaname, * Otherwise, we will not print "Partitions" section for a partitioned * table without any partitions. */ - if (tableinfo.relkind == RELKIND_PARTITIONED_TABLE && tuples == 0) + if (tuples == 0 && (tableinfo.relkind == RELKIND_PARTITIONED_TABLE || + tableinfo.relkind == RELKIND_PARTITIONED_INDEX)) { printfPQExpBuffer(&buf, _("Number of partitions: %d"), tuples); printTableAddFooter(&cont, buf.data); @@ -3188,7 +3191,7 @@ describeOneTableDetails(const char *schemaname, /* print the number of child tables, if any */ if (tuples > 0) { - if (tableinfo.relkind != RELKIND_PARTITIONED_TABLE) + if (tableinfo.relkind != RELKIND_PARTITIONED_TABLE && tableinfo.relkind != RELKIND_PARTITIONED_INDEX) printfPQExpBuffer(&buf, _("Number of child tables: %d (Use \\d+ to list them.)"), tuples); else printfPQExpBuffer(&buf, _("Number of partitions: %d (Use \\d+ to list them.)"), tuples); @@ -3198,39 +3201,33 @@ describeOneTableDetails(const char *schemaname, else { /* display the list of child tables */ - const char *ct = (tableinfo.relkind != RELKIND_PARTITIONED_TABLE) ? + const char *ct = (tableinfo.relkind != RELKIND_PARTITIONED_TABLE && tableinfo.relkind != RELKIND_PARTITIONED_INDEX) ? _("Child tables") : _("Partitions"); int ctw = pg_wcswidth(ct, strlen(ct), pset.encoding); for (i = 0; i < tuples; i++) { - if (tableinfo.relkind != RELKIND_PARTITIONED_TABLE) - { - if (i == 0) - printfPQExpBuffer(&buf, "%s: %s", - ct, PQgetvalue(result, i, 0)); - else - printfPQExpBuffer(&buf, "%*s %s", - ctw, "", PQgetvalue(result, i, 0)); + char *ptn_expr = tableinfo.relkind == RELKIND_PARTITIONED_TABLE ? PQgetvalue(result, i, 1) : ""; + char *partitioned_note; + switch (*PQgetvalue(result, i, 2)) { + case RELKIND_PARTITIONED_INDEX: + case RELKIND_PARTITIONED_TABLE: + partitioned_note = ", PARTITIONED"; + break; + default: + partitioned_note = ""; } - else - { - char *partitioned_note; - if (*PQgetvalue(result, i, 2) == RELKIND_PARTITIONED_TABLE) - partitioned_note = ", PARTITIONED"; - else - partitioned_note = ""; - - if (i == 0) - printfPQExpBuffer(&buf, "%s: %s %s%s", - ct, PQgetvalue(result, i, 0), PQgetvalue(result, i, 1), - partitioned_note); - else - printfPQExpBuffer(&buf, "%*s %s %s%s", - ctw, "", PQgetvalue(result, i, 0), PQgetvalue(result, i, 1), - partitioned_note); - } + if (i == 0) + printfPQExpBuffer(&buf, "%s: %s%s%s%s", + ct, PQgetvalue(result, i, 0), + tableinfo.relkind == RELKIND_PARTITIONED_TABLE ? " " : "", ptn_expr, + partitioned_note); + else + printfPQExpBuffer(&buf, "%*s %s%s%s%s", + ctw, "", PQgetvalue(result, i, 0), + tableinfo.relkind == RELKIND_PARTITIONED_TABLE ? " " : "", ptn_expr, + partitioned_note); if (i < tuples - 1) appendPQExpBufferChar(&buf, ','); -- 2.7.4 --AqsLC8rIMeq19msA--