Data warehouses and Snowflake
After this lesson you will tell OLTP from OLAP in the slides' words, define a data warehouse with Inmon's four adjectives, design a star schema and name the cube operations on it, and explain what Snowflake changed by separating storage from compute — including the two places where the slides blur scaling and caching.
Your bank's app shows your balance in a blink. Ask it how your spending changed over the last ten years and it has nothing to say: it keeps the current state of your account, not its history. The bank answers that question somewhere else, on a second copy of its data, filled in advance — a copy that, the slides admit, does not necessarily hold "most current information" (p. 491).
That second copy has a name and a 1992 definition, and the deck spends almost forty slides on its theory. Then it turns the page with one line: ".. So old school …" (p. 520). Yet on 16 September 2020 Snowflake, a company that sells exactly this kind of copy as a cloud service, raised 3.36 billion dollars on the New York Stock Exchange, in what was reported as the largest software IPO of all time.
If the theory is old school, what was new enough to be worth that much? Keep the question: the last section answers it.
Two kinds of work: OLTP feeds, OLAP asks
The deck opens with two acronyms (p. 483):
OLTP — On Line Transaction Processing: "Describes processing at operational sites".
OLAP — On Line Analytical Processing: "Describes processing at large, integrated data warehouses".
Picture a chain of electronics stores in Rome and Milan. Each till is an operational site: all day it runs short transactions — scan, pay, update the stock — each touching a few rows found by their key. Head office asks how many keyboards each region sold last quarter: a question that reads every sale of the quarter, but only a few columns of each. "OLTP systems provide source data to data warehouses, whereas OLAP systems help to analyze it" (p. 484); the slide draws the loop that joins them, from transactions to the warehouse, to analytics and decisions, and back to the business strategy.
Why not run both kinds of work on one database? Because they grow along different axes, as the slide "Challenges of Scale Differ" draws (p. 485, Fig. 1).
Two slides list the differences. Read each row as a consequence of the access pattern: a till looks up one product by its primary key, so OLTP keeps an "Index/hash on p.k." and only the "Current snapshot"; head office scans a year of sales, so the warehouse is built for "Lots of scans" and keeps "History". Even the schema follows: many narrow, normalised tables for OLTP (lesson 9), few wide ones for the warehouse — section 4 shows why.
| Standard DB / operational system (OLTP) | Warehouse (OLAP) | p. |
|---|---|---|
| Mostly updates | Mostly reads | 489 |
| Many small transactions | Queries long and complex | 489 |
| Mb - Gb of data | Gb - Tb of data | 489 |
| Current snapshot | History | 489 |
| Index/hash on p.k. | Lots of scans | 489 |
| Raw data | Summarized, reconciled | 489 |
| Thousands of users (e.g., clerical users) | Hundreds of users (e.g., decision-makers, analysts) | 489 |
| Transaction oriented | Subject oriented | 505 |
| Small (MB up to several GB) | Large (hundreds of GB up to several TB) | 505 |
| Current data | Historic data | 505 |
| Normalized table structure (many tables, few columns per table) | De-normalized table structure (few tables, many columns per table) | 505 |
| Continuous updates | Batch updates | 505 |
| Simple to fairly complex queries | Usually very complex queries | 505 |
A yin-yang closes the comparison (p. 506): "OLTP, Operational System, Data Entry" against "OLAP, Data Warehouse, Data Retrieval" — data enters through one half and comes out, analysed, through the other.
OLTP runs many short transactions on the current state; OLAP runs few long scans over history. They grow along different axes, so they live in different systems.
Copy it in advance: what a data warehouse is
The chain's data sits in many places — tills, web shop, loyalty cards, suppliers' spreadsheets — each with its own codes and its own idea of a "product". Page 487 names the problem: "Integrated Data Analytics", "Coherent Insights Extraction", "Heterogeneous and distributed data sources". The deck shows two ways to answer a question across such sources (Fig. 2).
Before: query-driven, lazy, on demand (p. 488)
After: the warehousing approach, integrated in advance (p. 490)
The traditional approach is "Query driven", "Lazy", "On-demand" (p. 488): an integration system splits each question, sends a piece to every source through a wrapper — an adapter that speaks the source's language — and merges the answers, helped by metadata on what each source holds. The warehousing approach turns this around: "Information integrated in advance", "Stored in dwh for direct querying and analysis" (p. 490). An extractor/monitor at each source extracts its data and detects changes, the integration system merges them, and the result is loaded into the data warehouse that clients query. Lesson 4 met the same choice as "virtual ETL" against ETL (p. 175).
"High query performance" — "But not necessarily most current information".
"Doesn't interfere with local processing at sources": "Complex queries at warehouse", "OLTP at information sources".
"Information copied at warehouse": it "Can modify, annotate, summarize, restructure, etc." and "Can store historical information".
"Widely adopted in industry".
"Rapidly changing information"
"Rapidly changing sources"
"Truly vast amounts of data from large numbers of sources"
"Clients with unpredictable needs"
The reasons: the copy is fast because it is local and pre-integrated, and stale because it is only as fresh as its last load; it does not interfere because the long scans run on the copy; it keeps history because it is yours — the till overwrites the stock level, the warehouse keeps every sale. The right column is where copying in advance fails: data or sources that change too fast, too much data, questions nobody can foresee.
Two definitions to learn
Data warehouse, a practitioner's viewpoint — "A data warehouse is simply a single, complete, and consistent store of data obtained from a variety of sources and made available to end users in a way they can understand and use it in a business context." Barry Devlin, IBM consultant (p. 493).
Data warehouse, an analytical viewpoint — "A DW is a subject-oriented, integrated, time-varying, non-volatile collection of data that is used primarily in organizational decision making." W.H. Inmon, Building the Data Warehouse, 1992 (p. 494).
Inmon's four adjectives are the ones to learn, and pp. 495–496 unfold them. Subject-oriented: "Organized by subject, not by application" (p. 495) — one Customer subject assembled from tills, web shop and loyalty cards. Integrated: many sources brought to one format and meaning; p. 495 calls the warehouse "A solution to data integration problem". Time-varying: every record carries its time, so the warehouse holds history, not only the present. Non-volatile: what is loaded is not overwritten. Page 496 prints these two together: under "Non-volatile" it lists "Historical" and "Time attributes are important", then "Updates infrequent" and "Maybe append-only" — data that is never overwritten piles up as history. Its examples are all history: "All transactions ever at a bank", "Complete client histories at insurance firm", "Financial information and portfolios of customers" — the app holds your balance, the warehouse every movement since you opened the account.
"Non-volatile means the warehouse is never written." It is written by loads, in batches; what it does not get is the stream of small updates of an OLTP database. A sale, once loaded, stays as it was.
A data warehouse is a subject-oriented, integrated, time-varying, non-volatile collection of data used for decision making, integrated in advance from many sources.
Inside the warehouse: layers, tiers, ETL and marts
The "Generic Warehouse Architecture" (p. 497) draws the warehousing approach bottom-up: sources, an extractor/monitor each, an integrator, the warehouse with its metadata, query and analysis, clients. Its grey labels — "Design Phase", "Loading", "Maintenance", "Optimization" — name the jobs around it, and p. 500, "Issues in Data Warehousing", lists them as problems: warehouse design; extraction, with "Wrappers, monitors (change detectors)"; integration, "Cleansing & merging" (extraction and integration together make the loading); optimization; maintenance, which keeps the copy in step with changing sources.
Pages 498–499 see the same thing as layers of data:
- Single-layer: "Every data element is stored once only" — a "Virtual warehouse": operational and informational systems read the same "Real-time data".
- Two-layer: "Real-time + derived data", the "Most used approach in industry": operations read the real-time data, analysts a derived copy.
- Three-layer: "Transformation of real-time data to derived data really requires two steps". First the reconciled data, integrated and cleaned — the "Physical Implementation of the Data Warehouse"; then the derived data at the "View level", for "Particular informational needs".
The reconciled layer makes reports agree: every derived view starts from the same cleaned base. Read "really requires" as the argument for it, not as a law — the previous slide calls two layers the industry's usual choice.
Who reads the derived data? Decision support systems, "Information technology to help the knowledge worker (executive, manager, analyst) make faster & better decisions" (p. 501), with sample questions such as "What were the sales volumes by region and product category for the last year?", "How did the share price of comp. manufacturers correlate with quarterly profits over the past 10 years?" and "Which orders should we fill to maximize revenues?". "On-line analytical processing (OLAP) is an element of decision support systems (DSS)". Their architecture has three tiers (Fig. 3).
The arrow into tier 1 reads "extract, transform, load, refresh, etc." (p. 502): ETL — extract the data from the sources, transform it to the warehouse's format and meaning, load it, refresh it periodically. (Loading raw data first and transforming it inside the warehouse is often called ELT — not a slide term, but how Snowflake loads in section 6.) Tier 2 has two kinds of OLAP server (p. 503). ROLAP, a "Relational specialized DBMS to store and manage warehouse data" plus "OLAP middleware to support missing pieces", keeps the cube virtual, in tables queried with SQL. MOLAP, with "Array-based storage structures" and "Direct access to array data structures", stores the cube as an array addressed by the dimension values.
Last, scope (p. 504). An enterprise warehouse "collects all information about subjects that span the entire organization". Data marts are "Departmental subsets that focus on selected subjects", like the "Marketing data mart: customer, product, sales" — "Faster roll out, but complex integration in the long run", since separate marts end up defining "customer" differently. A virtual warehouse is "views over operational DBs", "Easy to build but require excess capability on operat. db servers".
ETL — extract, transform, load, refresh — fills the warehouse; data marts are its departmental subsets; ROLAP keeps the cube in relational tables, MOLAP in arrays.
The star, the snowflake and the cube
An operational schema is a network of entities and relationships; p. 508 draws it as an "ER Diagram" next to the warehouse's "Star Schema", one central box with the others around it. Page 509 draws the star in the course's ER notation (Fig. 4).
The centre is the fact, the event being measured: a sale. The rays are the dimensions, the points of view from which you analyse it. Page 510 adds the table of the fact — Sale, with CodProd, CodStore, CodPromo, CodTime underlined and the bullets Amount, Qty — and five lines:
- "Attributes all over": measures on the fact, descriptions on the dimensions.
- "FACT is an aggregate": a row is not one receipt line but the total for one combination of product, store, promotion and time — the grain chosen at design time.
- "FACT has composed key (from dimensions)":
CodProd,CodStore,CodPromo,CodTime, each a reference to a dimension;AmountandQtyare the measures. - "FACT is normalized (BCNF)": the only dependency goes from the whole key to the measures (lesson 9).
- "DIMENSION is NOT normalized": Store keeps city, region and country together, although CodStore → City → Region is transitive.
Why keep the dimensions un-normalised, after lesson 9? Because users never update them: only the batch load writes them, and it changes a city's region in every row at once, so the update anomalies of lesson 9 do not bite; the repetition costs little, since dimension tables are small; and every question saves joins. This is p. 505's "De-normalized table structure": a narrow, very long fact table among wide, short dimensions.
Normalise them anyway and the star becomes a snowflake schema, "Hierarchies for not normalized dimensions" (p. 512): Store points to City, City to Region, Region to Country; time becomes Day, Month, Year; Product gets its Producer and Category (Fig. 5). Page 511's pictograms explain the name: a star's dimensions all touch the fact, a snowflake's branch.
The price is joins: "sales by country" takes one join in the star (Sale with Store) and four in the snowflake. The gain is explicit hierarchies and a little space — little, because a dimension is tiny next to the fact table. And the snowflake schema shares only its name with Snowflake, the product of section 5.
Operations on the cube
Now see the facts as points in a space whose axes are the dimensions. Page 514 draws the cube of the store chain: Store (Roma-1, Roma-2, Milano-1, Milano-2) by Product (PCs, Mouses, Keyboards, TVs) by Time ("1 trim. 2003" to "4 trim. 2003"), with an arrow labelled Quantity on one small cube. Each of the 4 × 4 × 4 = 64 cells holds the measure of one combination: one row of the fact table. Page 513 defines the operations:
Drill-down — "Add one analysis dimension (disaggregation)".
Roll-up — "Remove one analysis dimension (aggregation)".
Slice and dice — "Datacube (slice and dice)": cut a part out of the cube, "Select and Project" (p. 515).
From sales by region and month, a roll-up removes a dimension — sales by region, each total the sum of that region's months; a drill-down adds one — by region, month and category, finer groups, same grand total. A slice fixes one dimension to one value; a dice keeps ranges of values on several. Pages 516–519 shade them on the cube (Fig. 6).
"Roll-up only removes a dimension." That is p. 513's definition. Textbooks also call climbing a hierarchy (months to years, cities to regions) a roll-up and descending it a drill-down — the snowflake's chains are exactly such paths. In SQL both are the same move: a coarser GROUP BY.
Each operation edits one star query: join the fact to the dimensions you need, filter and group on their attributes, sum the measures. The first question of p. 501, with 2003 as the last year:
-- p. 501: sales volumes by region and category, last year
SELECT st.Region, p.Category, SUM(s.Qty) AS Qty
FROM Sale s
JOIN Store st ON s.CodStore = st.CodStore
JOIN Product p ON s.CodProd = p.CodProd
JOIN Time t ON s.CodTime = t.CodTime
WHERE t.Year = 2003
GROUP BY st.Region, p.Category;
Roll-up and drill-down change only the GROUP BY; slice and dice only the WHERE. Build the star yourself and watch it happen.
A star is one narrow fact table, dimension keys plus measures, among wide dimension tables. Every OLAP question joins the fact to the dimensions it names; roll-up and drill-down edit the GROUP BY, slice and dice the WHERE.
So old school? Snowflake's three layers
After the cube comes ".. So old school …" (p. 520), and the deck switches to a product. Its key features (p. 521): "Enterprise-ready cloud data warehouses that automatically scales for balancing performances and costs"; "Separation between compute and storage" — "Other databases combine the two together, meaning you must size for your largest workload and incur the cost that comes with it"; "Single place for storing all the data", one copy for every workload.
The middle one is the key. In a classic warehouse cluster every machine holds a share of the data and the processors that work on it. To have enough processors for the Monday-morning rush you buy machines that idle the rest of the week, and adding processors means moving data onto them. Separated, storage and compute each grow, shrink or stop on their own. Page 523 draws the two traditional designs, p. 524 Snowflake's (Fig. 7).
Before: the two traditional architectures (p. 523)
After: Snowflake's layers (p. 524); VW = virtual warehouse
Snowflake takes one idea from each. The slides draw it; Snowflake's documentation names it, "a hybrid of traditional shared-disk and shared-nothing database architectures". Its layers, bottom up:
- Database Storage (p. 525): "Data in Snowflake is organized into the internal optimized, compressed, columnar format"; Snowflake manages "Organization, file size, structure, compression, metadata, statistics", and the data is "visible or accessible by customers only through SQL query executed in Snowflake". A column store (lesson 20) behind SQL: no indexes to build, no files to tune.
- Query Processing (p. 526): "Snowflake processes queries using virtual warehouses", each an "MPP compute cluster composed of multiple compute nodes allocated by Snowflake from a cloud provider". "Virtual warehouses are independent compute cluster and does not share compute resources with other virtual warehouses" — "No impact on the performance of other virtual warehouses".
- Cloud Services (p. 527): "Services that coordinate activities across Snowflake for processing user requests, from login to query dispatch": "Authentication", "Infrastructure management", "Metadata management", "Query parsing and optimization", "Access control". The VPC box around the layers on p. 524 is the cloud provider's private network.
"A virtual warehouse is where the data is." The deck uses the phrase in two senses: on pp. 498 and 504 it is views over operational databases; in Snowflake (p. 526) it is a compute cluster that holds no data of its own, at most a cache of what it has read.
With no indexes, how does Snowflake avoid reading the whole table?
Background from Snowflake's documentation and its SIGMOD 2016 paper, not from the slides. Tables are split automatically into micro-partitions of 50 to 500 MB of uncompressed data, stored column by column. For each one the cloud services layer records the range of values of every column, so a filter on a date skips every micro-partition whose range cannot match: pruning, which does for scans what indexes do for lookups. Micro-partitions are never modified, only replaced, which makes two features cheap that the slides do not name: time travel (querying a table as it was) and zero-copy cloning (a copy that is only new metadata over the same files).
Page 522, "Why is data warehousing important?", lists what a managed cloud warehouse adds: "Consistency", "Security and Data Protection" (multi-factor authentication, single sign-on, TLS), "Connectivity" (Python and Spark connectors, Node.js and .NET drivers), "Fault Tolerance". Separation pays most when teams share data: p. 542 gives the data scientists DATASCIENCE_WH and the DBAs DBA_WH, two warehouses over the same transactions table, and p. 545 builds a multi-cluster AS_WH for a changing load. The widget puts a team of analysts on AS_WH: that assignment is this lesson's scenario, not the slides'.
Storage is one shared, columnar copy; compute is any number of independent virtual warehouses that can be resized, multiplied or suspended without touching the data.
Loading and tuning: stages, Snowpipe, warehouses, caches, clustering keys
Clients connect through a web interface, command-line clients, ODBC and JDBC drivers (Tableau), native connectors for Python and Spark, and third-party ETL and BI connectors (p. 528). Snowflake loads CSV, TSV, JSON, Avro, ORC, Parquet and XML, compressed or not (p. 529); the slide also lists Amazon S3, Google Cloud Storage and Microsoft Azure among the "Types of data", but they are places to load from, not formats. Two ways in (p. 530):
"Snowflake provides the COPY command for batch loading". It "uses Virtual Warehouse computing resources" and is "Managed manually". It "Allows basic transformations such as reordering and excluding columns, data typing, truncating strings".
"Snowpipe used for loading streaming data". "Scaling up / down is done automatically". It "Doesn't use the virtual warehouse computing resources".
A bulk load has four steps (p. 532): prepare the files, stage the data ("Make snowflake aware of the data"), execute COPY, schedule regular loads. A stage is "an intermediate, transient place used to process data for extracting, transforming and loading processes" (p. 533), classically an S3 bucket or an Azure blob store, "Long term cheap storage for raw data"; in Snowflake such an external stage is a named pointer to that place, written @name. COPY INTO then loads the files (p. 534, with the names of pp. 536–537):
-- load the stage's CSV files: '|'-separated, one header line
COPY INTO transactions
FROM @snowpipe_copy_example_stage
pattern = '.*.csv'
file_format = (type = csv field_delimiter = '|' skip_header = 1);
pattern is a regular expression on file names; for JSON the format is file_format = (type = json). COPY's transformations are deliberately basic — the rest is SQL inside the warehouse, the ELT order of section 3. To leave files where they are, an external table queries them in place, "Useful when there is a lot of data externally but we want to query only a small subset of data", sped up by materialized views (p. 531). Fig. 8 compares the two ways in.
Bulk: you run COPY on your warehouse (pp. 530–534)
Continuous: the bucket wakes the pipe (pp. 535–540)
Snowpipe is a "Mechanism to enable loading of streaming data" with a "Serverless architecture": "It has its own processing", "No virtual warehouse instances involved" (p. 535). A pipe is a stored COPY that Snowflake runs whenever a new file is announced, set up in four steps: "Stage data", "Validate copy command", "Create Pipe", "Configure cloud event or use REST APIs". The hands-on of pp. 536–540, in run order:
Create the database and make it the current one (p. 536).
CREATE DATABASE ingest_data;USE DATABASE ingest_data;Create an external stage on the S3 bucket, then list the files Snowflake can now see there.
CREATE OR REPLACE STAGE snowpipe_copy_example_stage url='s3://snowpipe-streaming/example_table';LIST @snowpipe_copy_example_stage;Create the target table (p. 537).
CREATE TABLE transactions ( Transaction_Date DATE, Customer_ID NUMBER, Transaction_ID NUMBER, Amount NUMBER );Create the pipe: the COPY of p. 534 wrapped in
CREATE PIPE … AS;auto_ingest = truemakes it listen for cloud events.CREATE OR REPLACE PIPE transaction_pipe auto_ingest = true AS COPY INTO transactions FROM @snowpipe_copy_example_stage file_format = (type = csv field_delimiter = '|' skip_header = 1);Read the address (ARN) of the pipe's queue: in Snowflake's documentation it is the
notification_channelcolumn (p. 540).SHOW PIPES;In the AWS console, "Amazon S3 > bucket_name > properties > events" (p. 538): a notification "Snowflake Notification" for "All object create events", prefix
transactions, sent to the "SQS Queue" with that ARN — "Insert here your snowpipe queue id" (p. 539).Upload a file and count the rows: "Now if a new file is uploaded on S3, the data arrives automatically on Snowflake" (p. 540) — with no COPY typed and no warehouse running.
SELECT COUNT(*) FROM transactions;
Keeping it fast
With no indexes and no files to tune, five levers remain (p. 541): "Use dedicated virtual warehouses for different workloads", "Scale up for know large workloads", "Scale up with virtual warehouses for unknown workloads", "Design the production workflow to maximize cache usage", "Use cluster keys for partitioning large tables". Dedicated warehouses first (p. 542):
-- virtual warehouse for data scientists
CREATE WAREHOUSE DATASCIENCE_WH WITH WAREHOUSE_SIZE = 'SMALL'
WAREHOUSE_TYPE = 'STANDARD' AUTO_SUSPEND = 300 AUTO_RESUME = TRUE;
AUTO_SUSPEND = 300 suspends the warehouse after 300 idle seconds, so it stops costing; AUTO_RESUME = TRUE restarts it at the next query. The DBAs get DBA_WH, XSMALL "because of queries size". Privileges complete the pattern (pp. 542–543): the PUBLIC role may use the database and its schema and read the table (GRANT USAGE, GRANT SELECT); each team's role may use its warehouse (GRANT USAGE ON WAREHOUSE … TO ROLE …); a user such as DS_1 gets that role and warehouse as defaults.
For a workload whose load changes, pp. 544–545 create a multi-cluster warehouse:
-- 1 to 3 XSMALL clusters, started as queries queue
CREATE WAREHOUSE AS_WH
WITH WAREHOUSE_SIZE = 'XSMALL'
MIN_CLUSTER_COUNT = 1
MAX_CLUSTER_COUNT = 3
SCALING_POLICY = 'STANDARD'
AUTO_SUSPEND = 300
AUTO_RESUME = TRUE;
Its requirements are "a minimum and maximum number" and the "Enterprise Edition of Snowflake" (p. 544); SCALING_POLICY = 'STANDARD' starts a cluster as soon as queries queue (Snowflake's documentation). What is automatic here is suspend and resume, and the number of running clusters between the two counts; a warehouse's size changes only when you change it — so p. 521's "automatically scales" holds for clusters, not for sizes. The slide calls all this "scale up" — the first slip to correct.
"In Snowflake caching is automatic", says p. 546: "Results are cached for 24 hours", and "Snowflake knows when data has changed and it re-executes the query if necessary". The advice that follows mixes two caches.
Last lever (p. 547): "For very large tables, automatic partitioning scheme may not be optimal", so you can create "custom cluster keys to partition table according to the needs", "Normally used for columns involved frequently in WHERE, JOIN or ORDER BY statements"; "Only very large tables (multi terabyte size) will benefit from clustering". A clustering key keeps close values in the same micro-partitions, so filters on it prune more. Page 548, with the commas it forgot:
-- the transactions table, kept in Transaction_date order
CREATE TABLE transactions_clustered_date
(
Transaction_date DATE,
Transaction_id Integer,
Customer_id String,
Amount integer
) CLUSTER BY (Transaction_date);
Pages 533–534 and 542–543 print typographic quotes (‘SMALL’): type straight ones. Page 543 writes DBA _WH for DBA_WH and omits the semicolon after MUST_CHANGE_PASSWORD = TRUE; p. 548 omits the commas. Page 533's credentials='login_password' is a placeholder: real stages use a CREDENTIALS = (…) clause or a storage integration. Its "Data can also be staged on local file system" means uploading local files (with PUT) into a stage that Snowflake keeps, an internal stage: Snowflake never reads your own disk.
Back to the puzzle
What did Snowflake sell, if the theory is old school? Not a new model: the star, the cube and ETL work inside it unchanged, and section 4's star query runs there as written. It changed the machinery, and one decision explains nearly every Snowflake slide: storage separated from compute. With the data stored once in cheap cloud storage, each team gets its own warehouse on the same table; a warehouse grows, multiplies or stops without moving a byte; a pipe loads files with no warehouse running; a cached result needs no warehouse at all. The old warehouse was sized "for your largest workload", with "the cost that comes with it" (p. 521). This one is sized minute by minute.
Two neighbours complete the picture. A data lake (lesson 4) keeps raw files and applies the schema when reading, a warehouse before loading — and external tables let Snowflake read lake files in place. Hadoop (lesson 31; Hive's SQL over files, lesson 32) and Spark (lesson 40) are engines over files: Snowflake loads the Parquet and ORC files they write (p. 529) and has a Spark connector (p. 528).
Exam-style questions
Theory questions in the forms the theory part uses — true/false, multiple choice and short open answers, where a wrong tick may cost points — and one design exercise. The nine past papers contain no data-warehouse or Snowflake exercise; this material belongs to the theory part, which covers the content of the theoretical and practical lectures.
True or false: a data warehouse always contains the most current information available in the operational systems.
Show model answer
False. In the warehousing approach information is integrated in advance and copied into the warehouse, which is refreshed by periodic batch loads. Queries are fast and do not interfere with the sources, but the data is not necessarily the most current: it is as fresh as the last load. For rapidly changing information the query-driven approach is still better.
The trap is the word "always". A good justification names the price of copying in advance — staleness — and the case in which the lazy, query-driven approach wins.
According to the lecture, which of the following characterise a data warehouse (OLAP) rather than an operational OLTP database? Select all that apply.
Show model answer
Mostly reads, history, lots of scans and batch updates. Many small transactions, an index or hash on the primary key and a normalized structure with many narrow tables characterise the OLTP database.
A select-all question built from the two comparison slides, pp. 489 and 505. Every option is a row of one of them: learn each row as a pair, and the wrong ticks become easy to avoid.
Give Inmon's definition of a data warehouse and explain each of its four properties with an example. Then explain how the warehousing approach differs from the query-driven approach to integrating heterogeneous sources.
Show model answer
Inmon defines a data warehouse as "a subject-oriented, integrated, time-varying, non-volatile collection of data that is used primarily in organizational decision making". Subject-oriented: data is organised by business subject, such as customer, product or sales, not by the application that produced it. Integrated: data from heterogeneous sources is reconciled into one consistent format and meaning. Time-varying: history is kept and every record is tied to a time — all transactions ever made at a bank, not only the current balance. Non-volatile: data is loaded in batches and then not updated, possibly append-only. In the warehousing approach information is integrated in advance: an extractor/monitor at each source feeds an integrator that loads the warehouse, and clients query the warehouse directly, with high performance and no interference with the sources, but not necessarily the most current data. In the query-driven approach (lazy, on demand) an integration system decomposes each query and sends it through wrappers to the live sources; it remains better for rapidly changing information or sources, truly vast amounts of data and clients with unpredictable needs.
A complete answer has three parts: the four adjectives with a concrete example each, the eager-versus-lazy contrast, and at least one case where each approach wins. Inmon's book writes "time-variant"; the slide prints "time-varying": use the slide's word and recognise the other.
A chain of pharmacies records its sales in an operational database whose ER diagram has these entities (primary key first): Sale Line (Line_ID, Date, Quantity, Amount), Medicine (Medicine_ID, Name, Category, Producer), Pharmacy (Pharmacy_ID, Name, City, Region) and Campaign (Campaign_ID, Description). Each sale line refers to exactly one medicine (1,1), exactly one pharmacy (1,1) and at most one campaign (0,1); a medicine, a pharmacy or a campaign can appear in any number of sale lines (0,N). Management wants to analyse quantities and amounts by medicine category, region and month.
(a) Design a star schema with one fact row per medicine, pharmacy, campaign and day: give the fact table with its key and its measures, and the dimension tables with their attributes, with the (min,max) cardinalities. (b) Say which tables are normalised and why. (c) Show how the Pharmacy dimension changes in a snowflake schema. (d) Write the SQL query that returns the total amount by region and month.
Show model answer
(a) Fact Sale(Medicine_ID, Pharmacy_ID, Campaign_ID, Time_ID, Quantity, Amount): the key is composed of the four dimension keys, the measures are Quantity and Amount, and each row aggregates all the sale lines of that combination in that day. Dimensions: Medicine(Medicine_ID, Name, Category, Producer), Pharmacy(Pharmacy_ID, Name, City, Region), Campaign(Campaign_ID, Description), with a "no campaign" row for sales without one so that the key stays complete, and Time(Time_ID, Day, Month, Year). Every relationship is (1,1) on the Sale side and (0,N) on the dimension side.
(b) The fact table is in BCNF: its only functional dependency goes from the whole key to the measures. The dimensions are not normalised: Pharmacy_ID → City → Region and Day → Month → Year are transitive dependencies, kept on purpose because the warehouse is loaded in batches and not updated in place, and every attribute stays one join away from the fact.
(c) In a snowflake schema the hierarchy becomes separate entities: Pharmacy (1,1)—(0,N) City (1,1)—(0,N) Region, that is Pharmacy(Pharmacy_ID, Name, City_ID), City(City_ID, Name, Region_ID), Region(Region_ID, Name).
(d)
SELECT ph.Region, t.Year, t.Month, SUM(s.Amount) AS Amount
FROM Sale s
JOIN Pharmacy ph ON s.Pharmacy_ID = ph.Pharmacy_ID
JOIN Time t ON s.Time_ID = t.Time_ID
GROUP BY ph.Region, t.Year, t.Month;
The design reasoning of pp. 509–512 applied to a new scenario. A complete answer has the composed key, the measures in the fact and the descriptions in the dimensions, the normalisation argument of p. 510, and a query that joins only the dimensions it needs — grouped by year and month, or April of two different years would fall into one group. The "no campaign" row is the detail that keeps the key complete: the slide's star puts Promo (1,1) on every sale, which needs exactly such a row for sales without a promotion.
Consider the cube Store × Product × Time with measure Quantity. Define drill-down, roll-up, slice and dice, give an example of each, and say which clause of the SQL star query each operation changes.
Show model answer
Drill-down adds one analysis dimension (disaggregation): from sales by product and quarter to sales by product, quarter and store. Roll-up removes one analysis dimension (aggregation): from sales by product, quarter and store back to sales by product and quarter, each cell being the sum over the stores; climbing a hierarchy, such as from month to year or from city to region, is also a roll-up. A slice fixes one dimension to one value and leaves a sub-cube with one dimension less, for example the sales of one product over all stores and periods. A dice selects ranges of values on several dimensions and leaves a smaller cube, for example a category of products in a region over a mid-term time span: two products, two stores and two quarters, 8 cells. In the star query, roll-up and drill-down change the GROUP BY (fewer or more grouping attributes, or a coarser or finer level of a hierarchy); slice and dice add conditions on dimension attributes to the WHERE.
Give the slide's definitions (p. 513) first, word for word, then the hierarchy form as a complement. The link to SQL shows that you understand the operations rather than remember the pictures.
Which statement describes the architecture of Snowflake?
Show model answer
The third. Snowflake is a hybrid of the two traditional architectures: like shared-disk it keeps the data in one central repository that every compute node can access, stored in an optimized, compressed, columnar format; like shared-nothing it processes queries on MPP clusters, the virtual warehouses, which share no compute resources with each other. A cloud services layer handles authentication, infrastructure, metadata, query parsing and optimization, and access control.
The slides draw the two traditional architectures (p. 523) and Snowflake's layers (p. 524) without the word "hybrid"; Snowflake's documentation uses it. The question checks that you can place Snowflake against both, not just name its layers.
Explain the separation between compute and storage in Snowflake and why the lecture presents it as a key feature. Then explain how resizing a virtual warehouse differs from a multi-cluster warehouse, and write the statement that creates a warehouse of size XSMALL that runs between 1 and 3 clusters and suspends after 5 minutes of inactivity.
Show model answer
In Snowflake the data is stored once, in a central cloud storage layer, in a compressed columnar format managed by Snowflake, while queries are processed by virtual warehouses: independent MPP compute clusters that read that storage and share no compute resources with each other. Other databases combine compute and storage, so they must be sized for the largest workload and that cost is paid all the time. With the two separated, each workload gets its own warehouse on the same data without interference, and a warehouse can be suspended when idle (AUTO_SUSPEND) and resumed automatically (AUTO_RESUME), so compute is paid only while it is used. Resizing a warehouse — scaling up, for example from XSMALL to LARGE — gives each query more compute and makes large, complex queries faster. A multi-cluster warehouse — scaling out — keeps the size but runs between MIN_CLUSTER_COUNT and MAX_CLUSTER_COUNT identical clusters, started automatically when queries queue: it serves more concurrent users but does not make a single query faster, and it requires the Enterprise Edition.
CREATE WAREHOUSE AS_WH
WITH WAREHOUSE_SIZE = 'XSMALL'
MIN_CLUSTER_COUNT = 1
MAX_CLUSTER_COUNT = 3
SCALING_POLICY = 'STANDARD'
AUTO_SUSPEND = 300
AUTO_RESUME = TRUE;
Two traps: the slides title multi-cluster warehouses "Scale Up" (p. 544), so name both moves and say what each one does; and AUTO_SUSPEND is in seconds, so five minutes is 300.
Check yourself
A bank wants a report of how its customers' spending changed over ten years. Why does it run the report on a data warehouse and not on the database behind its banking app?
A row of the fact table Sale holds Qty = 50 for Keyboards, Milano-1, no promotion, 15 April 2003. What does the row represent?
Starting from "sales by region and month", which of these are roll-ups? Select all that apply.
Roll-up makes the groups coarser; drill-down makes them finer; slice and dice keep the groups and drop rows.
You snowflake the Store dimension of the star into Store, City, Region, Country. What happens to the query "sales by country"?
At 9:00, 40 analysts open dashboards and their queries queue on a one-cluster XSMALL warehouse; at the same time one data scientist's full scan is too slow on its own warehouse. Which change fits each problem?
A dashboard sends exactly the same query as an hour ago; no data has changed since, and its warehouse has been suspended for fifty minutes. What happens?
New CSV files land in an S3 bucket every few minutes, day and night. Why does Snowpipe fit better than a scheduled COPY?
Key take-aways
- OLTP is "processing at operational sites" — many small transactions on the current snapshot, found by key; OLAP is "processing at large, integrated data warehouses" — long queries, lots of scans, history. They scale on different axes (p. 485), so they live in different systems.
- The warehousing approach integrates information in advance (extractor/monitor, integrator, warehouse) instead of on demand (wrappers, integration system): fast and non-interfering, but not necessarily current. Inmon: a "subject-oriented, integrated, time-varying, non-volatile collection of data" for decision making.
- Architecture: single, two or three layers (real-time, reconciled, derived data); ETL — extract, transform, load, refresh — into tier 1; MOLAP or ROLAP servers in tier 2; data marts as departmental subsets, a virtual warehouse as views over operational DBs.
- The star schema has a fact (composed key from the dimensions, measures, BCNF) and un-normalised dimensions; the snowflake schema normalises them into hierarchies at the price of more joins. Drill-down adds and roll-up removes an analysis dimension (the GROUP BY); slice fixes one dimension and dice keeps ranges on several (the WHERE).
- Snowflake separates compute and storage: one columnar storage, independent virtual warehouses, a cloud services layer — a hybrid of shared-disk and shared-nothing. It loads with COPY on your warehouse or with Snowpipe on serverless compute, from stages that point at cloud storage.
- Its performance levers are dedicated warehouses, resizing (scale up) for heavy queries, multi-cluster warehouses (scale out, which the slides also call "scale up") for concurrency, caches — the 24-hour result cache in cloud services, the data cache in each running warehouse — and clustering keys for multi-terabyte tables.
What to watch and read
-
Fact Tables and Dimension Tables
Ralph Kimball, 2003
The inventor of dimensional modelling on facts as numeric measurements at one grain and dimensions as flat, textual context — p. 510's "FACT is normalized, DIMENSION is NOT normalized" with its reasons.
-
Understand star schema and the importance for Power BI
Microsoft Learn
Every idea of section 4 with a diagram: fact and dimension tables, granularity, snowflaking a dimension and why many designers avoid it. Ignore the Power BI framing.
-
Snowflake key concepts and architecture
Snowflake documentation
The page the slides of pp. 524–527 come from: the three layers and the "hybrid of shared-disk and shared-nothing" sentence the slides only draw.
-
Micro-partitions & Data Clustering
Snowflake documentation
What sits behind "automatic partitioning scheme" and clustering keys (p. 547): micro-partitions, their metadata, pruning and clustering depth.
-
The Snowflake Elastic Data Warehouse
Dageville et al., SIGMOD 2016
The founders' own account of separating storage and compute, virtual warehouses, pruning without indexes, time travel. Open it through the university library.