From: Jim C. Nasby <jim@nasby.net>
To: pgsql-performance@postgresql.org
Subject: Partial index where clause not filtering through
Date: Mon, 16 Jun 2003 00:31:18 -0500
Message-ID: <20030616003118.S66185@flake.decibel.org> (raw)
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@nasby.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?"
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: jim@nasby.net
Subject: Re: Partial index where clause not filtering through
In-Reply-To: <20030616003118.S66185@flake.decibel.org>
References: <20030616003118.S66185@flake.decibel.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox