Warehouse performance tuning

Clustering/sort keys, partition pruning, materialized views, avoiding SELECT * on wide tables, result caching. Read the query profile before adding compute.

About 25 min read3-question knowledge check

The mental model

Tuning a warehouse query is detective work, not weightlifting. The instinct when a query is slow is to add muscle — a bigger warehouse, more slots, more nodes. That is almost always the wrong first move, because it pays more money to run the *same inefficient plan* faster. The right first move is to read the evidence — the query profile — and find where the time actually went. Nine times in ten it went to scanning data you did not need or shuffling data you could have filtered first, and both are fixed by doing less work, not buying more compute.

The analogy that sticks: a query profile is a race telemetry readout. A slow lap is not fixed by a bigger engine; you read the telemetry to see *where* the time was lost — braking too early (scanning too much), taking the long line through a corner (shuffling across the network), running out of fuel (spilling to disk). Each has a specific fix, and none is "add horsepower." The single most valuable habit an interviewer is listening for is "I read the profile first." An engineer who reaches for a bigger warehouse before reading the profile is the SQL-writer red flag from the job description.

The WHY: **the dominant cost of an analytical query is bytes scanned and bytes shuffled, not CPU cycles.** So tuning is a hierarchy — first reduce what you scan (partition pruning, clustering, projecting only needed columns, result cache), then reduce what you move (filter before joins, align data layout), and *only then*, if the profile proves the query is genuinely compute-bound and parallelisable, add compute. Follow that order and most queries get dramatically faster and cheaper from a DDL change or a rewritten WHERE clause, with the warehouse size untouched.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision