Re: unnesting of array of different size explodes memory

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: unnesting of array of different size explodes memory
Дата
Msg-id 4785.1302706352@sss.pgh.pa.us
обсуждение исходный текст
Ответ на unnesting of array of different size explodes memory  (Andreas Gaab <A.Gaab@scanlab.de>)
Список pgsql-sql
Andreas Gaab <A.Gaab@scanlab.de> writes:
> As I now understand, the following query leads to 12 results, not just 4 (or 3...):

> SELECT unnest(ARRAY[1,2,3]), unnest(ARRAY[4,5,6,7]);

> Why could postgres use as much memory till the kernel complained when unnesting 1200 and 1300 elements resulting in
1.6e6rows. Are there settings to prevent this such as "work_mem"?
 

Multiple SRFs in a targetlist are a good thing to avoid.  The behavior
is ... um ... peculiar, and the fact that we can't reclaim memory
partway through is really the least of the problems with it.

Try doing it like this instead:

SELECT * from unnest(ARRAY[1,2,3]) a, unnest(ARRAY[4,5,6,7]) b;

This has saner behavior and is less likely to leak memory.  Not to
mention less likely to be deprecated or de-implemented altogether
in the far future.
        regards, tom lane


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

Предыдущее
От: Andreas Gaab
Дата:
Сообщение: unnesting of array of different size explodes memory
Следующее
От: Tom Lane
Дата:
Сообщение: Re: pass in array to function for use by where clause? how optimize?