Re: Prepared statements versus stored procedures

Поиск
Список
Период
Сортировка
От Laurenz Albe
Тема Re: Prepared statements versus stored procedures
Дата
Msg-id 10fa77d60703bae073a2f301443db84fe903b139.camel@cybertec.at
обсуждение исходный текст
Ответ на Prepared statements versus stored procedures  (Simon Connah <simon.n.connah@protonmail.com>)
Ответы Re: Prepared statements versus stored procedures
Список pgsql-general
On Sun, 2023-11-19 at 17:30 +0000, Simon Connah wrote:
> I was reading about prepared statements and how they allow the server to
> plan the query in advance so that if you execute that query multiple times
> it gets sped up as the database has already done the planning work.
>
> My question is this. If I make a stored procedure doesn't the database
> already pre-plan and optimise the query because it has access to the whole
> query? Or could I create a stored procedure and then turn it into a prepared
> statement for more speed? I was also thinking a stored procedure would help
> as it requires less network round trips as the query is already on the server.

Statements in functions and procedures don't get planned until the function
or procedure is called for the first time.  These plans don't get cached unless
the procedural language you are using has special support for that.

Currently, only functions and procedures written in PL/pgSQL cache execution
plans of static SQL statements.  And you are right, that is usually a good thing.

Yours,
Laurenz Albe



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

Предыдущее
От: Laurenz Albe
Дата:
Сообщение: Re: pg_basebackup
Следующее
От: KK CHN
Дата:
Сообщение: pgBackRest on old installation