Re: Showing index details with \d on psql

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: Showing index details with \d on psql
Date: 2001-10-13 23:19:54
Message-ID: 22541.1003015194@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

>> I don't like the '*' things. They look ugly and convey little
>> real information.

> They convey "this column is indexed" and also indicate in how many
> indexes it appears.

I tend to agree with Peter on that part ... the asterisks add more
clutter than information. I also think that they could lead to
ambiguity; for example, it's not obvious that the * is not part of
the default clause where there's a default.

I have a large number of problems with this part of your patch:

char *s = _("Indexes:");

! snprintf(buf, sizeof(buf), "%*s %s%s%s",
! (int)strlen(s),
! i == 0 ? s : "",
! PQgetvalue(result1, i, 0),
! strcmp(PQgetvalue(result1, i, 2), "t") == 0 ? _(" (primary key)") : "",
! strcmp(PQgetvalue(result1, i, 3), "t") == 0 ? _(" (unique)") : "");
!
! char indexchar[5]; /* Should be plenty */
! int indexnumber=0;
! char * indexlist = PQgetvalue(result1, i, 1);
! int j,found;
! for (j=0,found=0;j<=strlen(indexlist); j++) {
! if (indexlist[j] == 0 || indexlist[j] == 32) {
! indexnumber = atoi(indexchar);
! if (indexnumber>0) /* pg_class has a -2! */
! {
! strcat(cells[(indexnumber-1) * cols + 2],
! cells[(indexnumber-1) * cols +2][0] ? " *" : "*");
! strcat(buf, ++found==1 ? " (" : ", ");
! strcat(buf, cells[(indexnumber-1) * cols]);
! }
! indexchar[0] = '\0';
! }
! else { strcat(indexchar,&indexlist[j]); }
! }
! if (found) /* must cover for pg_class again */
! strcat(buf, ")");
footers[count_footers++] = xstrdup(buf);

Gripe #1: declarations after the start of a block are a C++-ism. They
are not legal in ANSI C.

Gripe #2: what is indexchar[], why is it being used without
initialization, and what is your justification for thinking 5 is enough
space?

Gripe #3: "32" is not a portable spelling of "' '".

Gripe #4: looks to me like it will fail when indexes are on columns
numbered 10 or above, because the loop will do strcat() multiple times.

Gripe #5: doing the wrong thing on indexes that mention system columns
(negative column numbers) isn't acceptable.

You are really doing things quite the hard way here anyhow, since
pg_get_indexdef would produce the info you want without so much work,
and with less dependency in psql on backend catalog details. I'd
suggest pulling the pg_get_indexdef result instead of indkey in the
SELECT, and then just print the part after USING.

BTW, "primary key" implies "unique", so I think it's not necessary to
print both annotations for a primary key.

regards, tom lane

In response to

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Peter Eisentraut 2001-10-14 20:50:21 Re: psql: default base and password reading
Previous Message Greg Sabino Mullane 2001-10-13 22:13:35 Re: Showing index details with \d on psql