Showing index details with \d on psql

From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: <pgsql-patches(at)postgresql(dot)org>
Subject: Showing index details with \d on psql
Date: 2001-10-07 01:09:14
Message-ID: 200110070109.VAA10810@smtp6.mindspring.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

While hacking around with psql, I came up with the idea of
identifying the columns in a table as to which index they
are in (and conversly, showing which columns an index
contains). I find this useful because a normal listing that
only tells you the name of the index is not very helpful
and usually needs a separate \d index_name entry. The only
concern is how to do it:
as a separate "index" column?
appending the name of the index to the Description column?
numbering the indexes and using the number to save space?
(The latter is used in the enclosed patch and
example below). Which columns the index affects follows the
name, and it also tells you if an index is a primary key. Here
is some sample output:

data=> \d mytable
Table "mytable"

Table "mytable"
Attribute | Type | Modifier

- -----------+-----------------------+-----------------------------
post | integer | not null (index #1)
thread | smallint | (index #2) (index #3)
reply | smallint | not null
subject | character varying(60) | default 'foo' (index #2)
Indices: 1. mytable_foobar (1) (PRIMARY KEY)
2. alphabet (4 2)
3. badname (2)

The numbers at the end of the index names are ugly, but it does
show you instantly the composition and order of the index. I
think once you get used to it, it can be very valuable and
save on calls to \d index_name. My big concern is the size that
each "(index #x)" takes up, but having them separate does make
them stand out more, and in most cases, columns will not belong
to a lot of indices.

The attached (rough) patch is against 7.1.2. Feedback
welcome, as always. :)

Greg Sabino Mullane
greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200110062052

-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html

iQA/AwUBO7+rPrybkGcUlkrIEQKz7gCcCyPUDAGGwMbwPa09Rc2pqMbD0cYAn1qY
Yw6/kJdux/vwdN4waU5rdPmH
=/PN6
-----END PGP SIGNATURE-----

Attachment Content-Type Size
unknown_filename text/plain 2.2 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Weiping He 2001-10-07 14:34:17 Re: Simplified Chinese translation file for nls support
Previous Message Rene Pijlman 2001-10-06 21:48:25 Re: JDBC test suite patch