drop table if exists f;

drop table if exists d0;
drop table if exists d1;
drop table if exists d2;
drop table if exists d3;
drop table if exists d4;
drop table if exists d5;
drop table if exists d6;
drop table if exists d7;
drop table if exists d8;
drop table if exists d9;

create table d0 (id int primary key, val text);
create table d1 (id int primary key, val text);
create table d2 (id int primary key, val text);
create table d3 (id int primary key, val text);
create table d4 (id int primary key, val text);
create table d5 (id int primary key, val text);
create table d6 (id int primary key, val text);
create table d7 (id int primary key, val text);
create table d8 (id int primary key, val text);
create table d9 (id int primary key, val text);

create table f (id int primary key,
                id0 int references d0(id),
                id1 int references d1(id),
                id2 int references d2(id),
                id3 int references d3(id),
                id4 int references d4(id),
                id5 int references d5(id),
                id6 int references d6(id),
                id7 int references d7(id),
                id8 int references d8(id),
                id9 int references d9(id),
                val text);

insert into d0 select i, md5(i::text) from generate_series(1,1000) s(i);
insert into d1 select i, md5(i::text) from generate_series(1,1000) s(i);
insert into d2 select i, md5(i::text) from generate_series(1,1000) s(i);
insert into d3 select i, md5(i::text) from generate_series(1,1000) s(i);
insert into d4 select i, md5(i::text) from generate_series(1,1000) s(i);
insert into d5 select i, md5(i::text) from generate_series(1,1000) s(i);
insert into d6 select i, md5(i::text) from generate_series(1,1000) s(i);
insert into d7 select i, md5(i::text) from generate_series(1,1000) s(i);
insert into d8 select i, md5(i::text) from generate_series(1,1000) s(i);
insert into d9 select i, md5(i::text) from generate_series(1,1000) s(i);

insert into f
select i,
       1 + mod(11 * i,1000),
       1 + mod(13 * i,1000),
       1 + mod(17 * i,1000),
       1 + mod(23 * i,1000),
       1 + mod(29 * i,1000),
       1 + mod(31 * i,1000),
       1 + mod(37 * i,1000),
       1 + mod(41 * i,1000),
       1 + mod(43 * i,1000),
       1 + mod(47 * i,1000),
       md5(i::text)
from generate_series(1,10000) s(i);

vacuum analyze;
