drop table a;
drop table b;
drop table c;
drop table d;

create table a(id int, b int);
create table b(id int);
create table c(id int);
create table d(id int);

insert into a select id, id from generate_series(1, 100000) as id;
insert into b select generate_series(1, 100000);
insert into c select generate_series(1, 100000);
insert into d select generate_series(1, 100000);

create index a_idx1 on a(id);
create index b_idx1 on b(id);
create index c_idx1 on c(id);
create index d_idx1 on d(id);


-- this is the slow query when analyze has been run. before analyze it returns the results fast
-- explain analyze select * from a left join (b inner join c on b.id = c.id) on a.b = b.id where a.id = 4;

-- this runs fast always
-- explain analyze select * from a left join (b left join c on b.id = c.id) on a.b = b.id where a.id = 4;

