pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedWhich index methodology is better?-
3+ messages / 3 participants
[nested] [flat]
* Which index methodology is better?-
@ 2007-11-05 18:43 Chris Hoover <revoohc@gmail.com>
0 siblings, 2 replies; 3+ messages in thread
From: Chris Hoover @ 2007-11-05 18:43 UTC (permalink / raw)
To: pgsql-performance
I have a question.
Consider this scenario.
Table customer (
customer_id int8,
customer_l_name varchar(35),
customer_f_name varchar(30),
customer_addr_1 varchar(100),\
customer_addr_2 varchar(100),
customer_city varchar(50),
customer_state char(2),
customer_zip varchar(9)
);
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.
My question is, is this better? Does it end up using less memory
and/or disk or more? I am trying to find ways to keep more of my
customers databases in memory, and I am thinking that loading one
index is probably a little better than loading three.
Thanks for any advice,
Chris
PG 8.1
RH 4.0
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Which index methodology is better?-
@ 2007-11-05 19:56 Tom Lane <tgl@sss.pgh.pa.us>
parent: Chris Hoover <revoohc@gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2007-11-05 19:56 UTC (permalink / raw)
To: Chris Hoover <revoohc@gmail.com>; +Cc: pgsql-performance
"Chris Hoover" <revoohc@gmail.com> writes:
> Is it better to create 3 indexes, or one index on the three columns?
This is covered in considerable detail in the fine manual:
http://www.postgresql.org/docs/8.2/static/indexes.html
See particularly sections 11.3 and 11.4
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Which index methodology is better?-
@ 2007-11-05 20:07 Heikki Linnakangas <heikki@enterprisedb.com>
parent: Chris Hoover <revoohc@gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Heikki Linnakangas @ 2007-11-05 20:07 UTC (permalink / raw)
To: Chris Hoover <revoohc@gmail.com>; +Cc: 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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2007-11-05 20:07 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-11-05 18:43 Which index methodology is better?- Chris Hoover <revoohc@gmail.com>
2007-11-05 19:56 ` Tom Lane <tgl@sss.pgh.pa.us>
2007-11-05 20:07 ` Heikki Linnakangas <heikki@enterprisedb.com>
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