Indexes, multicolumn or not?

From: "postgres" <postgres(at)hemaka(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Indexes, multicolumn or not?
Date: 2003-10-09 20:58:00
Message-ID: 003001c38ea8$06960210$6501a8c0@DDP7NX01
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I have finished a database and I'm in the process of optimizing my
queries. One of the things I am doing to accomplish this is to create
indexes on common queries, specially those invoke by triggers/rules by
common inserts. In one instance, I have a table that's something like
this

Create table sample
(
sample_id serial primary key,
numeric_flag int
);
--numeric_flag either null or 1. I decided not to use
Booleans on this particular database.

for this common query:

select * from sample where sample_id = n1 and numeric_flag = n2;

I have done something like this:

create index sample_idx on sample (sample_id,numeric_flag);

my question is: would it be better to just create to separate indexes
rather than a multicolumn index or perhaps the index on the primary key
is enough?

I also have a similar situation with primary keys and date columns, do a
multicolumn or separate. I am most confused by the statement in the
particular thread (link below) for it claims a query can only use one
index. so what is the point of multicolumns if that is true (or perhaps
article was posted before multicolumn features or something else I am
ignorant on)

http://archives.postgresql.org/pgsql-admin/2001-03/msg00033.php

Thank you in advance for any insight.

Browse pgsql-general by date

  From Date Subject
Next Message Gene Vital 2003-10-09 21:09:33 Re: Parent Id
Previous Message Patrick Welche 2003-10-09 20:49:52 Re: autoupdate sequences after copy