drop table test1;
CREATE TABLE test1
(
  idnbr integer unique not null,
  num1 numeric(12,2),
  num2 numeric(12,2),
  text1 varchar(600)
);

create function fill_table(integer) returns integer as
'
DECLARE
  maxnum alias for $1;
  md5str text;
  startid integer;
BEGIN
  select coalesce(max(idnbr)+1,0) from test1 into startid;
  for i in 1..maxnum loop
      select substr(
	md5(random()) ||md5(random()) ||md5(random()) 
	||md5(random()) ||md5(random()) ||md5(random()) 
	||md5(random()) ||md5(random()) ||md5(random()) 
	||md5(random()) ||md5(random()) ||md5(random()) 
	||md5(random()) ||md5(random()) ||md5(random()) 
	||md5(random()) ||md5(random()) ||md5(random()),
	1,(200+random()*400)::integer
	) into md5str;
      insert into test1 values (startid+i,random()*10000, (random()*100)::integer, md5str);
  end loop;
  return maxnum;
END;
' language plpgsql;

truncate test1;
select fill_table(100000);
analyze test1;
update test1 set num1 = num1 + 0 where random() > 0.5;
-- These shouldn't take long at all for a table containing 100000 tuples + ~50000 dead tuples
vacuum verbose test1;
vacuum full verbose test1;

