create table p (
	id bigint primary key
) with (autovacuum_enabled=off);

create table p1 (
	p_id bigint primary key references p(id)
) with (autovacuum_enabled=off);

create table p2 (
	p_id bigint primary key references p(id)
) with (autovacuum_enabled=off);

create table p3 (
	p_id bigint primary key references p(id)
) with (autovacuum_enabled=off);

create table p4 (
	p_id bigint primary key references p(id)
) with (autovacuum_enabled=off);

create table p5 (
	p_id bigint primary key references p(id)
) with (autovacuum_enabled=off);


insert into p  select x from generate_series(1, 10000000) x;
insert into p1 select x from generate_series(1, 10000000) x where x % 5 = 1;
insert into p2 select x from generate_series(1, 10000000) x where x % 5 = 2;
insert into p3 select x from generate_series(1, 10000000) x where x % 5 = 3;
insert into p4 select x from generate_series(1, 10000000) x where x % 5 = 4;
insert into p5 select x from generate_series(1, 10000000) x where x % 5 = 0;

analyze p, p1, p2, p3, p4, p5;

begin;
insert into p select x from generate_series(10000001, 20000000) x;
rollback;

-- uncomment one join/projection at a time to see
-- planning buffers increase
explain (analyze, buffers)
select
	p.*
--	, p1.*
--	, p2.*
--	, p3.*
--	, p4.*
--	, p5.*
from p
--left join p1 on (p.id = p1.p_id)
--left join p2 on (p.id = p2.p_id)
--left join p3 on (p.id = p3.p_id)
--left join p4 on (p.id = p4.p_id)
--left join p5 on (p.id = p5.p_id)
where p.id IN (1,100,10000,1000000,10000000, 20000000);
