SQL Query Performance: 5 Fixes That Actually Work
Slow queries are the most common thing that makes a data engineer look bad in a meeting. Someone runs a dashboard, the spinner turns for 20 seconds, and the Slack message hits your DMs before the query finishes. This guide covers the five fixes that resolve 80% of production slowdowns—each with a concrete example you can run against your own warehouse. In this guide Fix 1: Missing (or wrong) indexes Fix 2: SELECT * on wide tables Fix 3: Nested subqueries vs CTEs vs JOINs Fix 4: Implicit type casting in JOINs Fix 5: Unanchored JOINs (cartesian products) FAQ Quick answer: If a query is slow and you can only check one thing, check the JOIN columns for indexes. A single missing index on a foreign-key column will turn an O(log n) lookup into a full table scan across millions of rows. Fix 1: Missing (or wrong) indexes An index is a sorted lookup structure. Without one on a JOIN or WHERE column, the database scans every row in the table. With one, it jumps dire...