
drop table if exists a cascade;
create table a
(id			integer		not null primary key
,partition	integer
,filler		text
);

create table a_p1 as
select generate_series(1, 10000000)::integer as id, 1::integer as partition, repeat('a',100) as filler;

alter table a_p1 add primary key (id);
alter table a_p1 inherit a; 
alter table a_p1 add check ( partition = 1);

create table a_p2 as
select generate_series(1000000000,1001000000)::integer as id, 2::integer as partition, repeat('a',100) as filler;

alter table a_p2 add primary key (id);
alter table a_p2 inherit a; 
alter table a_p2 add check ( partition = 2);

drop table if exists b cascade;
create table b
(id 		integer		not null primary key
,filler		text
);

drop table if exists c cascade;
create table c
(id			integer		not null primary key
,othercol	integer
);

create index c_idx on c (othercol);

insert into c
select generate_series(1,24667), 0;
insert into c
select generate_series(25000, 27488), 1;

explain select count(*) from a join b on (a.id = b.id)
left join c on (a.id = c.id and c.othercol = 1);

explain select count(*) from a join b on (a.id = b.id)
left join c on (b.id = c.id and c.othercol = 1);

set enable_seqscan = off;

explain select count(*) from a join b on (a.id = b.id)
left join c on (a.id = c.id and c.othercol = 1);

explain select count(*) from a join b on (a.id = b.id)
left join c on (b.id = c.id and c.othercol = 1);


