3 ms·
I've found that the planner generally does a good job with single-table restrictions. With joins, not so much. Sometimes simply turning a join of multiple table
by Ozzie_osman 5y ago
I've found that the planner generally does a good job with single-table restrictions. With joins, not so much. Sometimes simply turning a join of multiple tables into a CTE has forced the planner to be more efficient. Sometimes, counterintuitive, doing the join in the application is faster.
And yes, before resorting to any of those, I've spent time doing EXPLAINs and making sure I have the right indexes.
- olau 5y agoSimple constricting joins are usually okay, but if you have joins with "or" conditions on largish tables, that can easily throw it off completely. I find that I often need to rewrite those to use union.