create table a (
       id integer,
       named text);
create index named_a_idx on a (named);

create table b (
       id integer,
       named text);
create index named_b_idx on b (named);

insert into a (id, named) values (generate_series(1,100000,2), md5(random()::text));
insert into b (id, named) values (generate_series(2,100000,2), md5(random()::text));

create view testing as select * from a union select * from b;

explain analyze select * from a order by named;

explain analyze select * from b order by named;

explain analyze select * from testing order by named;

explain analyze (select id, named from a) union (select id, named from b) order by named;

explain analyze (select id, named from a order by named) union (select id, named from b order by named);

drop view testing;

drop table a;

drop table b;