Re: Problem with index in OR'd expression

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: postgresql(dot)org(at)tgice(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Problem with index in OR'd expression
Date: 2006-12-23 03:31:28
Message-ID: 6293.1166844688@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

postgresql(dot)org(at)tgice(dot)com writes:
> select * from t where c1 = 75000;
> select * from t where ((0 is null) OR (c1 = 75000));

> The first one properly uses the index on c1, the second does not.
> Obviously, a human looking at the second one would realize it's
> essentially identical to the first and properly evaluate the (0 is null)
> part once (since it's immutable) and then ignore it for the rest of the
> searching.

Well, you could update --- 8.2 contains code to recognize that the IS
NULL expression is constant, but prior releases do not.

However, if you're hoping to do this:

> ((vC1 IS NULL) OR (C1 = vC1)) AND
> ((vC2 IS NULL) OR (C2 = vC2)) ...

you're still gonna lose because those are variables not constants ...

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-12-23 03:58:37 Re: psql "SCHEMA" switch
Previous Message Nikolay Samokhvalov 2006-12-23 01:34:54 Re: xml2 install problem