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 1hf3RL-0007CX-Dg for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Jun 2019 14:25:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hf3RK-0008UF-9R for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Jun 2019 14:25:54 +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 1hf3RJ-0008U8-Su for pgsql-hackers@lists.postgresql.org; Sun, 23 Jun 2019 14:25:54 +0000 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hf3RH-0001w2-2d for pgsql-hackers@postgresql.org; Sun, 23 Jun 2019 14:25:53 +0000 Received: by mail-io1-xd41.google.com with SMTP id u19so546884ior.9 for ; Sun, 23 Jun 2019 07:25:50 -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=pfriBZtnWBp7es6DieKwQ96mzDKusUdynDHSg9vIrfw=; b=yt7PW5cng38I+12o+bLJXcBaHoNVuGj58O0nbprnraUmSfCF8tduDYqBcWhn3k25op bmfUdxxcsDt+nPxm8ROCqVlUsAwxGZqONnmksXYIpdjBdzNWjwIteau3bv8OVHxzLANI IrAmUt9t6qSEE6EGpr9Gm9Dgg3mdcjuGKPA4G05THF91oWJOJRRLybsqdAbromHRzsW/ EMYH+K6QGKYbDs4NEDbrqlcKKBQezqFrx0yJM040YTZOYunpE4rd/hm7FPDJENLwV9nK 1GGfbg8qun+GvozItgod5zZOzWTllAH6KVE+cOGjPmaMf2KtqdTNybI7xgOlfMgHyL2U h3mA== 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=pfriBZtnWBp7es6DieKwQ96mzDKusUdynDHSg9vIrfw=; b=eHEZ2/LhL/ANqBegZ9iumOoz62EoNeRnS5A95/it/I/VfCZQIK+YeiCMgL691EmeAM Dw50LDaBEX9qLQtVOg/YvZ6mp33g9WiioglhF8SxGabaIZDhUZHpmhxNXLlM9kmi56F0 6NZ30WnRZFFBlGq0P7Jg8r3zFGi51p7n31iN+jlkQj5HgH6+bKJLODa269k0sshObl5O 3TBIDZHJVqMITWjJjo57LRRTV2inE9sVw7PoEZQ6Jv/Ltn7udml5/OKuR+cyYYDs7YQG qJY1gaKmKlnzllSPMRmAhg6Hw8k3YGCPXws3uRQEISglqxAX1Y2itU4Cw3bA8tVE/oYL UOjw== X-Gm-Message-State: APjAAAXzwL2S/WYGvjltPuVsGIJ9+QSiAn3goR90IL0Vee2a8JhS9YEd FxyVOqmnRP4vUjSpup7ZZdJieQZb27c= X-Google-Smtp-Source: APXvYqyudiHAT/XyJG4HgQ/6J2kLkUslLQ3/jbNpND0QVeOjlo4ckrQy93EpGquaYpRlrGJLYExbxA== X-Received: by 2002:a5d:890d:: with SMTP id b13mr76479544ion.124.1561299948871; Sun, 23 Jun 2019 07:25:48 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id n7sm8709159ioo.79.2019.06.23.07.25.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Jun 2019 07:25:48 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 30F0F800DAB; Sun, 23 Jun 2019 09:25:47 -0500 (CDT) Date: Sun, 23 Jun 2019 09:25:47 -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: <20190623142546.GE16019@telsasoft.com> References: <20190422154902.GH14223@telsasoft.com> <20190503142721.GC3925@telsasoft.com> <20190506162251.GN3925@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="LpQ9ahxlCli8rRTG" Content-Disposition: inline In-Reply-To: <20190506162251.GN3925@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 --LpQ9ahxlCli8rRTG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I'm continuing this thread with an additional change to slash dee for partitioned indexes. postgres=# \d ttz_i_idx Partitioned index "public.ttz_i_idx" Column | Type | Key? | Definition --------+---------+------+------------ i | integer | yes | i btree, for table "public.ttz" Number of partitions: 2 (Use \d+ to list them.) postgres=# \d+ ttz_i_idx Partitioned index "public.ttz_i_idx" Column | Type | Key? | Definition | Storage | Stats target --------+---------+------+------------+---------+-------------- i | integer | yes | i | plain | btree, for table "public.ttz" Partitions: ttz1_i_idx, ttz2_i_idx, PARTITIONED Showing the list of index partitions is probably not frequently useful, but consider the case of non-default names, for example due to truncation. I didn't update regression output; note that this patch also, by chance, causes tablespace of partitioned indexes to be output, which I think is good and an oversight that it isn't currently shown. I added CF entry and including previous two patches for CFBOT purposes. Recap: Tom, Andreas, Robert, Stephen and I agree that \d toast should show the main table. Rafia and Alvaro think that \d on the main table should (also?) show its toast. Justin --LpQ9ahxlCli8rRTG 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 --LpQ9ahxlCli8rRTG 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 --LpQ9ahxlCli8rRTG Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0002-show-childs-of-partitioned-indices.patch" From 1281338ce47d0dbf0e0f93d1e483721396ac2402 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Wed, 19 Jun 2019 15:41:25 -0500 Subject: [PATCH v3] show childs of partitioned indices --- src/bin/psql/describe.c | 52 +++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ff98c4f..3a55dc9 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; @@ -3178,7 +3179,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 +3190,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 +3200,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 --LpQ9ahxlCli8rRTG--