From: | Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | jaitken(at)dimension(dot)net |
Cc: | tgl(at)sss(dot)pgh(dot)pa(dot)us, pgsql-sql(at)postgreSQL(dot)org |
Subject: | Re: [SQL] Single vs. multiple indexes |
Date: | 1998-07-09 18:13:29 |
Message-ID: | 199807091813.OAA00116@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
> Bruce Momjian writes:
> > Good question. The optimizer can only use only one index in a query, so
> > if you create five indexes, the optimizer will pick the best one to use,
> > and disregard the rest. If you create one index with five fields, it
> > will use as much of the index as it can. If you restrict on the first
> > field of the index, it will use only that part of the index. If you
> > restrict on the first three fields, it will use all three parts,
> > resulting in better performance than just having an index on the first
> > field.
> >
> > If you restrict only on the second field of the index, the index is
> > useless and will not be used.
> >
>
> Just to be sure I understand what you're saying here, let's assume
> I've got a table with three integer fields a, b, and c. I can do
> one of two things:
>
> 1. Create an index on (a), an index on (b), and an index on (c).
> 2. Create an index on (a, b, c).
>
> Now let's assume I perform a query that references b only. In this
> case, if I understand you correctly, method #1 above is better,
> because the index in method #2 will not be used.
>
> However, if I perform a query that references a and b, then method
> #2 would be better, because the composite index will be used,
> whereas in method #1, only one of the two relevant indices would be
> chosen?
Exactly.
--
Bruce Momjian | 830 Blythe Avenue
maillist(at)candle(dot)pha(dot)pa(dot)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)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 1998-07-09 18:58:39 | Is retrieval by OID a special case? |
Previous Message | Jeff Aitken | 1998-07-09 18:04:00 | Re: [SQL] Single vs. multiple indexes |