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)

ModelFact’s dimension keysCampus dimension holdsProCon / verdict
Separate dimensions and no country columneach dimension one hop from the fact already determines the country ⟹ the second key is redundant in every fact row
Combined dimension onlyfewest tables, one join, one query pathdimension sits in 2NF β€” harmless in a warehouse
Hierarchy dimensions only dimensions in 3NFextra join for a country-level question; already covers the child dimension
Linked dimensions and noneredundancy β€” 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

StepFact keyed onRowComposite 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