Re: Understanding how partial indexes work?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Chris Velevitch" <chris(dot)velevitch(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Understanding how partial indexes work?
Date: 2007-12-06 15:39:20
Message-ID: 14932.1196955560@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Chris Velevitch" <chris(dot)velevitch(at)gmail(dot)com> writes:
> I have a query on a table:-
> X between k1 and k2 or X < k1 and Y <> k3

> where k1, k2, k3 are constants.

> How would this query work, if I created an index on X and a partial
> index on X where Y <> k3?

Is it worth the trouble? You didn't mention the statistics involved,
but ordinarily I'd think a non-equal condition is too nonselective
to justify the cost of maintaining an extra index.

The real problem here is that "X < k1" is probably too nonselective
as well, which will likely lead the planner to decide that a plain
seqscan is the cheapest solution. In principle the above could be
done with a BitmapOr of two indexscans on X, but unless the constants
are such that only a small fraction of rows are going to be selected,
it's likely that a seqscan is the way to go.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2007-12-06 15:39:56 Re: Understanding how partial indexes work?
Previous Message Abraham, Danny 2007-12-06 15:29:20 Question in dblink