Search Postgresql Archives

Re: Problem with index in OR'd expression

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



postgresql.org@xxxxxxxxx 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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux