pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Jackson, DeJuan <djackson@cpsgroup.com>
To: Bruce Momjian <maillist@candle.pha.pa.us>
To: jaitken@dimension.net
Cc: tgl@sss.pgh.pa.us
Cc: pgsql-sql@postgreSQL.org
Subject: RE: [SQL] Single vs. multiple indexes
Date: Fri, 10 Jul 1998 12:37:35 -0500
Message-ID: <F10BB1FAF801D111829B0060971D839F32157A@cpsmail> (raw)
> > 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.
>
But let's not forget one of the wonders of PostgreSQL. In this world
you can have your cake and eat it to. So, create all 4 indices and let
the optimizer sort em out for your queries.
-DEJ
view thread (6+ messages) latest in thread
Message-ID: <F10BB1FAF801D111829B0060971D839F32157A@cpsmail> Permalink: ../F10BB1FAF801D111829B0060971D839F32157A@cpsmail/ Also on: postgresql.org/message-id/F10BB1FAF801D111829B0060971D839F32157A@cpsmail ·
reply
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Reply to all the recipients from your mail client; the link fills in the headers below: reply via email Some clients, webmail especially, drop In-Reply-To and References from a link, and the reply then starts a new thread: use the mbox below. To: pgsql-sql@postgresql.org Cc: djackson@cpsgroup.com, maillist@candle.pha.pa.us, jaitken@dimension.net, tgl@sss.pgh.pa.us Subject: Re: [SQL] Single vs. multiple indexes In-Reply-To: <F10BB1FAF801D111829B0060971D839F32157A@cpsmail> References: <F10BB1FAF801D111829B0060971D839F32157A@cpsmail> * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox