-- number of foreign keys generated
\set n 1000

\o out.sql
select 'create table t' || x || ' (a int, b int, c int, d int, e int, f int, primary key(a,b,c,d,e,f));' from generate_series(1,:n) x(x);
\gexec

create table f1 (a int not null, b int not null, c int not null, d int not null, e int not null, f int not null);
select 'alter table f1 add constraint f1_t' || x || '_fkey foreign key (a,b,c,d,e,f) references t' || x from generate_series(1,:n) x(x);
\gexec

create table f2 (a int not null, b int not null, c int not null, d int not null, e int not null, f int not null);
select 'alter table f2 add constraint f2_t' || x || '_fkey foreign key (a,b,c,d,e,f) references t' || x from generate_series(1,:n) x(x);
\gexec

create table f3 (a int not null, b int not null, c int not null, d int not null, e int not null, f int not null);
select 'alter table f3 add constraint f3_t' || x || '_fkey foreign key (a,b,c,d,e,f) references t' || x from generate_series(1,:n) x(x);
\gexec

create table f4 (a int not null, b int not null, c int not null, d int not null, e int not null, f int not null);
select 'alter table f4 add constraint f4_t' || x || '_fkey foreign key (a,b,c,d,e,f) references t' || x from generate_series(1,:n) x(x);
\gexec

create table f5 (a int not null, b int not null, c int not null, d int not null, e int not null, f int not null);
select 'alter table f5 add constraint f5_t' || x || '_fkey foreign key (a,b,c,d,e,f) references t' || x from generate_series(1,:n) x(x);
\gexec

\o /dev/null

select 'explain analyze
select * from f1
inner join f2 on f1.a = f2.a and f1.b = f2.b and f1.c = f2.c and f1.d = f2.d and f1.e = f2.e and f1.f = f2.f' from generate_series(1,100) s(i);

\o explain-2.log

\gexec

\o /dev/null

select 'explain analyze
select * from f1
inner join f2 on f1.a = f2.a and f1.b = f2.b and f1.c = f2.c and f1.d = f2.d and f1.e = f2.e and f1.f = f2.f
inner join f3 on f1.a = f3.a and f1.b = f3.b and f1.c = f3.c and f1.d = f3.d and f1.e = f3.e and f1.f = f3.f' from generate_series(1,100) s(i);

\o explain-3.log

\gexec

\o /dev/null

select 'explain analyze
select * from f1
inner join f2 on f1.a = f2.a and f1.b = f2.b and f1.c = f2.c and f1.d = f2.d and f1.e = f2.e and f1.f = f2.f
inner join f3 on f1.a = f3.a and f1.b = f3.b and f1.c = f3.c and f1.d = f3.d and f1.e = f3.e and f1.f = f3.f
inner join f4 on f1.a = f4.a and f1.b = f4.b and f1.c = f4.c and f1.d = f4.d and f1.e = f4.e and f1.f = f4.f' from generate_series(1,100) s(i);

\o explain-4.log

\gexec

\o /dev/null

select 'explain analyze
select * from f1
inner join f2 on f1.a = f2.a and f1.b = f2.b and f1.c = f2.c and f1.d = f2.d and f1.e = f2.e and f1.f = f2.f
inner join f3 on f1.a = f3.a and f1.b = f3.b and f1.c = f3.c and f1.d = f3.d and f1.e = f3.e and f1.f = f3.f
inner join f4 on f1.a = f4.a and f1.b = f4.b and f1.c = f4.c and f1.d = f4.d and f1.e = f4.e and f1.f = f4.f
inner join f5 on f1.a = f5.a and f1.b = f5.b and f1.c = f5.c and f1.d = f5.d and f1.e = f5.e and f1.f = f5.f' from generate_series(1,100) s(i);

\o explain-5.log

\gexec

\o /dev/null

SET enable_fkey_estimates = off;

select 'explain analyze
select * from f1
inner join f2 on f1.a = f2.a and f1.b = f2.b and f1.c = f2.c and f1.d = f2.d and f1.e = f2.e and f1.f = f2.f' from generate_series(1,100) s(i);

\o explain-2-off.log

\gexec

\o /dev/null

select 'explain analyze
select * from f1
inner join f2 on f1.a = f2.a and f1.b = f2.b and f1.c = f2.c and f1.d = f2.d and f1.e = f2.e and f1.f = f2.f
inner join f3 on f1.a = f3.a and f1.b = f3.b and f1.c = f3.c and f1.d = f3.d and f1.e = f3.e and f1.f = f3.f' from generate_series(1,100) s(i);

\o explain-3-off.log

\gexec

\o /dev/null

select 'explain analyze
select * from f1
inner join f2 on f1.a = f2.a and f1.b = f2.b and f1.c = f2.c and f1.d = f2.d and f1.e = f2.e and f1.f = f2.f
inner join f3 on f1.a = f3.a and f1.b = f3.b and f1.c = f3.c and f1.d = f3.d and f1.e = f3.e and f1.f = f3.f
inner join f4 on f1.a = f4.a and f1.b = f4.b and f1.c = f4.c and f1.d = f4.d and f1.e = f4.e and f1.f = f4.f' from generate_series(1,100) s(i);

\o explain-4-off.log

\gexec

\o /dev/null

select 'explain analyze
select * from f1
inner join f2 on f1.a = f2.a and f1.b = f2.b and f1.c = f2.c and f1.d = f2.d and f1.e = f2.e and f1.f = f2.f
inner join f3 on f1.a = f3.a and f1.b = f3.b and f1.c = f3.c and f1.d = f3.d and f1.e = f3.e and f1.f = f3.f
inner join f4 on f1.a = f4.a and f1.b = f4.b and f1.c = f4.c and f1.d = f4.d and f1.e = f4.e and f1.f = f4.f
inner join f5 on f1.a = f5.a and f1.b = f5.b and f1.c = f5.c and f1.d = f5.d and f1.e = f5.e and f1.f = f5.f' from generate_series(1,100) s(i);

\o explain-5-off.log

\gexec
