create or replace function create_test_hash() returns bool as $$ declare coll bigint default 500; -- tweak this to where create index gets really slow max_coll bigint default 50000000; begin loop raise notice 'staring %', coll; execute 'create table test_hash_'|| coll ||'(num int8);'; execute 'insert into test_hash_'|| coll ||' (num) select n from generate_series(0, '|| max_coll ||') as n;'; execute 'insert into test_hash_'|| coll ||' (num) select (n+4294967296) * '|| max_coll ||'/'|| coll ||'::int from generate_series(0, '|| coll ||') as n;'; coll := coll * 2; exit when coll >= max_coll; end loop; return true; end $$ language 'plpgsql';