Re: Baffled by failure to use index when WHERE uses a function

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Clive Page <cgp(at)star(dot)le(dot)ac(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Baffled by failure to use index when WHERE uses a function
Date: 2006-03-10 09:57:54
Message-ID: 20060310095753.GA9260@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Mar 10, 2006 at 09:14:27AM +0000, Clive Page wrote:
> I have a table cov3 of about 3 million rows, with a B-tree index on an
> integer column called hpix. If I do a simple select on this column it
> works in milliseconds, using the index naturally:
>
> select * from cov3 where hpixint = 482787587;
^^^^^^^
That's not the column you said you were using and that your other
example uses. Have you verified that hpix has an index?

> So I would like to use this function to find rows, and I try for example:
>
> select * from cov3 where hpix = healpix(2.85,-11.48);
>
> but it takes ages. An EXPLAIN shows why, it insists upon a sequential
> scan:

If healpix() always returns the same output for given input then
define it to be IMMUTABLE. For more information see "Function
Volatility Categories" in the documentation.

http://www.postgresql.org/docs/8.1/interactive/xfunc-volatility.html

--
Michael Fuhr

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2006-03-10 10:36:19 Re: PL/pgSQL question
Previous Message Martijn van Oosterhout 2006-03-10 09:53:57 Re: Baffled by failure to use index when WHERE uses a function