Re: Indexes intersection

From: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
To: Roberto de Amorim <rbamorim(at)ig(dot)com(dot)br>
Cc: pgsql-general(at)postgresql(dot)org, suporte(at)dbexperts(dot)com(dot)br
Subject: Re: Indexes intersection
Date: 2003-04-09 00:16:07
Message-ID: 20030408191607.S31861@flake.decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Apr 07, 2003 at 03:25:31PM -0300, Roberto de Amorim wrote:
> for example: I have 2 indexes, the first in on (date_inclusion ,
> date_cancellation ) and the other is in (date_cancellation ,
> date_inclusion ).
>
> so, when I do a query like this:
> select * from mytable
> where (date_inclusion <= '01/01/2003') and (date_cancellation >
> '01/01/2003')
>
> I think that PostgreSQL should use those 2 indexes and do an intersection
> automatically between they

I think you're not asking the question quite right. :) In this case, it
will use one index or the other, because both indexes contain both
fields. I'm guessing what you want to know is if you had two indexes

create index index_a on mytable(date_inclusion)
create index index_a on mytable(date_cancellation)

would the query you show use both indexes, or would it just pick one.

I don't know the answer, but would like to. :)
--
Jim C. Nasby (aka Decibel!) jim(at)nasby(dot)net
Member: Triangle Fraternity, Sports Car Club of America
Give your computer some brain candy! www.distributed.net Team #1828

Windows: "Where do you want to go today?"
Linux: "Where do you want to go tomorrow?"
FreeBSD: "Are you guys coming, or what?"

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Denis @ Next2Me 2003-04-09 00:21:16 Re: [SQL] Yet Another (Simple) Case of Index not used
Previous Message Denis @ Next2Me 2003-04-09 00:10:01 Re: [GENERAL] Yet Another (Simple) Case of Index not used