I've hit this before, sometimes without an upgrade, where the postgres planner does something unreasonable and since I'm not a DB expert, it's hard to debug.
The solution was to confine the planner's ability to do bad things. CTEs (like the article) are one way. Another is to pull work up into the application layer (for instance, keep the IN filter in the query but overfetch and filter the < piece in the app... Not always feasible but has saved me in the past).
The solution was to confine the planner's ability to do bad things. CTEs (like the article) are one way. Another is to pull work up into the application layer (for instance, keep the IN filter in the query but overfetch and filter the < piece in the app... Not always feasible but has saved me in the past).