Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb5472d

Browse files
committed
Improve psql's \d output for TOAST tables.
Add the name of the owning table to the footers for a TOAST table.Also, show all the same footers as for a regular table (in practice,this adds the index and perhaps the tablespace and access method).Justin Pryzby, reviewed by Fabien CoelhoDiscussion:https://postgr.es/m/20190422154902.GH14223@telsasoft.com
1 parent06140c2 commiteb5472d

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

‎src/bin/psql/describe.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,33 @@ describeOneTableDetails(const char *schemaname,
21722172
PQclear(result);
21732173
}
21742174

2175+
if (tableinfo.relkind==RELKIND_TOASTVALUE)
2176+
{
2177+
/* For a TOAST table, print name of owning table */
2178+
PGresult*result;
2179+
2180+
printfPQExpBuffer(&buf,
2181+
"SELECT n.nspname, c.relname\n"
2182+
"FROM pg_catalog.pg_class c"
2183+
" JOIN pg_catalog.pg_namespace n"
2184+
" ON n.oid = c.relnamespace\n"
2185+
"WHERE reltoastrelid = '%s';",oid);
2186+
result=PSQLexec(buf.data);
2187+
if (!result)
2188+
gotoerror_return;
2189+
2190+
if (PQntuples(result)==1)
2191+
{
2192+
char*schemaname=PQgetvalue(result,0,0);
2193+
char*relname=PQgetvalue(result,0,1);
2194+
2195+
printfPQExpBuffer(&tmpbuf,_("Owning table: \"%s.%s\""),
2196+
schemaname,relname);
2197+
printTableAddFooter(&cont,tmpbuf.data);
2198+
}
2199+
PQclear(result);
2200+
}
2201+
21752202
if (tableinfo.relkind==RELKIND_INDEX||
21762203
tableinfo.relkind==RELKIND_PARTITIONED_INDEX)
21772204
{
@@ -2272,10 +2299,12 @@ describeOneTableDetails(const char *schemaname,
22722299

22732300
PQclear(result);
22742301
}
2302+
/* If you add relkinds here, see also "Finish printing..." stanza below */
22752303
elseif (tableinfo.relkind==RELKIND_RELATION||
22762304
tableinfo.relkind==RELKIND_MATVIEW||
22772305
tableinfo.relkind==RELKIND_FOREIGN_TABLE||
2278-
tableinfo.relkind==RELKIND_PARTITIONED_TABLE)
2306+
tableinfo.relkind==RELKIND_PARTITIONED_TABLE||
2307+
tableinfo.relkind==RELKIND_TOASTVALUE)
22792308
{
22802309
/* Footer information about a table */
22812310
PGresult*result=NULL;
@@ -3040,7 +3069,8 @@ describeOneTableDetails(const char *schemaname,
30403069
if (tableinfo.relkind==RELKIND_RELATION||
30413070
tableinfo.relkind==RELKIND_MATVIEW||
30423071
tableinfo.relkind==RELKIND_FOREIGN_TABLE||
3043-
tableinfo.relkind==RELKIND_PARTITIONED_TABLE)
3072+
tableinfo.relkind==RELKIND_PARTITIONED_TABLE||
3073+
tableinfo.relkind==RELKIND_TOASTVALUE)
30443074
{
30453075
PGresult*result;
30463076
inttuples;
@@ -3308,7 +3338,8 @@ add_tablespace_footer(printTableContent *const cont, char relkind,
33083338
relkind==RELKIND_MATVIEW||
33093339
relkind==RELKIND_INDEX||
33103340
relkind==RELKIND_PARTITIONED_TABLE||
3311-
relkind==RELKIND_PARTITIONED_INDEX)
3341+
relkind==RELKIND_PARTITIONED_INDEX||
3342+
relkind==RELKIND_TOASTVALUE)
33123343
{
33133344
/*
33143345
* We ignore the database default tablespace so that users not using

‎src/test/regress/expected/psql.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4748,3 +4748,15 @@ drop schema testpart;
47484748
set search_path to default;
47494749
set role to default;
47504750
drop role regress_partitioning_role;
4751+
-- \d on toast table (use pg_statistic's toast table, which has a known name)
4752+
\d pg_toast.pg_toast_2619
4753+
TOAST table "pg_toast.pg_toast_2619"
4754+
Column | Type
4755+
------------+---------
4756+
chunk_id | oid
4757+
chunk_seq | integer
4758+
chunk_data | bytea
4759+
Owning table: "pg_catalog.pg_statistic"
4760+
Indexes:
4761+
"pg_toast_2619_index" PRIMARY KEY, btree (chunk_id, chunk_seq)
4762+

‎src/test/regress/sql/psql.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,3 +1131,6 @@ set search_path to default;
11311131

11321132
set role to default;
11331133
drop role regress_partitioning_role;
1134+
1135+
-- \d on toast table (use pg_statistic's toast table, which has a known name)
1136+
\dpg_toast.pg_toast_2619

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp