> Would a rule be that
> if the first attribute of an index is unique, then additional
> attributes are basically useless?

For PostgreSQL this is currently true, since indexes are currently not
used for order by. If you have a unique first column in an index,
then all following columns could only be used for sorting,
not for faster access (access actually gets worse).

Andreas


Mon, 30 Mar 1998 20:19:01 +0200
Zeugswetter Andreas SARZ <Andreas.Zeugswetter@telecom.at>
AW: [HACKERS] Re: Let's talk up 6.3
> 
> > Would a rule be that
> > if the first attribute of an index is unique, then additional
> > attributes are basically useless?
> 
> For PostgreSQL this is currently true, since indexes are currently not
> used for order by. If you have a unique first column in an index,
> then all following columns could only be used for sorting,
> not for faster access (access actually gets worse).

Sorry, don't follow this logic.  He is not restricting on the first
field of the index, so the index is not used.

-- 
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)

Mon, 30 Mar 1998 13:35:34 -0500 (EST)
Bruce Momjian <maillist@candle.pha.pa.us>
Re: AW: [HACKERS] Re: Let's talk up 6.3
Andreas:
> > Would a rule be that
> > if the first attribute of an index is unique, then additional
> > attributes are basically useless?
> 
> For PostgreSQL this is currently true, since indexes are currently not
> used for order by. If you have a unique first column in an index,
> then all following columns could only be used for sorting,
> not for faster access (access actually gets worse).

The rule 'if the first attribute of an index is unique, then additional
attributes are basically useless' is exactly correct for all systems, not
just PostgreSQL. It has nothing to do with whether indexes are used for
'orderby'.

A bit of thought will reveal that if the first key is unique then there
is no way any subsequent key can influence the sort order. Consider:

 col1 col2
 ---- ----
  A    9
  B    5
  C    1
 ...  ...

There is no value you can put in col2 that will make 'A' sort after 'B'.

-dg

David Gould            dg@illustra.com           510.628.3783 or 510.305.9468 
Informix Software  (No, really)         300 Lakeside Drive  Oakland, CA 94612
"Of course, someone who knows more about this will correct me if I'm wrong,
 and someone who knows less will correct me if I'm right."
               --David Palmer (palmer@tybalt.caltech.edu)

Mon, 30 Mar 1998 11:14:18 -0800 (PST)
dg@illustra.com (David Gould)
Re: AW: [HACKERS] Re: Let's talk up 6.3