Re: plpgsql memory leaks

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: plpgsql memory leaks
Дата
Msg-id CAFj8pRATsUvX0j8g9GcXC8N_9w-igEwuBqjAcbrZhL8Jq6uDZw@mail.gmail.com
обсуждение исходный текст
Ответ на plpgsql memory leaks  (Pavel Stehule <pavel.stehule@gmail.com>)
Ответы Re: plpgsql memory leaks  (Michael Banck <mbanck@gmx.net>)
Список pgsql-hackers


pá 12. 1. 2024 v 10:27 odesílatel Pavel Stehule <pavel.stehule@gmail.com> napsal:
Hi

I have reported very memory expensive pattern:

CREATE OR REPLACE FUNCTION public.fx(iter integer)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  c cursor(m bigint) for select distinct i from generate_series(1, m) g(i);
  t bigint;
  s bigint;
begin
  for i in 1..iter
  loop
    open c(m := i * 10000);
    s := 0;
    loop
      fetch c into t;
      exit when not found;
      s := s + t;
    end loop;
    close c; raise notice '%=%', i, s;
  end loop;
end;
$function$
;

This script takes for 100 iterations 100MB

but rewritten

CREATE OR REPLACE FUNCTION public.fx(iter integer)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
declare
  t bigint;
  s bigint;
begin
  for i in 1..iter
  loop
    s := 0;
    for t in select  ic from generate_series(1, i * 10000) g(ic)
    loop
      s := s + t;
    end loop;
    raise notice '%=%', i, s;
  end loop;
end;
$function$

takes lot of megabytes of memory too.

The megabytes leaks are related to JIT. With JIT off the memory consumption is significantly less  although there are some others probably.

regards

Pavel


Regards

Pavel

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

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: alter table add x wrong error position
Следующее
От: Bharath Rupireddy
Дата:
Сообщение: Re: A failure in t/038_save_logical_slots_shutdown.pl