Re: Which index methodology is better?-

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
      message can get through to the mailing list cleanly

[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux