drop table if exists x;
drop table if exists x2;

create table x(a int, b int);
create table x2(a int, b int);

insert into x2 select (random()*100)::int, (random()*100)::int from generate_series(1,1000);
insert into x select (random()*88)::int, (random()*88)::int from generate_series(1,1000);

analyze;

CREATE OR REPLACE FUNCTION public.foo(a integer)
 RETURNS SETOF integer
 LANGUAGE sql
 IMMUTABLE
AS $function$ select a from x where a = $1; $function$;

explain with pl as (select distinct a from x)
select x2.a from x2 join pl on x2.a = pl.a where x2.a not in (select foo(a) from pl);

explain analyze verbose with pl as (select distinct a from x)
select x2.a from x2 join pl on x2.a = pl.a where x2.a not in (select foo(a) from pl);
