Re: function slower than the same code in an sql file

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: function slower than the same code in an sql file
Дата
Msg-id 14399.1319778608@sss.pgh.pa.us
обсуждение исходный текст
Ответ на function slower than the same code in an sql file  (CS DBA <cs_dba@consistentstate.com>)
Ответы Re: function slower than the same code in an sql file  (CS DBA <cs_dba@consistentstate.com>)
Список pgsql-performance
CS DBA <cs_dba@consistentstate.com> writes:
> I have code that drops a table, re-create's it (based on a long set of
> joins) and then re-creates the indexes.

> It runs via psql in about 10 seconds.  I took the code and simply
> wrapped it into a plpgsql function and the function version takes almost
> 60 seconds to run.

> I always thought that functions should run faster than psql... am I wrong?

Did you really just put the identical queries into a function, or did
you parameterize them with values passed to the function?

Parameterized queries are often slower due to the planner not knowing
the specific constant values that are used in the actual calls.  There's
some work done for 9.2 to improve that, but in existing releases you
typically have to construct dynamic queries and EXECUTE them if you run
into this problem.

            regards, tom lane

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

Предыдущее
От: CS DBA
Дата:
Сообщение: function slower than the same code in an sql file
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: function slower than the same code in an sql file