create table a (id bigint generated always as identity, col boolean, primary key (id));
insert into a (col) (select i % 1000 = 2 from generate_series(1, 1000000) i);
create index on a (col);
create table b (id bigint generated always as identity, a_fk bigint, order_crit float8, primary key (id), foreign key (a_fk) references a(id));
insert into b (a_fk, order_crit) (select i + 6 * (i % 1024 = 1)::int, random() from generate_series(1, 1000000, 2) i);
create index on b (a_fk, order_crit);
analyze a;
analyze b;

explain analyze select * from a, (select distinct on (a_fk) a_fk, id from b order by a_fk, order_crit) b where a.id = b.a_fk and col = true;
explain analyze select * from a, (select distinct on (a_fk) a_fk, id from b order by a_fk, order_crit) b where a.id = b.a_fk and col = false;
explain analyze select * from a, lateral (select distinct on (a_fk) a_fk, id from b where a.id = b.a_fk order by a_fk, order_crit) b where col = true;
explain analyze select * from a, lateral (select distinct on (a_fk) a_fk, id from b where a.id = b.a_fk order by a_fk, order_crit) b where col = false;
