I'm testing now on a empty DB trying to find out how to improve this.
In this query I have 3 joins like this:
SELECT t1.id, t2.valid_from
FROM t1
JOIN t2 ON (t1.id_t1 = t1.id)
LEFT JOIN t3 ON (t3.id_t1 = t1.id AND t3.valid_from<t2.valid_from)
WHERE t3.id IS NULL
If I delete these 3 joins than the planning time goes down from 5.482 ms to 754.708 ms but I'm not sure why this context is so demanding on the planner.
I'm tryng now to make a materialized view that will allow me to stop using the syntax above.
I reattached the same files, they should be fine like this.