optimizer_first_rows_simple.sql

application/sql

Filename: optimizer_first_rows_simple.sql
Type: application/sql
Part: 0
Message: Re: Disabling options lowers the estimated cost of a query
--create two identical partitioned tables with 100 partitions each
drop table a;
create table a (id bigint, primary key (id)) partition by range (id);
create table a0 partition of a for values from ('0') to ('100000');

drop table b;
create table b (id bigint, primary key (id)) partition by range (id);
create table b0 partition of b for values from ('0') to ('100000');

-- insert data
insert into a (id) (select generate_series(0, 99999));
analyze a;
insert into b (id) (select generate_series(0, 99999));
analyze b;

-- reproduce issue
reset all;
set max_parallel_workers_per_gather = 0;
set enable_partitionwise_join = on;
explain select * from a left join b using (id) order by id desc limit 10000;
explain select * from a left join b using (id) order by id asc limit 10000;
set enable_hashjoin = off;
set enable_mergejoin = off;
explain select * from a left join b using (id) order by id desc limit 10000;
explain select * from a left join b using (id) order by id asc limit 10000;