create table dim1 (id serial primary key, val text);
create table dim2 (id serial primary key, val text);
create table dim3 (id serial primary key, val text);
create table dim4 (id serial primary key, val text);
create table t (id serial primary key, id1 int, id2 int, id3 int, id4 int, r double precision);

insert into dim1 (val) select md5(i::text) from generate_series(1,10000000) s(i);
insert into dim2 (val) select md5(i::text) from generate_series(1,10000000) s(i);
insert into dim3 (val) select md5(i::text) from generate_series(1,10000000) s(i);
insert into dim4 (val) select md5(i::text) from generate_series(1,10000000) s(i);
insert into t (id1, id2, id3, id4, r) select 1 + mod((random() * 100000000)::int,10000000), 1 + mod((random() * 100000000)::int,10000000), 1 + mod((random() * 100000000)::int,10000000), 1 + mod((random() * 100000000)::int,10000000), random() from generate_series(1, 100000000) s(x);
create index on t(r);
