DT5: Warehouse foundations

Lesson 4 of 5 · reading 15–25 minutes; practice and project time is on the module page

Queries that read less

🎯You'll be able to

Read a query plan, and rewrite queries to scan fewer rows and columns, filter early and avoid repeated work.

🏠The everyday picture

To find one bill from March, you open the March file, not every file since the shop opened.

📘What it really is

📝A worked example

Input: compare select order_date, sum(net_amount_paise) from marts.fct_order_lines group by 1 with select order_date, sum(net_revenue_paise) from marts.mart_daily_sales group by 1.

Expected output: both give the same 30 daily totals (₹19,65,764 for the month). The first reads 10,181 rows; the second reads 90. At SabziSathi's size both are instant, but the ratio is what matters as data grows.

🌍Where it's used

📝Case scenario

A logistics company's daily report joined 3 billion tracking events to shipments, then filtered to the last day. Moving the date filter before the join cut the job from 40 minutes to 2, because the join then handled one day's events instead of five years'.

🖱️Try it

Run both worked-example queries with explain analyze and note the rows read by each scan. Success: you can point to 10,181 and 90 in the plans.

⚠️Common mistakes

🛠️For your project

Project 3's dashboard reads mart_daily_sales, not the fact table, for its headline numbers.

✅Quick check

Does LIMIT 10 make a query cheap on a columnar warehouse?

Show the answer

Often not: the engine may still scan everything first.

Why filter before a join?

Show the answer

The join then works on fewer rows.

← PreviousCloud warehouses
ProLearners Assist