drop table foo;
create table foo(a int, b int, c int);
insert into foo select 1,2,3 from generate_series(1,1000000);
vacuum foo;

set work_mem = '100MB';

\timing on

create or replace function ptest1_rec() returns void as $$
declare r record;
begin
  for r in select * from foo loop
    perform r.a + r.b + r.c;
  end loop;
end$$
language plpgsql stable;

select ptest1_rec();

create or replace function ptest1_row() returns void as $$
declare r foo;
begin
  for r in select * from foo loop
    perform r.a + r.b + r.c;
  end loop;
end$$
language plpgsql stable;

select ptest1_row();

create or replace function ptest2_rec() returns void as $$
declare r record;
begin
  for r in select * from foo loop
    r.a := r.b + r.c;
  end loop;
end$$
language plpgsql stable;

select ptest2_rec();

create or replace function ptest2_row() returns void as $$
declare r foo;
begin
  for r in select * from foo loop
    r.a := r.b + r.c;
  end loop;
end$$
language plpgsql stable;

select ptest2_row();

create or replace function ptest3_rec() returns void as $$
declare r record; t int;
begin
  for r in select * from foo loop
    t := r.b;
  end loop;
end$$
language plpgsql stable;

select ptest3_rec();

create or replace function ptest3_row() returns void as $$
declare r foo; t int;
begin
  for r in select * from foo loop
    t := r.b;
  end loop;
end$$
language plpgsql stable;

select ptest3_row();

create or replace function ptest4_rec() returns void as $$
declare r record; t int;
begin
  for r in select * from foo loop
    t := r.a + r.b + r.c;
  end loop;
end$$
language plpgsql stable;

select ptest4_rec();

create or replace function ptest4_row() returns void as $$
declare r foo; t int;
begin
  for r in select * from foo loop
    t := r.a + r.b + r.c;
  end loop;
end$$
language plpgsql stable;

select ptest4_row();
