create table priority as select floor(random()*1000000)::int as id, floor(random()*10)::int as priority, random() as z from generate_series(1,1000000)f(id) order by random();
vacuum ANALYZE priority;
create index on priority (id, priority,z);
create extension postgres_fdw ;
create server fdw foreign data wrapper postgres_fdw;
create user MAPPING FOR CURRENT_USER SERVER fdw ;
create schema fgn;
import foreign schema public from server fdw into fgn;
explain select distinct on (id) id, z from fgn.priority order by id, priority desc,z;
alter foreign table fgn.priority options (use_remote_estimate 'true');
explain select distinct on (id) id, z from fgn.priority order by id, priority desc,z;
