Re: Creating indexes?

From: Greg Smith <greg(at)2ndquadrant(dot)com>
To: Bjørn T Johansen <btj(at)havleik(dot)no>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Creating indexes?
Date: 2010-04-22 21:53:02
Message-ID: 4BD0C53E.3080900@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bjørn T Johansen wrote:
> What is the best approach for PostgreSQL when creating indexes? E.g I have two fields in a table that I want indexed, is it best to create one index
> combining the two fields or creating one for each field? If I create one for each field, will the search when using both fields be slower that a
> combined index?
>

http://www.postgresql.org/docs/current/static/indexes-bitmap-scans.html
covers the basis here. There is some amount of additional overhead in
keeping around and using two indexes on a single field as opposed to one
two-field index, particularly in terms of disk space used. However, the
result is enormously more flexible. Having two single-column indexes
can satisfy all sorts of queries that the combined index wouldn't be a
help on, and the overhead of combining the index results together is low.

--
Greg Smith 2ndQuadrant US Baltimore, MD
PostgreSQL Training, Services and Support
greg(at)2ndQuadrant(dot)com www.2ndQuadrant.us

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bob Pawley 2010-04-22 22:24:56 Foreign Key
Previous Message Bjørn T Johansen 2010-04-22 21:36:51 Creating indexes?