drop table if exists f;
drop table if exists c0;
drop table if exists c1;
drop table if exists c2;
drop table if exists c3;
drop table if exists c4;
drop table if exists c5;
drop table if exists c6;
drop table if exists c7;
drop table if exists c8;
drop table if exists c9;
drop table if exists c10;
drop table if exists c11;
drop table if exists c12;
drop table if exists c13;

create table c13 (id int primary key, val text);
create table c12 (id int primary key, val text, c13_id int references c13(id));
create table c11 (id int primary key, val text, c12_id int references c12(id));
create table c10 (id int primary key, val text, c11_id int references c11(id));
create table c9 (id int primary key, val text, c10_id int references c10(id));
create table c8 (id int primary key, val text, c9_id int references c9(id));
create table c7 (id int primary key, val text, c8_id int references c8(id));
create table c6 (id int primary key, val text, c7_id int references c7(id));
create table c5 (id int primary key, val text, c6_id int references c6(id));
create table c4 (id int primary key, val text, c5_id int references c5(id));
create table c3 (id int primary key, val text, c4_id int references c4(id));
create table c2 (id int primary key, val text, c3_id int references c3(id));
create table c1 (id int primary key, val text, c2_id int references c2(id));
create table c0 (id int primary key, val text, c1_id int references c1(id));

create table f (id int primary key,  val text, c0_id int references c0(id));


insert into c13 select i, md5(i::text) from generate_series(1,1000) s(i);
insert into c12 select i, md5(i::text), floor(random() * 1000)::int + 1 from generate_series(1,1000) s(i);
insert into c11 select i, md5(i::text), floor(random() * 1000)::int + 1 from generate_series(1,1000) s(i);
insert into c10 select i, md5(i::text), floor(random() * 1000)::int + 1 from generate_series(1,1000) s(i);
insert into c9 select i, md5(i::text), floor(random() * 1000)::int + 1 from generate_series(1,1000) s(i);
insert into c8 select i, md5(i::text), floor(random() * 1000)::int + 1 from generate_series(1,1000) s(i);
insert into c7 select i, md5(i::text), floor(random() * 1000)::int + 1 from generate_series(1,1000) s(i);
insert into c6 select i, md5(i::text), floor(random() * 1000)::int + 1 from generate_series(1,1000) s(i);
insert into c5 select i, md5(i::text), floor(random() * 1000)::int + 1 from generate_series(1,1000) s(i);
insert into c4 select i, md5(i::text), floor(random() * 1000)::int + 1 from generate_series(1,1000) s(i);
insert into c3 select i, md5(i::text), floor(random() * 1000)::int + 1 from generate_series(1,1000) s(i);
insert into c2 select i, md5(i::text), floor(random() * 1000)::int + 1 from generate_series(1,1000) s(i);
insert into c1 select i, md5(i::text), floor(random() * 1000)::int + 1 from generate_series(1,1000) s(i);
insert into c0 select i, md5(i::text), floor(random() * 1000)::int + 1 from generate_series(1,10000) s(i);

insert into f
select
    i,
    md5(i::text),
     floor(random() * 10000)::int + 1
from generate_series(1,10000) s(i);

vacuum analyze;
