Unexpected memory usage for repeated inserts within plpgsql function

Поиск
Список
Период
Сортировка
От happy times
Тема Unexpected memory usage for repeated inserts within plpgsql function
Дата
Msg-id tencent_5C738ECA65BAD6861AA43E8F@qq.com
обсуждение исходный текст
Ответы Re: Unexpected memory usage for repeated inserts within plpgsql function  (Dilip Kumar <dilipbalaut@gmail.com>)
Список pgsql-hackers
Hi Hackers,

I have been seeing memory usage increasing for a simple plpgsql function. Could you please take a look and check is it a bug?

The function definition is:

create function f() returns int as
$$DECLARE count int;
BEGIN
    count := 1;
    LOOP
        count := count + 1;

        begin

            EXECUTE 'insert into test values(10)';

            IF count > 1000000 THEN
                EXIT;
            END IF;
        exception when others then

        end;
    END LOOP;

END$$
LANGUAGE plpgsql;

When I ran this function by "select f()", from top command, I could see memory usage (Resident memory) kept on increasing:


Then I used gdb to suspend the process each time insert was actually executed, and issued "   (gdb) p MemoryContextStats(TopMemoryContext) ". From the server log, I saw only "SPI Proc" part of all the memory contexts was increasing:


My question: Is this problem as-designed?

Thank you for your time!!
Guangzhou

Вложения

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

Предыдущее
От: Kyotaro HORIGUCHI
Дата:
Сообщение: Re: [BUG] pg_basebackup from disconnected standby fails
Следующее
От: Jim Mlodgenski
Дата:
Сообщение: Re: PoC: Make it possible to disallow WHERE-less UPDATE and DELETE