Re: Want function to be called only once in query

Поиск
Список
Период
Сортировка
От Steve Pritchard
Тема Re: Want function to be called only once in query
Дата
Msg-id CAF7Aqmz_go1rOEBAm6Wz87zXd82TxEpRrLd5_RxVaaKkv2ALog@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Want function to be called only once in query  (Jim Mlodgenski <jimmy76@gmail.com>)
Список pgsql-performance
> Add the MATERIALIZED keyword to the WITH statement

Many thanks Jim, that's just what I needed - that does the trick.

It's hard to keep abreast of these SQL changes. Thank goodness for mailing lists!

Steve

On Thu, 16 Sept 2021 at 11:56, Jim Mlodgenski <jimmy76@gmail.com> wrote:
On Thu, Sep 16, 2021 at 4:51 AM Steve Pritchard <steve.pritchard@bto.org> wrote:
>
> I have a PL/pgSQL function that I want to call within a query, but the function is fairly expensive to execute so I only want it executed once within the query. However the planner seems to reorganize my query so that it calls the function for every row.
>
> We were previously on Pg 9.6 and this wasn't a problem then. But now that we have upgraded to Pg 13, the behaviour has changed.
>

The behavior for planning a CTE changed in PG12.

> There must be a "proper" way to get the planner to call a function only once.
>
Add the MATERIALIZED keyword to the WITH statement


--
Steve Pritchard
Database Developer

British Trust for Ornithology, The Nunnery, Thetford, Norfolk IP24 2PU, UK 
Tel: +44 (0)1842 750050, fax: +44 (0)1842 750030
Registered Charity No 216652 (England & Wales) No SC039193 (Scotland)
Company Limited by Guarantee No 357284 (England & Wales)

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

Предыдущее
От: Jim Mlodgenski
Дата:
Сообщение: Re: Want function to be called only once in query
Следующее
От: Ulf Lohbrügge
Дата:
Сообщение: Query executed during pg_dump leads to excessive memory usage