Re: Which index methodology is better?- - Mailing list pgsql-performance

From Heikki Linnakangas
Subject Re: Which index methodology is better?-
Date
Msg-id 472F781F.6080200@enterprisedb.com
Whole thread Raw
In response to Which index methodology is better?-  ("Chris Hoover" <revoohc@gmail.com>)
Responses Is ANALYZE transactional?  (Craig James <craig_james@emolecules.com>)
List 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

pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: Which index methodology is better?-
Next
From: "Merlin Moncure"
Date:
Subject: Re: Database connections and stored procs (functions)