OLAP (Online Analytical Processing) 00:00:01 A two-year report meets a live checkout A merchant wants revenue by region and product category. A cashier needs one order to commit promptly. Both care about the same sales, but the work each request asks the storage system to do is radically different. Four operational databases hold today's business: orders, payments, customers and inventory. Each is built for small, fast transactions. A scheduled job copies changes since its last run. Reading from a replica or a change stream can reduce interference with checkouts, although collection and replication still use resources. Types are fixed, duplicates removed, and the four ways of writing a country become one. Rows land in sales_fact, with dim_time, dim_product, dim_customer and dim_store around it. Common totals are computed once, for example revenue per day, product and region. This plays the part of the classic cube. A dashboard asks for revenue by region and category. The warehouse scans columns, adds up and returns a few rows. Dashboards, reports, alerts and model training all read from here. A warehouse brings the relevant source records together for analytical queries. Track the load's freshness so the merchant knows which sales could still be missing from today's total. 00:01:29 Read one field from every sale Lay five sales out two ways. A row-oriented arrangement places one sale's fields together. A column-oriented arrangement places all the amounts together. Which pays less just to sum the amounts? Five sales with four columns. The question is the total amount. Rows are stored one after another, so reading the amount also brings the date, region and product off the disk. All 20 cells are read to use 5 of them. Each column is stored on its own. Only amount is read; the other three files are not opened. A dictionary can encode repeated amount values compactly. The effect on total storage depends on the distribution and encoding of the actual column. Fetch everything about sale 4. The row store reads one row. The column store must visit four files and put the row together again. The advantage reverses for some point lookups that need every field. Choose from the expected access pattern instead of assuming that the smaller scan is universally the faster store. 00:02:34 Skip months before reading bytes The analyst needs one date range and one amount column. Metadata about ranges of dates can eliminate whole chunks before the engine opens them. Column selection can then reduce the surviving scan further. Each month is 10 GB. The system remembers the smallest and largest date in each one. The query wants dates from March 1 to March 31. Compare that range with each partition's range. April starts too late. Only March can hold matching rows. Of five columns of about equal size, the query uses one. 10 GB becomes about 2 GB. These savings compound only when the data layout supports the predicate. Interleaving years randomly among every block makes the date summaries much less selective. 00:03:24 Ask a different question of the same facts Start with revenue for all buyers. Adding region, then product category, changes the grouping. The underlying transactions stay put while their measures are summarized at a different grain. One row for everything. The average order is 1,250,000 divided by 15,000 equals 83.33. Add the quarter to the grouping. The four rows add up to the row before. Fix one value of one dimension. The same year grouped by category. The totals agree with the year. Electronics in Q4. The numbers in this small cube are an assumption that adds up to the totals above. Swap rows and columns. Nothing is computed again; only the view turns. An average needs its numerator and denominator. Combining group averages without their counts can change the result, even when each subtotal was right. 00:04:20 Deal with a day that changes after midnight A summary job has finished the first two days. A late correction arrives after the third day's processing. Blindly adding the entire third day again could double-count real purchases. Days 1 and 2 are summarised. Day 3 has just ended. An order of 30 for day 2 arrives after day 2 was summarised. A phone was offline. The job replaces day 2 and day 3. Day 1 is left alone. The same job runs twice by accident. Nothing changes, because days are replaced and not added to. Replace or reconcile the affected units of aggregation atomically. The cashier keeps a transactional record, while the analyst gets a repeatable result whose freshness and correction rules can actually be explained.