Partial index where clause not filtering through

From: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
To: pgsql-performance(at)postgresql(dot)org
Subject: Partial index where clause not filtering through
Date: 2003-06-16 05:31:18
Message-ID: 20030616003118.S66185@flake.decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

I have the following index:
street_range__street_locality_high_low_v btree (street_name_id,
locality_id, addr_high_v, addr_low_v) WHERE (addr_high_v IS NOT NULL)

The query has a where clause like this:
FROM street_range s, input i
WHERE 1=1
AND i.address_v IS NOT NULL

AND s.locality_id = i.locality_id
AND s.street_name_id = i.street_name_id

AND s.addr_low_v <= i.address_v
AND s.addr_high_v >= i.address_v

As-is, it won't use the index. i.address_v IS NOT NULL AND s.addr_high_v
>= i.address_v should mandate that s.addr_high_v must be not-null, if
I'm remembering how nulls work correctly. (Actually, having any kind of
comparison on s.addr_high_v should mandate NOT NULL since NULL != NULL,
right?) Therefore the optimizer should be able to deduce that it can use
the index.

Adding AND s.addr_high_v IS NOT NULL to the where clause makes
everything work fine, so there is a work-around. Just seems like a minor
item to add to the TODO.
--
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?"

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Jim C. Nasby 2003-06-16 05:36:29 Re: left join performance problem
Previous Message Tom Lane 2003-06-16 05:28:26 Re: left join performance problem