Re: Why does a simple query not use an obvious index?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Why does a simple query not use an obvious index?
Дата
Msg-id 8089.1093884443@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Why does a simple query not use an obvious index?  ("Steinar H. Gunderson" <sgunderson@bigfoot.com>)
Список 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 по дате отправления:

Предыдущее
От: "Steinar H. Gunderson"
Дата:
Сообщение: Re: Why does a simple query not use an obvious index?
Следующее
От: Martin Sarsale
Дата:
Сообщение: seqscan instead of index scan