From ae748eda1460e6da37a6c5a1e1168a5c7c18639b Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Wed, 19 Jun 2019 15:41:25 -0500 Subject: [PATCH v6] show childs of partitioned indices --- src/bin/psql/describe.c | 57 ++++++++++++++----------------- src/test/regress/input/tablespace.source | 1 + src/test/regress/output/tablespace.source | 31 +++++++++++++++++ 3 files changed, 57 insertions(+), 32 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 86a7610..6d136ba 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3069,6 +3069,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; @@ -3120,6 +3121,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); @@ -3184,7 +3186,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); @@ -3194,7 +3197,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); @@ -3204,39 +3207,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, ','); @@ -3279,10 +3276,6 @@ describeOneTableDetails(const char *schemaname, if (verbose && tableinfo.relkind != RELKIND_MATVIEW && tableinfo.hasoids) printTableAddFooter(&cont, _("Has OIDs: yes")); - /* Tablespace info */ - add_tablespace_footer(&cont, tableinfo.relkind, tableinfo.tablespace, - true); - /* Access method info */ if (verbose && tableinfo.relam != NULL && !pset.hide_tableam) { diff --git a/src/test/regress/input/tablespace.source b/src/test/regress/input/tablespace.source index 8f012fc..7875292 100644 --- a/src/test/regress/input/tablespace.source +++ b/src/test/regress/input/tablespace.source @@ -86,6 +86,7 @@ CREATE TABLE testschema.part2 PARTITION OF testschema.part FOR VALUES IN (2); SELECT relname, spcname FROM pg_catalog.pg_tablespace t, pg_catalog.pg_class c where c.reltablespace = t.oid AND c.relname LIKE 'part%_idx'; \d testschema.part_a_idx +\d+ testschema.part_a_idx -- partitioned rels cannot specify the default tablespace. These fail: CREATE TABLE testschema.dflt (a int PRIMARY KEY) PARTITION BY LIST (a) TABLESPACE pg_default; diff --git a/src/test/regress/output/tablespace.source b/src/test/regress/output/tablespace.source index 2ea68ca..d4771b7 100644 --- a/src/test/regress/output/tablespace.source +++ b/src/test/regress/output/tablespace.source @@ -129,6 +129,17 @@ Partitioned index "testschema.part_a_idx" a | integer | yes | a btree, for table "testschema.part" Tablespace: "regress_tblspace" +Number of partitions: 2 (Use \d+ to list them.) + +\d+ testschema.part_a_idx + Partitioned index "testschema.part_a_idx" + Column | Type | Key? | Definition | Storage | Stats target +--------+---------+------+------------+---------+-------------- + a | integer | yes | a | plain | +btree, for table "testschema.part" +Tablespace: "regress_tblspace" +Partitions: testschema.part1_a_idx, + testschema.part2_a_idx -- partitioned rels cannot specify the default tablespace. These fail: CREATE TABLE testschema.dflt (a int PRIMARY KEY) PARTITION BY LIST (a) TABLESPACE pg_default; @@ -344,6 +355,7 @@ Partitioned index "testschema.test_index1" --------+--------+------+------------ val | bigint | yes | val btree, for table "testschema.test_default_tab_p" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index2 Partitioned index "testschema.test_index2" @@ -352,6 +364,7 @@ Partitioned index "testschema.test_index2" val | bigint | yes | val btree, for table "testschema.test_default_tab_p" Tablespace: "regress_tblspace" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index3 Partitioned index "testschema.test_index3" @@ -359,6 +372,7 @@ Partitioned index "testschema.test_index3" --------+--------+------+------------ id | bigint | yes | id primary key, btree, for table "testschema.test_default_tab_p" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index4 Partitioned index "testschema.test_index4" @@ -367,6 +381,7 @@ Partitioned index "testschema.test_index4" id | bigint | yes | id unique, btree, for table "testschema.test_default_tab_p" Tablespace: "regress_tblspace" +Number of partitions: 1 (Use \d+ to list them.) -- use a custom tablespace for default_tablespace SET default_tablespace TO regress_tblspace; @@ -378,6 +393,7 @@ Partitioned index "testschema.test_index1" --------+--------+------+------------ val | bigint | yes | val btree, for table "testschema.test_default_tab_p" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index2 Partitioned index "testschema.test_index2" @@ -386,6 +402,7 @@ Partitioned index "testschema.test_index2" val | bigint | yes | val btree, for table "testschema.test_default_tab_p" Tablespace: "regress_tblspace" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index3 Partitioned index "testschema.test_index3" @@ -393,6 +410,7 @@ Partitioned index "testschema.test_index3" --------+--------+------+------------ id | bigint | yes | id primary key, btree, for table "testschema.test_default_tab_p" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index4 Partitioned index "testschema.test_index4" @@ -401,6 +419,7 @@ Partitioned index "testschema.test_index4" id | bigint | yes | id unique, btree, for table "testschema.test_default_tab_p" Tablespace: "regress_tblspace" +Number of partitions: 1 (Use \d+ to list them.) SELECT * FROM testschema.test_default_tab_p; id | val @@ -416,6 +435,7 @@ Partitioned index "testschema.test_index1" --------+---------+------+------------ val | integer | yes | val btree, for table "testschema.test_default_tab_p" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index2 Partitioned index "testschema.test_index2" @@ -424,6 +444,7 @@ Partitioned index "testschema.test_index2" val | integer | yes | val btree, for table "testschema.test_default_tab_p" Tablespace: "regress_tblspace" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index3 Partitioned index "testschema.test_index3" @@ -431,6 +452,7 @@ Partitioned index "testschema.test_index3" --------+--------+------+------------ id | bigint | yes | id primary key, btree, for table "testschema.test_default_tab_p" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index4 Partitioned index "testschema.test_index4" @@ -439,6 +461,7 @@ Partitioned index "testschema.test_index4" id | bigint | yes | id unique, btree, for table "testschema.test_default_tab_p" Tablespace: "regress_tblspace" +Number of partitions: 1 (Use \d+ to list them.) SELECT * FROM testschema.test_default_tab_p; id | val @@ -456,6 +479,7 @@ Partitioned index "testschema.test_index1" --------+---------+------+------------ val | integer | yes | val btree, for table "testschema.test_default_tab_p" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index2 Partitioned index "testschema.test_index2" @@ -464,6 +488,7 @@ Partitioned index "testschema.test_index2" val | integer | yes | val btree, for table "testschema.test_default_tab_p" Tablespace: "regress_tblspace" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index3 Partitioned index "testschema.test_index3" @@ -471,6 +496,7 @@ Partitioned index "testschema.test_index3" --------+--------+------+------------ id | bigint | yes | id primary key, btree, for table "testschema.test_default_tab_p" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index4 Partitioned index "testschema.test_index4" @@ -479,6 +505,7 @@ Partitioned index "testschema.test_index4" id | bigint | yes | id unique, btree, for table "testschema.test_default_tab_p" Tablespace: "regress_tblspace" +Number of partitions: 1 (Use \d+ to list them.) -- tablespace should not change even if there is an index rewrite ALTER TABLE testschema.test_default_tab_p ALTER val TYPE bigint; @@ -488,6 +515,7 @@ Partitioned index "testschema.test_index1" --------+--------+------+------------ val | bigint | yes | val btree, for table "testschema.test_default_tab_p" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index2 Partitioned index "testschema.test_index2" @@ -496,6 +524,7 @@ Partitioned index "testschema.test_index2" val | bigint | yes | val btree, for table "testschema.test_default_tab_p" Tablespace: "regress_tblspace" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index3 Partitioned index "testschema.test_index3" @@ -503,6 +532,7 @@ Partitioned index "testschema.test_index3" --------+--------+------+------------ id | bigint | yes | id primary key, btree, for table "testschema.test_default_tab_p" +Number of partitions: 1 (Use \d+ to list them.) \d testschema.test_index4 Partitioned index "testschema.test_index4" @@ -511,6 +541,7 @@ Partitioned index "testschema.test_index4" id | bigint | yes | id unique, btree, for table "testschema.test_default_tab_p" Tablespace: "regress_tblspace" +Number of partitions: 1 (Use \d+ to list them.) DROP TABLE testschema.test_default_tab_p; -- check that default_tablespace affects index additions in ALTER TABLE -- 2.7.4