create table check_test_div (
id integer,
data float8
);

create table check_test_div_0 (
check(id % 5 = 0)
) inherits(check_test_div);

create table check_test_div_1 (
check(id % 5 = 1)
) inherits(check_test_div);

create table check_test_div_2 (
check(id % 5 = 2)
) inherits(check_test_div);

create table check_test_div_3 (
check(id % 5 = 3)
) inherits(check_test_div);

create table check_test_div_4 (
check(id % 5 = 4)
) inherits(check_test_div);

create table inner_t as
select generate_series(0,1000004)::integer as id, ceil(random()*1000000)::integer as num;

begin;

insert INTO check_test_div_0
select (generate_series(0,200000)*5)::integer as id, random() as data;

insert INTO check_test_div_1
select (generate_series(0,200000)*5+1)::integer as id, random() as data;

insert INTO check_test_div_2
select (generate_series(0,200000)*5+2)::integer as id, random() as data;

insert INTO check_test_div_3
select (generate_series(0,200000)*5+3)::integer as id, random() as data;

insert INTO check_test_div_4
select (generate_series(0,200000)*5+4)::integer as id, random() as data;

commit;

explain
select data, num from check_test_div join inner_t on check_test_div.id = inner_t.id;
