From adbe3b01da876ea506dbffedc7188c3ebfd46e42 Mon Sep 17 00:00:00 2001 From: amit Date: Wed, 12 Jul 2017 15:24:07 +0900 Subject: [PATCH 3/4] Indicate whether a partition is itself partitioned in \d+ output That's done by appending a " has partitions" string to the line describing an individual partition. Authors: Amit Langote, Ashutosh Bapat --- src/bin/psql/describe.c | 37 +++++++++++++++++++++++++----------- src/test/regress/expected/insert.out | 15 +++++++++++++++ src/test/regress/sql/insert.sql | 4 ++++ 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 86adfb71b7..faf69b95c6 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -2838,7 +2838,9 @@ describeOneTableDetails(const char *schemaname, /* print child tables (with additional info if partitions) */ if (pset.sversion >= 100000) printfPQExpBuffer(&buf, - "SELECT c.oid::pg_catalog.regclass, pg_get_expr(c.relpartbound, c.oid)" + "SELECT c.oid::pg_catalog.regclass," + " pg_get_expr(c.relpartbound, c.oid)," + " c.relkind" " FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i" " WHERE c.oid=i.inhrelid AND" " i.inhparent = '%s' AND" @@ -2863,21 +2865,25 @@ describeOneTableDetails(const char *schemaname, if (!verbose) { + const char *ct = (tableinfo.relkind != RELKIND_PARTITIONED_TABLE) + ? _("child tables") + : _("partitions"); + /* print the number of child tables, if any */ if (tuples > 0) { - if (tableinfo.relkind != RELKIND_PARTITIONED_TABLE) - 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); + printfPQExpBuffer(&buf, + _("Number of %s: %d (Use \\d+ to list them.)"), + ct, tuples); printTableAddFooter(&cont, buf.data); } } else { /* display the list of child tables */ - const char *ct = (tableinfo.relkind != RELKIND_PARTITIONED_TABLE) ? - _("Child tables") : _("Partitions"); + const char *ct = (tableinfo.relkind != RELKIND_PARTITIONED_TABLE) + ? _("Child tables") + : _("Partitions"); int ctw = pg_wcswidth(ct, strlen(ct), pset.encoding); for (i = 0; i < tuples; i++) @@ -2893,12 +2899,21 @@ describeOneTableDetails(const char *schemaname, } else { + char *partitioned_note; + + if (*PQgetvalue(result, i, 2) == RELKIND_PARTITIONED_TABLE) + partitioned_note = " has partitions"; + else + partitioned_note = ""; + if (i == 0) - printfPQExpBuffer(&buf, "%s: %s %s", - ct, PQgetvalue(result, i, 0), PQgetvalue(result, i, 1)); + printfPQExpBuffer(&buf, "%s: %s %s%s", + ct, PQgetvalue(result, i, 0), PQgetvalue(result, i, 1), + partitioned_note); else - printfPQExpBuffer(&buf, "%*s %s %s", - ctw, "", PQgetvalue(result, i, 0), PQgetvalue(result, i, 1)); + printfPQExpBuffer(&buf, "%*s %s %s%s", + ctw, "", PQgetvalue(result, i, 0), PQgetvalue(result, i, 1), + partitioned_note); } if (i < tuples - 1) appendPQExpBufferChar(&buf, ','); diff --git a/src/test/regress/expected/insert.out b/src/test/regress/expected/insert.out index d1153f410b..210a158521 100644 --- a/src/test/regress/expected/insert.out +++ b/src/test/regress/expected/insert.out @@ -314,6 +314,21 @@ select tableoid::regclass::text, a, min(b) as min_b, max(b) as max_b from list_p part_null | | 1 | 1 (9 rows) +-- test \d+ output on a table which has both partitioned and unpartitioned +-- partitions +\d+ list_parted + Table "public.list_parted" + Column | Type | Collation | Nullable | Default | Storage | Stats target | Description +--------+---------+-----------+----------+---------+----------+--------------+------------- + a | text | | | | extended | | + b | integer | | | | plain | | +Partition key: LIST (lower(a)) +Partitions: part_aa_bb FOR VALUES IN ('aa', 'bb'), + part_cc_dd FOR VALUES IN ('cc', 'dd'), + part_ee_ff FOR VALUES IN ('ee', 'ff') has partitions, + part_gg FOR VALUES IN ('gg') has partitions, + part_null FOR VALUES IN (NULL) + -- cleanup drop table range_parted, list_parted; -- more tests for certain multi-level partitioning scenarios diff --git a/src/test/regress/sql/insert.sql b/src/test/regress/sql/insert.sql index 83c3ad8f53..3c67692ace 100644 --- a/src/test/regress/sql/insert.sql +++ b/src/test/regress/sql/insert.sql @@ -185,6 +185,10 @@ insert into list_parted select 'gg', s.a from generate_series(1, 9) s(a); insert into list_parted (b) values (1); select tableoid::regclass::text, a, min(b) as min_b, max(b) as max_b from list_parted group by 1, 2 order by 1; +-- test \d+ output on a table which has both partitioned and unpartitioned +-- partitions +\d+ list_parted + -- cleanup drop table range_parted, list_parted; -- 2.11.0