Dimension Hierarchies
Context: FIT3003_MOC Β· Chapter 4 Β· the optional family of snowflaking β one dimension split into a many-1 chain Parent Framework: Snowflake Schema
Quick Revision
- π― Objective: given two dimensions in a many-1 relationship, choose between four schema shapes β separate, combined, hierarchy, linked β and defend the choice.
- π¦ Core Components: Separate β both keys in the fact | Combined β one flat dimension | Hierarchy β chained dimensions | Linked β chained and both keys in the fact.
- β‘ Key Constraint: a many-1 relationship is necessary but not sufficient for a hierarchy β is many-1 and still a bad hierarchy, because the two are not the same kind of thing.
π How It Works
1. What a hierarchy is
- Core Mechanism: Many-1 chain of dimensions β ; each childβs ID sits in the parent as an FK, and only the top table touches the fact.
- Rules That Always Hold: Fact keeps the most granular key β the factβs composite PK holds , never or ; the coarser levels are reached by joining up the chain.
- Normal form: Hierarchy 3NF, flat 2NF β a flat carrying has transitive dependencies β Third Normal Form (3NF); splitting removes them, and that is the only thing splitting achieves.
2. Non-hierarchy vs hierarchy β the Student Enrolment case
- The fact: β enrolment numbers seen by course, campus and semester/year.
- Option 1 β non-hierarchy: one table β .
- Option 2 β hierarchy: three tables β , , .
- The scoreboard: query count is a tie, join count is not β both options answer a country-level question in two queries; the non-hierarchy version needs one join (fact one dimension), the hierarchy version needs three tables joined.
- The claim that fails: roll-up/drill-down is not improved β the hierarchy model is not about drill-down exploration, and rolling up (detail β general) works from the flat dimension just as well.
3. Wrong hierarchy β direction is not free
- The error: chaining downward from the coarse level β with in the fact.
- Why it breaks: the factβs grain collapses β keyed on , two Australian campuses enrolling in the same course in the same semester produce two rows with an identical composite key, and neither the PK nor the query can separate them.
- Rule: the fact always keys the most granular member of the chain; coarser levels are derived by joining up, never by re-keying the fact.
4. Design considerations
- Many-1 is not enough: subject similarity is the real test β and share a spatial context, so they may chain; is a different kind of thing, so is improper even though every link is many-1.
- Access is always through the fact: fact measures are the focus of retrieval β a dimension reachable only via another dimension is one hop further from every query.
- The standing default: link every dimension directly to the fact whenever possible; relationships among dimensions add no efficient access.
ποΈ Schema
erDiagram COURSEDIM ||--o{ STUDENTENROLLMENTFACT : qualifies SEMYEARDIM ||--o{ STUDENTENROLLMENTFACT : qualifies CAMPUSDIM ||--o{ STUDENTENROLLMENTFACT : qualifies CITYDIM ||--o{ CAMPUSDIM : "many-1" COUNTRYDIM ||--o{ CITYDIM : "many-1" STUDENTENROLLMENTFACT { VARCHAR2 CampusID FK VARCHAR2 CourseCode FK VARCHAR2 SemesterID FK NUMBER No_of_Students } CAMPUSDIM { VARCHAR2 CampusID PK VARCHAR2 CampusName VARCHAR2 Address VARCHAR2 Suburb VARCHAR2 Postcode VARCHAR2 CityID FK } CITYDIM { VARCHAR2 CityID PK VARCHAR2 CityName VARCHAR2 State VARCHAR2 CountryID FK } COUNTRYDIM { VARCHAR2 CountryID PK VARCHAR2 Country } COURSEDIM { VARCHAR2 CourseCode PK VARCHAR2 CourseName NUMBER Duration } SEMYEARDIM { VARCHAR2 SemesterID PK VARCHAR2 Semester NUMBER Year }
βοΈ Core Decision Matrix
(two dimensions in a many-1 relationship β and β arranged four ways)
| Model | Factβs dimension keys | Campus dimension holds | Pro | Con / verdict |
|---|---|---|---|---|
| Separate dimensions | and | no country column | each dimension one hop from the fact | already determines the country βΉ the second key is redundant in every fact row |
| Combined dimension | only | fewest tables, one join, one query path | dimension sits in 2NF β harmless in a warehouse | |
| Hierarchy dimensions | only | dimensions in 3NF | extra join for a country-level question; already covers the child dimension | |
| Linked dimensions | and | none | redundancy β the same link is stored twice, in the fact and between the dimensions |
When It Flips: choose combined when campus and country are "often seen as one entity or one piece of information" β the Chapter 4 verdict for this case study. Choose hierarchy only when the child is a subject the analyst interrogates independently. Never choose linked.
π Exam Execution Trace & Applied Exercises
Manual Execution Trace β what the fact table looks like under each key choice
| Step | Fact keyed on | Row | Composite PK status | |
|---|---|---|---|---|
| 1 | (correct) | unique | ||
| 2 | (correct) | unique | ||
| 3 | (correct) | unique | ||
| 4 | (wrong hierarchy) | β | ||
| 5 | (wrong hierarchy) | duplicate β PK violated | ||
| 6 | (wrong hierarchy) | unique by accident |
Final Extracted Output: rows 4β5 are indistinguishable, so the Clayton and Caulfield figures can never be recovered β keying the fact at the coarse end of a hierarchy destroys grain irreversibly β Data Warehouse.
β οΈ Common Mistakes
- π‘ Justifying a hierarchy with βit is in 3NFβ β the warehouse is loaded in bulk and read; the anomalies 3NF prevents cannot occur, so the extra joins buy nothing.
- π‘ Putting the coarse key in the fact β collapses the grain and duplicates the composite PK; the fact keys the leaf of the chain.
- π‘ Chaining two unrelated subjects because the cardinality happens to be many-1 β passes the cardinality test and fails the subject test.
- π‘ Drawing a linked dimension β storing the relationship in the fact and between the dimensions is pure redundancy, never an optimisation.
π§ Active Recall
The lecture rejects the hierarchy model for the Campus/Country case. Give the three reasons in the order a marker expects them.
Answer
- Short answer: query efficiency, key coverage, and subject unity.
- Why: Efficient query processing β the combined model reaches a country-level answer with fact one dimension; the hierarchy adds a join for no analytical gain. Key coverage β already functionally determines the child dimensionβs key, so stores nothing the parent did not imply. One entity β campus and country are regarded as a single piece of spatial information in this case study, and a dimension should model one subject the analyst names.
Why does "all dimensions should be linked directly to the fact whenever possible" follow from how a warehouse is queried, rather than being an aesthetic rule?
Answer
- Short answer: every retrieval starts at a fact measure, so distance from the fact is distance in every query.
- Why: Access path β data access to the warehouse is always through the fact, and dimensions exist to qualify a measure; a dimension two hops away is joined twice on every question that mentions it. Bounded joins β the starβs guarantee is dimensions single joins β Star Schema; snowflaking trades that bound away, so it must be forced by the source (Bridge Tables) rather than chosen for tidiness.