Filter or aggregate early when possible.
Section: Join performance
Reduce row counts before large joins
sql
sql
WITH recent_orders AS (
SELECT order_id, customer_id
FROM orders
WHERE created_at >= CURRENT_DATE - INTERVAL '30 days'
)
SELECT c.customer_id, ro.order_id
FROM customers c
JOIN recent_orders ro ON ro.customer_id = c.customer_id;Explanation
Smaller intermediate sets usually mean faster join processing.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Join performance
Use EXPLAIN to inspect join strategy
Check whether the planner uses indexes, hash joins, merge joins, or nested loops.