create or replace function bench_create(r int, n int) returns void as
$$
begin
  perform pg_advisory_lock(r);
  execute 'create table bench_' || r || ' (v int)';
  execute 'insert into bench_' || r || ' select v from generate_series(1,$1) v' using n;
end;
$$ language plpgsql;

create or replace function bench_read(r int) returns void as
$$
begin
  execute 'select count(*) from bench_' || r;
end;
$$ language plpgsql;

create or replace function bench_delete(r int) returns void as
$$
begin
  execute 'delete from bench_' || r;
end;
$$ language plpgsql;

create or replace function bench_drop(r int) returns void as
$$
begin
  execute 'drop table bench_' || r;
  perform pg_advisory_unlock(r);
end;
$$ language plpgsql;

  
