Data engineering

Stage 2 · Lesson 3 of 9

SQL performance at scale

Analytical SQL and data modelling

In a warehouse, cost and speed depend mainly on how much data a query reads. Most warehouses use : each column is stored separately. So they read only the columns you ask for, and SELECT * on a wide table is expensive.

They can also skip whole chunks of data using partitions and or sort keys. But they only skip when you filter on those columns directly. Filter early.

Add things up before joining when you can. Do not wrap in functions inside a WHERE clause, because that stops the skipping. Before and after a change, read the or the bytes scanned figure your warehouse shows.

On BigQuery or Athena you pay per byte scanned. On warehouses with fixed capacity, you pay in time and capacity.

Common traptesting on a small sample and discovering the real cost only when a scans terabytes every hour.

A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock

Resources for this stage

Start with

Practise

  • Fifty graded problems; the window function and aggregation ones match what pipeline SQL needs

  • An interactive book on one real dataset that ends with window functions and self joins

Keep handy

Also worth your time

Mark this stage as not done?