Join Performance, EXPLAIN, and Optimization/Reduce row counts before large joins

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
Index join keys
Join columns are prime indexing candidates.
OpenIn sheetsqlsame section
Use EXPLAIN to inspect join strategy
Check whether the planner uses indexes, hash joins, merge joins, or nested loops.
OpenIn sheetsqlsame section
Avoid SELECT * in wide join queries
Return only the columns you need.
OpenIn sheetsqlsame section
Slow join checklist
Use this when a join query is unexpectedly slow.