Re: Which index methodology is better?-

From: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
To: Chris Hoover <revoohc(at)gmail(dot)com>
Cc: PGSQL Performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Which index methodology is better?-
Date: 2007-11-05 20:07:59
Message-ID: 472F781F.6080200@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Merlin Moncure 2007-11-06 02:47:02 Re: Database connections and stored procs (functions)
Previous Message Tom Lane 2007-11-05 19:56:29 Re: Which index methodology is better?-