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"
Index: describe.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/describe.c,v
retrieving revision 1.115
diff -c -r1.115 describe.c
*** describe.c 6 Apr 2005 05:23:32 -0000 1.115
--- describe.c 4 Jun 2005 06:37:36 -0000
***************
*** 37,44 ****
const char *schemavar, const char *namevar,
const char *altnamevar, const char
*visibilityrule);
! static void add_tablespace_footer(char relkind, Oid tablespace,
! char **footers, int *count,
PQExpBufferData buf);
/*----------------
* Handlers for various slash commands displaying some sort of list
--- 37,44 ----
const char *schemavar, const char *namevar,
const char *altnamevar, const char
*visibilityrule);
! static bool add_tablespace_footer(char relkind, Oid tablespace, char
**footers,
!
int *count, PQExpBufferData buf, bool newline);
/*----------------
* Handlers for various slash commands displaying some sort of list
***************
*** 942,948 ****
footers = pg_malloc_zero(4 * sizeof(*footers));
footers[count_footers++] = pg_strdup(tmpbuf.data);
add_tablespace_footer(tableinfo.relkind,
tableinfo.tablespace,
! footers,
&count_footers, tmpbuf);
footers[count_footers] = NULL;
}
--- 942,948 ----
footers = pg_malloc_zero(4 * sizeof(*footers));
footers[count_footers++] = pg_strdup(tmpbuf.data);
add_tablespace_footer(tableinfo.relkind,
tableinfo.tablespace,
! footers,
&count_footers, tmpbuf, true);
footers[count_footers] = NULL;
}
***************
*** 1022,1028 ****
{
printfPQExpBuffer(&buf,
"SELECT c2.relname,
i.indisprimary, i.indisunique, i.indisclustered, "
!
"pg_catalog.pg_get_indexdef(i.indexrelid, 0, true)\n"
"FROM
pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
"WHERE c.oid = '%s'
AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
"ORDER BY
i.indisprimary DESC, i.indisunique DESC, c2.relname",
--- 1022,1028 ----
{
printfPQExpBuffer(&buf,
"SELECT c2.relname,
i.indisprimary, i.indisunique, i.indisclustered, "
!
"pg_catalog.pg_get_indexdef(i.indexrelid, 0, true), c2.reltablespace\n"
"FROM
pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
"WHERE c.oid = '%s'
AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
"ORDER BY
i.indisprimary DESC, i.indisunique DESC, c2.relname",
***************
*** 1142,1147 ****
--- 1142,1148 ----
{
const char *indexdef;
const char *usingpos;
+ PQExpBufferData tmpbuf;
/* Output index name */
printfPQExpBuffer(&buf, _(" \"%s\""),
***************
*** 1165,1170 ****
--- 1166,1187 ----
if (strcmp(PQgetvalue(result1, i, 3), "t") == 0)
appendPQExpBuffer(&buf, " CLUSTER");
+ /* Print tablespace of the index on the same
line */
+ count_footers += 1;
+ initPQExpBuffer(&tmpbuf);
+ if (add_tablespace_footer('i',
+
atooid(PQgetvalue(result1, i, 5)),
+
footers, &count_footers, tmpbuf, false))
+ {
+ appendPQExpBuffer(&buf, ", ");
+ appendPQExpBuffer(&buf, tmpbuf.data);
+
+ count_footers -= 2;
+ }
+ else
+ count_footers -= 1;
+ termPQExpBuffer(&tmpbuf);
+
footers[count_footers++] = pg_strdup(buf.data);
}
}
***************
*** 1265,1271 ****
}
add_tablespace_footer(tableinfo.relkind, tableinfo.tablespace,
! footers,
&count_footers, buf);
/* end of list marker */
footers[count_footers] = NULL;
--- 1282,1288 ----
}
add_tablespace_footer(tableinfo.relkind, tableinfo.tablespace,
! footers,
&count_footers, buf, true);
/* end of list marker */
footers[count_footers] = NULL;
***************
*** 1317,1325 ****
}
! static void
add_tablespace_footer(char relkind, Oid tablespace, char **footers,
! int *count, PQExpBufferData buf)
{
/* relkinds for which we support tablespaces */
if (relkind == 'r' || relkind == 'i')
--- 1334,1346 ----
}
! /*
! * Return true if the relation uses non default tablespace;
! * otherwise return false
! */
! static bool
add_tablespace_footer(char relkind, Oid tablespace, char **footers,
! int *count, PQExpBufferData buf, bool
newline)
{
/* relkinds for which we support tablespaces */
if (relkind == 'r' || relkind == 'i')
***************
*** 1336,1352 ****
"WHERE oid = '%u';",
tablespace);
result1 = PSQLexec(buf.data, false);
if (!result1)
! return;
/* Should always be the case, but.... */
if (PQntuples(result1) > 0)
{
! printfPQExpBuffer(&buf, _("Tablespace: \"%s\""),
!
PQgetvalue(result1, 0, 0));
footers[(*count)++] = pg_strdup(buf.data);
}
PQclear(result1);
}
}
}
/*
--- 1357,1379 ----
"WHERE oid = '%u';",
tablespace);
result1 = PSQLexec(buf.data, false);
if (!result1)
! return false;
/* Should always be the case, but.... */
if (PQntuples(result1) > 0)
{
! printfPQExpBuffer(&buf,
! newline?_("Tablespace:
\"%s\""):_("tablespace \"%s\""),
! PQgetvalue(result1, 0, 0));
!
footers[(*count)++] = pg_strdup(buf.data);
}
PQclear(result1);
+
+ return true;
}
}
+
+ return false;
}
/*
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend