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

Commitb4132fd

Browse files
committed
Now \d show tablespace of indices per discussion.
test=# \d e Table "public.e" Column | Type | Modifiers--------+---------+----------- i | integer | not null j | integer | not null k | integer |Indexes: "e_pkey" PRIMARY KEY, btree (i, j), tablespace "haha" "ei" btree (i) "ej" btree (j), tablespace "haha" "ek" btree (k)Tablespace: "haha"Qingqing Zhou
1 parent8b84aeb commitb4132fd

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

‎src/bin/psql/describe.c

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.116 2005/06/1402:57:41 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.117 2005/06/1423:59:31 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"describe.h"
@@ -37,8 +37,8 @@ static void processNamePattern(PQExpBuffer buf, const char *pattern,
3737
constchar*schemavar,constchar*namevar,
3838
constchar*altnamevar,constchar*visibilityrule);
3939

40-
staticvoidadd_tablespace_footer(charrelkind,Oidtablespace,
41-
char**footers,int*count,PQExpBufferDatabuf);
40+
staticbooladd_tablespace_footer(charrelkind,Oidtablespace,char**footers,
41+
int*count,PQExpBufferDatabuf,boolnewline);
4242

4343
/*----------------
4444
* Handlers for various slash commands displaying some sort of list
@@ -942,7 +942,7 @@ describeOneTableDetails(const char *schemaname,
942942
footers=pg_malloc_zero(4*sizeof(*footers));
943943
footers[count_footers++]=pg_strdup(tmpbuf.data);
944944
add_tablespace_footer(tableinfo.relkind,tableinfo.tablespace,
945-
footers,&count_footers,tmpbuf);
945+
footers,&count_footers,tmpbuf, true);
946946
footers[count_footers]=NULL;
947947

948948
}
@@ -1022,7 +1022,7 @@ describeOneTableDetails(const char *schemaname,
10221022
{
10231023
printfPQExpBuffer(&buf,
10241024
"SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, "
1025-
"pg_catalog.pg_get_indexdef(i.indexrelid, 0, true)\n"
1025+
"pg_catalog.pg_get_indexdef(i.indexrelid, 0, true), c2.reltablespace\n"
10261026
"FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
10271027
"WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
10281028
"ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname",
@@ -1142,6 +1142,7 @@ describeOneTableDetails(const char *schemaname,
11421142
{
11431143
constchar*indexdef;
11441144
constchar*usingpos;
1145+
PQExpBufferDatatmpbuf;
11451146

11461147
/* Output index name */
11471148
printfPQExpBuffer(&buf,_(" \"%s\""),
@@ -1165,6 +1166,22 @@ describeOneTableDetails(const char *schemaname,
11651166
if (strcmp(PQgetvalue(result1,i,3),"t")==0)
11661167
appendPQExpBuffer(&buf," CLUSTER");
11671168

1169+
/* Print tablespace of the index on the same line */
1170+
count_footers+=1;
1171+
initPQExpBuffer(&tmpbuf);
1172+
if (add_tablespace_footer('i',
1173+
atooid(PQgetvalue(result1,i,5)),
1174+
footers,&count_footers,tmpbuf, false))
1175+
{
1176+
appendPQExpBuffer(&buf,", ");
1177+
appendPQExpBuffer(&buf,tmpbuf.data);
1178+
1179+
count_footers-=2;
1180+
}
1181+
else
1182+
count_footers-=1;
1183+
termPQExpBuffer(&tmpbuf);
1184+
11681185
footers[count_footers++]=pg_strdup(buf.data);
11691186
}
11701187
}
@@ -1265,7 +1282,7 @@ describeOneTableDetails(const char *schemaname,
12651282
}
12661283

12671284
add_tablespace_footer(tableinfo.relkind,tableinfo.tablespace,
1268-
footers,&count_footers,buf);
1285+
footers,&count_footers,buf, true);
12691286
/* end of list marker */
12701287
footers[count_footers]=NULL;
12711288

@@ -1317,9 +1334,13 @@ describeOneTableDetails(const char *schemaname,
13171334
}
13181335

13191336

1320-
staticvoid
1337+
/*
1338+
* Return true if the relation uses non default tablespace;
1339+
* otherwise return false
1340+
*/
1341+
staticbool
13211342
add_tablespace_footer(charrelkind,Oidtablespace,char**footers,
1322-
int*count,PQExpBufferDatabuf)
1343+
int*count,PQExpBufferDatabuf,boolnewline)
13231344
{
13241345
/* relkinds for which we support tablespaces */
13251346
if (relkind=='r'||relkind=='i')
@@ -1336,17 +1357,23 @@ add_tablespace_footer(char relkind, Oid tablespace, char **footers,
13361357
"WHERE oid = '%u';",tablespace);
13371358
result1=PSQLexec(buf.data, false);
13381359
if (!result1)
1339-
return;
1360+
return false;
13401361
/* Should always be the case, but.... */
13411362
if (PQntuples(result1)>0)
13421363
{
1343-
printfPQExpBuffer(&buf,_("Tablespace: \"%s\""),
1344-
PQgetvalue(result1,0,0));
1364+
printfPQExpBuffer(&buf,
1365+
newline?_("Tablespace: \"%s\""):_("tablespace \"%s\""),
1366+
PQgetvalue(result1,0,0));
1367+
13451368
footers[(*count)++]=pg_strdup(buf.data);
13461369
}
13471370
PQclear(result1);
1371+
1372+
return true;
13481373
}
13491374
}
1375+
1376+
return false;
13501377
}
13511378

13521379
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp