Re: [pgsql-hackers-win32] Poor Performance for large queries

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: [pgsql-hackers-win32] Poor Performance for large queries
Дата
Msg-id 415A74EB.9040308@archonet.com
обсуждение исходный текст
Ответ на Re: [pgsql-hackers-win32] Poor Performance for large queries in functions  (John Meinel <john@johnmeinel.com>)
Ответы Re: [pgsql-hackers-win32] Poor Performance for large queries  (John Meinel <john@johnmeinel.com>)
Список pgsql-performance
John Meinel wrote:
>
> So notice that when doing the actual select it is able to do the index
> query. But for some reason with a prepared statement, it is not able to
> do it.
>
> Any ideas?

In the index-using example, PG knows the value you are comparing to. So,
it can make a better estimate of how many rows will be returned. With
the prepared/compiled version it has to come up with a plan that makes
sense for any value.

If you look back at the explain output you'll see PG is guessing 181,923
rows will match with the prepared query but only 1 for the second query.
If in fact you returned that many rows, you wouldn't want to use the
index - it would mean fetching values twice.

The only work-around if you are using plpgsql functions is to use
EXECUTE to make sure your queries are planned for each value provided.

--
   Richard Huxton
   Archonet Ltd

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

Предыдущее
От: John Meinel
Дата:
Сообщение: Re: [pgsql-hackers-win32] Poor Performance for large queries in functions
Следующее
От: Steven Rosenstein
Дата:
Сообщение: Re: This query is still running after 10 hours...