pg.ddx.io pgsql-performance@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Heikki Linnakangas <heikki@enterprisedb.com>
To: Chris Hoover <revoohc@gmail.com>
Cc: PGSQL Performance <pgsql-performance@postgresql.org>
Subject: Re: Which index methodology is better?-
Date: Mon, 05 Nov 2007 20:07:59 +0000
Message-ID: <472F781F.6080200@enterprisedb.com> (raw)
In-Reply-To: <1d219a6f0711051043x569b7f51r4cee3353e6ea9f10@mail.gmail.com>
References: <1d219a6f0711051043x569b7f51r4cee3353e6ea9f10@mail.gmail.com>
Chris Hoover wrote:
> On this table, a customer can search by customer_id, customer_l_name,
> and customer_f_name.
>
> Is it better to create 3 indexes, or one index on the three columns?
>
> I did some initial testing with index customer_test_idx(customer_id,
> customer_l_name, customer_f_name) and postgres would use the index for
> select * from customer where customer_f_name = 'zxy' - so the single
> index will cover the three.
Postgres can use the index in that case, but it's going to have to scan
the whole index, which is a lot slower than looking up just the needed
rows. If you do an EXPLAIN ANALYZE on that query, and compare it against
"select * from customer where customer_id = 123", you'll see that it's a
lot more expensive.
I'd recommend having separate indexes. Having just one index probably
does take less space, but the fact that you don't have to always scan
all of it probably outweighs that.
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
view thread (3+ messages)
Message-ID: <472F781F.6080200@enterprisedb.com> Permalink: ../472F781F.6080200@enterprisedb.com/ Also on: postgresql.org/message-id/472F781F.6080200@enterprisedb.com ·
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 using the --to and --cc options: reply via email To: pgsql-performance@postgresql.org Cc: heikki@enterprisedb.com, revoohc@gmail.com Subject: Re: Which index methodology is better?- In-Reply-To: <472F781F.6080200@enterprisedb.com> * 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