drop table a;
create table a (a int, b int,  c int) partition by list (a);

create table a1 partition of a for values in (1) partition by range (b, c);
create table a1_1 partition of a1 for values from (1, 0) to (1, 10);
create table a1_2 partition of a1 for values from (2, 0) to (2, 10);

create table a2 partition of a for values in (2) partition by range (b, c);
create table a2_1 partition of a2 for values from (1, 0) to (1, 10);
create table a2_2 partition of a2 for values from (2, 0) to (2, 10);


insert into a select 1, i%2 + 1, i % 10 from generate_series(1, 10000) i;
insert into a select 2, i%2 + 1, i % 10 from generate_series(1, 10000) i;

analyze a;

set plan_cache_mode  to force_generic_plan; 
prepare s as select * from a where a = $1;
explain execute s(1);


prepare s4 as select * from a where a = $1 and b = $2 and c = $3;
explain execute s4(1, 1, 2);


prepare s2 as select * from a where a = $1 union all select * from a where a = $2;
explain execute s2(1, 1);


prepare s3 as select * from a where a = $1 union select * from a where a = $2;
explain execute s3(1, 1);


-- add limit to make sure the runtime partition prune.
explain select * from generate_series(1, 10) i(i) join lateral (select * from a where a.a = (i.i % 2 + 1) and a.b = (i.i % 2 + 1) and a.c = (i.i % 10) limit 10000000) m on true;

