Re: Rethinking plpgsql's assignment implementation

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: Rethinking plpgsql's assignment implementation
Дата
Msg-id CAFj8pRAPuA69CAm75DLk7+-HP69ryFGGqJ9Sy1D0PmuUPO-hcQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Rethinking plpgsql's assignment implementation  (Pavel Stehule <pavel.stehule@gmail.com>)
Ответы Re: Rethinking plpgsql's assignment implementation  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hi

I checked a performance and it looks so access to record's field is faster, but an access to arrays field is significantly slower

do $$
declare
  a int[];
  aux int;
  rep boolean default true;
begin
  for i in 1..5000
  loop
    a[i]:= 5000 - i;
  end loop;
 
  raise notice '%', a[1:10];

  while rep
  loop
    rep := false;
    for i in 1..5000
    loop
      if a[i] > a[i+1] then
        aux := a[i];
        a[i] := a[i+1]; a[i+1] := aux;
        rep := true;
      end if;
    end loop;
  end loop;

  raise notice '%', a[1:10];

end;
$$;

This code is about 3x slower than master (40 sec x 12 sec). I believe so this is a worst case scenario

I tested pi calculation

CREATE OR REPLACE FUNCTION pi_est_1(n int)
RETURNS numeric AS $$
DECLARE
  accum double precision DEFAULT 1.0;
  c1 double precision DEFAULT 2.0;
  c2 double precision DEFAULT 1.0;
BEGIN            
  FOR i IN 1..n
  LOOP              
    accum := accum * ((c1 * c1) / (c2 * (c2 + 2.0)));                  
    c1 := c1 + 2.0;                  
    c2 := c2 + 2.0;                  
  END LOOP;
  RETURN accum * 2.0;                  
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION pi_est_2(n int)
RETURNS numeric AS $$
DECLARE
  accum double precision DEFAULT 1.0;
  c1 double precision DEFAULT 2.0;
  c2 double precision DEFAULT 1.0;
BEGIN
  FOR i IN 1..n
  LOOP
    accum := accum * ((c1 * c1) / (c2 * (c2 + double precision '2.0')));
    c1 := c1 + double precision '2.0';
    c2 := c2 + double precision '2.0';
  END LOOP;
  RETURN accum * double precision '2.0';
END;
$$ LANGUAGE plpgsql;

And the performance is 10% slower than on master

Interesting point - the master is about 5% faster than pg13




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

Предыдущее
От: Michael Paquier
Дата:
Сообщение: Re: pg_waldump error message fix
Следующее
От: Bharath Rupireddy
Дата:
Сообщение: Re: Fail Fast In CTAS/CMV If Relation Already Exists To Avoid Unnecessary Rewrite, Planning Costs