Kent Tong <kent.tong.mo@xxxxxxxxx> writes: > I have a complex query involving over 15 joins and a CTE query and it takes > over 17s to complete. If you want constructive comments about that, you're going to need to show us the whole thing (and the underlying tables' schemas). Little bits in isolation are not very intelligible. https://wiki.postgresql.org/wiki/Slow_Query_Questions One thought is that you might need to raise from_collapse_limit and/or join_collapse_limit to at least 15 to get the planner to do a complete search of the join-order space. regards, tom lane