Re: prepared statements suboptimal?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: prepared statements suboptimal?
Дата
Msg-id 17422.1194451906@sss.pgh.pa.us
обсуждение исходный текст
Ответ на prepared statements suboptimal?  (rihad <rihad@mail.ru>)
Ответы Re: prepared statements suboptimal?
Список pgsql-general
rihad <rihad@mail.ru> writes:
> I don't understand why postgres couldn't plan this:
> SELECT foo.e, foo.f
> FROM foo
> WHERE pk=$1 AND b=$2 AND status='1' AND c <= $3;

> to be later executed any slower than

> SELECT foo.e, foo.f
> FROM foo
> WHERE pk='abcabc' AND b='13' AND status='1' AND c <= '2007-11-20 13:14:15';

The reason is that without knowing the parameter values, the planner has
to pick a "generic" plan that will hopefully not be too awful regardless
of what the actual values end up being.  When it has the actual values
it can make much tighter estimates of the number of matching rows, and
possibly choose a much better but special-purpose plan.  As an example,
if the available indexes are on b and c then the best query plan for the
first case is probably bitmap indexscan on b.  But in the second case,
the planner might be able to determine (by consulting the ANALYZE stats)
that there are many rows matching b='13' but very few rows with c <=
'2007-11-20 13:14:15', so for those specific parameter values an
indexscan on c would be better.  It would be folly to choose that as the
generic plan, though, since on the average a one-sided inequality on c
could be expected to not be very selective at all.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: The .pgpass file
Следующее
От: Tom Lane
Дата:
Сообщение: Re: any way for ORDER BY x to imply NULLS FIRST in 8.3?