with seed as (
select c1
from t100
where bucketid in (0,1,2)
)
select seed.c1, t.c2, t.c3
from seed,
lateral (
select a.c2, b.c3
from t10000 a
full join t10000 b
on a.c1 = b.c1
where a.c1 = seed.c1
and coalesce(a.c2,0) > 10
and greatest(a.c3, b.c3, 0) < 100
and least(a.c4, b.c4, 1000) > 0
and abs(a.c2 - b.c2) % 7 in (1,3,5)
) t
order by t.c2, t.c3