Re: Why does a simple query not use an obvious index? - Mailing list pgsql-performance

From Tom Lane
Subject Re: Why does a simple query not use an obvious index?
Date
Msg-id 8089.1093884443@sss.pgh.pa.us
Whole thread Raw
In response to Re: Why does a simple query not use an obvious index?  ("Steinar H. Gunderson" <sgunderson@bigfoot.com>)
List pgsql-performance
"Steinar H. Gunderson" <sgunderson@bigfoot.com> writes:
> On Sun, Aug 29, 2004 at 06:03:43PM -0400, Tom Lane wrote:
>> The expression "now() - something" is not a constant, so the planner
>> is faced with "timestampfield > unknownvalue".

> Out of curiosity, does the subselect query I presented earlier in the thread
> count as "a constant"? It gives the correct query plan, but this could of
> course just be correct by accident...

That was on 7.2, wasn't it?  I don't remember any longer exactly how 7.2
does this stuff, but it's different from 7.3 and later (and certainly
not any more "right").

You did at one time need to hide now() in a subselect to get the planner
to consider an indexscan at all --- that was before we made the
distinction between immutable and stable functions, and so now() had
to be treated as unsafe to index against (just as random() still is).
I think 7.2 behaved that way but I'm not totally sure.

            regards, tom lane

pgsql-performance by date:

Previous
From: "Steinar H. Gunderson"
Date:
Subject: Re: Why does a simple query not use an obvious index?
Next
From: Martin Sarsale
Date:
Subject: seqscan instead of index scan