pl/python long-lived allocations in datum->dict transformation

Поиск
Список
Период
Сортировка
От Jan Urbański
Тема pl/python long-lived allocations in datum->dict transformation
Дата
Msg-id 4F2ED053.1010904@wulczer.org
обсуждение исходный текст
Ответы Re: pl/python long-lived allocations in datum->dict transformation  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Consider this:

create table arrays as select array[random(), random(), random(),
random(), random(), random()] as a from generate_series(1, 1000000);

create or replace function plpython_outputfunc() returns void as $$
c = plpy.cursor('select a from arrays')
for row in c:
    pass
$$ language plpythonu;

When running the function, every datum will get transformed into a
Python dict, which includes calling the type's output function,
resulting in a memory allocation. The memory is allocated in the SPI
context, so it accumulates until the function is finished.

This is annoying for functions that plough through large tables, doing
some calculation. Attached is a patch that does the conversion of
PostgreSQL Datums into Python dict objects in a scratch memory context
that gets reset every time.

Cheers,
Jan

Вложения

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

Предыдущее
От: Jeff Davis
Дата:
Сообщение: Re: initdb and fsync
Следующее
От: Jan Urbański
Дата:
Сообщение: plpgsql leaking memory when stringifying datums