From adf1951107c728050c613356b6485ee7929940f6 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 4 Jun 1999 21:21:13 +0000 Subject: [PATCH] Suppress indexes on large objects from psql's \d listing; they were confusing because the large object tables themselves are not shown. (Besides, if you've got hundreds or thousands of large objects, you really don't want to see 'em at all.) Also, suppress all indexes from the \z ACL listing, since indexes have no meaningful protection information. --- src/bin/psql/psql.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/bin/psql/psql.c b/src/bin/psql/psql.c index 3d698384f6..048b85a627 100644 --- a/src/bin/psql/psql.c +++ b/src/bin/psql/psql.c @@ -421,6 +421,7 @@ tableList(PsqlSettings *pset, bool deep_tablelist, char info_type, char *rr; PGresult *res; int usePipe = 0; + bool haveIndexes = false; char *pagerenv; FILE *fout; @@ -440,27 +441,39 @@ tableList(PsqlSettings *pset, bool deep_tablelist, char info_type, listbuf[0] = '\0'; strcat(listbuf, "SELECT usename, relname, relkind, relhasrules "); strcat(listbuf, "FROM pg_class, pg_user "); + strcat(listbuf, "WHERE usesysid = relowner "); switch (info_type) { case 't': - strcat(listbuf, "WHERE ( relkind = 'r') "); + strcat(listbuf, "and ( relkind = 'r') "); break; case 'i': - strcat(listbuf, "WHERE ( relkind = 'i') "); + strcat(listbuf, "and ( relkind = 'i') "); + haveIndexes = true; break; case 'S': - strcat(listbuf, "WHERE ( relkind = 'S') "); + strcat(listbuf, "and ( relkind = 'S') "); break; case 'b': default: - strcat(listbuf, "WHERE ( relkind = 'r' OR relkind = 'i' OR relkind = 'S') "); + strcat(listbuf, "and ( relkind = 'r' OR relkind = 'i' OR relkind = 'S') "); + haveIndexes = true; break; } if (!system_tables) - strcat(listbuf, " and relname !~ '^pg_'"); + strcat(listbuf, "and relname !~ '^pg_' "); else - strcat(listbuf, " and relname ~ '^pg_'"); - strcat(listbuf, " and usesysid = relowner"); + strcat(listbuf, "and relname ~ '^pg_' "); + /* + * Large-object relations are automatically ignored because they have + * relkind 'l'. However, we want to ignore their indexes as well. + * The clean way to do that would be to do a join to find out which + * table each index is for. The ugly but fast way is to know that + * large object indexes have names starting with 'xinx'. + */ + if (haveIndexes) + strcat(listbuf, "and (relkind != 'i' OR relname !~ '^xinx') "); + strcat(listbuf, " ORDER BY relname "); if (!(res = PSQLexec(pset, listbuf))) return -1; @@ -603,10 +616,10 @@ rightsList(PsqlSettings *pset) listbuf[0] = '\0'; strcat(listbuf, "SELECT relname, relacl "); - strcat(listbuf, "FROM pg_class, pg_user "); - strcat(listbuf, "WHERE ( relkind = 'r' OR relkind = 'i' OR relkind = 'S') "); + strcat(listbuf, "FROM pg_class "); + /* Currently, we ignore indexes since they have no meaningful rights */ + strcat(listbuf, "WHERE ( relkind = 'r' OR relkind = 'S') "); strcat(listbuf, " and relname !~ '^pg_'"); - strcat(listbuf, " and usesysid = relowner"); strcat(listbuf, " ORDER BY relname "); if (!(res = PSQLexec(pset, listbuf))) return -1; -- 2.39.5