begin;
drop table check_test_div cascade;
drop table inner_t cascade;
commit;

begin;

create table check_test_div (
id integer,
data_x float8,
data_y float8
);

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

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

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

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

insert INTO check_test_div_0
select (ceil(random()*1000)*3)::integer as id, random(), random() as data
from generate_series(0,5000);

insert INTO check_test_div_1
select (ceil(random()*1000)*3+1)::integer as id, random(), random() as data
from generate_series(0,5000);

insert INTO check_test_div_2
select (ceil(random()*1000)*3+2)::integer as id, random(), random() as data
from generate_series(0,5000);

commit;

-- Hash Join
set enable_hashjoin to on;
set enable_mergejoin to off;
set enable_nestloop to off;

explain analyze
select data_x, data_y, num from check_test_div join inner_t on check_test_div.id = inner_t.id;

-- Merge Join
set enable_hashjoin to off;
set enable_mergejoin to on;
set enable_nestloop to on; -- Not incorrect.

explain analyze
select data_x, data_y, num from check_test_div join inner_t on check_test_div.id = inner_t.id;

-- Nested Loop
set enable_hashjoin to off;
set enable_mergejoin to off;
set enable_nestloop to on;

explain analyze
select data_x, data_y, num from check_test_div join inner_t on check_test_div.id = inner_t.id;

