Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

OLAP vs OLTP and data cubes

Clear, exam-focused notes comparing OLAP and OLTP, explaining data cubes, dimensions, measures and core OLAP operations with formulas, worked examples and likely exam questions.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Business Intelligence engineers build systems to help managers make fast, data-driven decisions. OLTP systems support everyday transaction processing (fast inserts/updates); OLAP systems support analytical queries (aggregations, trends). Understanding the difference and how data cubes (multidimensional pre-aggregated stores) work is essential when designing data warehouses, BI reports, dashboards and choosing ROLAP/MOLAP for performance and storage trade-offs.

Key ideas

  • Definition: Online Transaction Processing (OLTP) — systems optimized for high-volume, concurrent transactional workloads (short, simple reads/writes). Assumptions: many concurrent users, write-intensive, highly normalized schemas (3NF), strict ACID properties, low-latency per transaction.

  • Definition: Data warehouse — a central repository of integrated data from multiple sources, structured for analysis and reporting. Assumptions: subject-oriented, integrated, time-variant, non-volatile.

  • Definition: Data mart — a smaller, focused data warehouse for a department or subject area.

  • Definition: Dimension — an attribute or set of attributes by which measures are categorized (e.g., Time, Product, Customer). Dimensions are often hierarchical (e.g., Day → Month → Quarter → Year).

  • Definition: Measure — a numeric quantity stored in facts and aggregated in analysis (e.g., SalesAmount, QuantitySold). Measures are classified by additivity: additive across all dimensions (e.g., Quantity), semi-additive (e.g., AccountBalance additive across some dimensions but not Time), or non-additive (e.g., Ratios). Always state along which dimensions a measure can be aggregated.

  • Definition: Fact table — the central table in a dimensional schema that records measures tied to foreign keys of dimensions.

  • Definition: Data cube — a conceptual multidimensional array where each cell holds aggregated measure(s) for a particular tuple of dimension members. Exact statement: If D1..Dn are dimensions with cardinalities c1..cn, then the cube has at most ∏_{i=1..n} ci cells (assumes full materialization across all dimension combinations). A fully materialized cube contains 2^n cuboids (group-bys), from the base cuboid (all n dimensions) up to the apex (ALL).

  • Sparsity: real cubes are usually sparse (many empty cells) because not every combination of dimension members has facts.

  • OLAP operations (exact definitions exam-style):

    • Roll-up: aggregate data along a dimension hierarchy or by reducing dimensionality (e.g., from Day to Month). Assumption: a defined hierarchy or grouping exists.
    • Drill-down: the inverse of roll-up; move from higher-level summary to finer detail (e.g., Year → Quarter → Month).
    • Slice: select a single value for one dimension to produce a sub-cube (e.g., select Time=2025-01-01 gives a (n-1)-dimensional result).
    • Dice: select ranges or sets of values on two or more dimensions to produce a smaller sub-cube (e.g., Product in {A,B}, Region in {North}).
    • Pivot (rotate): reorient the cube’s dimensions for display/analysis (swap rows and columns in a report).
  • ROLAP vs MOLAP (exact statements):

    • ROLAP (Relational OLAP): OLAP built on top of a relational database; aggregates are stored in relational tables or computed on demand. Assumptions: uses SQL, benefits from relational storage and indexes, scales to very large dimensions but may have slower query performance unless aggregates are precomputed.
    • MOLAP (Multidimensional OLAP): OLAP built on a multidimensional array storage (proprietary cube stores). Aggregates are precomputed and stored in optimized multidimensional format; fast queries but potentially high storage for dense cubes and less flexible for very large dimension cardinalities.
    • HOLAP (Hybrid OLAP) (briefly): combines ROLAP and MOLAP: detailed data remains in relational storage, while commonly used aggregates are stored in multidimensional store.
  • Storage and performance trade-offs: materializing all aggregates (full cube) speeds queries (pre-aggregation cost) but increases storage and ETL time; partial aggregation or on-demand aggregation reduces storage but increases query latency.

  • Diagram instructions (what to draw):

    • Draw a 3D block (cube) labeled axes Time (z), Product (x), Region (y). Mark one cell and label it with a measure: SalesAmount = ₹X (or appropriate currency). Show a roll-up arrow on Time axis from Day to Month. Show a slice plane perpendicular to Product axis at Product=A.
    • Draw two small boxes labeled OLTP and OLAP: OLTP box shows many small transactions (Insert, Update) to normalized tables; OLAP box shows a cube with aggregated cells and few heavy read queries.

Formulas

N_cells = ∏_{i=1..n} c_i

  • N_cells = maximum number of cube cells (dimensionless). c_i = cardinality (number of distinct members) of dimension i. Applies when fully materializing all combinations.

Storage_full = N_cells × S_cell

  • Storage_full in bytes (B). S_cell = bytes per cell (storage needed to store measures and overhead). Applies when the cube is fully materialized and each cell is stored.

Sparsity = 1 - (N_facts / N_cells)

  • Sparsity is fraction of empty cells (dimensionless, between 0 and 1). N_facts = number of actual fact records mapped to unique cells. Applies when facts map to cube cells exactly once; if multiple facts per cell, aggregate first.

Storage_sparse_estimate ≈ N_facts × S_fact_storage

  • Storage in bytes. S_fact_storage = bytes to store an aggregated cell for each non-empty combination. Useful when materializing only non-empty cells.

Note: S_cell and S_fact_storage depend on implementation (e.g., 8 bytes for a double measure, plus overhead). Verify specific overheads for your platform.

Worked examples

Example 1 — Cube size and sparsity (numerical) Given: Dimensions and cardinalities — Time (365 days), Products (10,000 products), Customers (100,000 customers). Assume we store one aggregated measure SalesAmount as an 8-byte float and overhead per cell 24 bytes (total S_cell = 32 B). Actual distinct fact combinations recorded N_facts = 100,000,000 (1e8). Compute full cube storage and sparsity.

Step 1: N_cells = 365 × 10,000 × 100,000 = 365 × 10^9 = 365,000,000,000 cells. Step 2: Storage_full = N_cells × 32 B = 365e9 × 32 B = 11,680e9 B = 11,680 GB ≈ 11.68 TB. (using decimal units: 1 GB = 10^9 B, 1 TB = 10^12 B) Step 3: Sparsity = 1 - (1e8 / 365e9) = 1 - 0.000274 = 0.999726 ≈ 99.9726% sparse. Step 4: If we store only non-empty cells: Storage_sparse ≈ 1e8 × 32 B = 3.2e9 B = 3.2 GB.

Answer: Full materialization ≈ 11.68 TB; storing only non-empty cells ≈ 3.2 GB; cube sparsity ≈ 99.97%.

(Assumptions: overhead 24 B per cell is an example—verify for your platform.)

Example 2 — OLAP operations trace (small fact table) Fact table rows (Sales):

  1. (Time=2025-Jan, Product=A, Region=North, Sales=100)
  2. (2025-Jan, A, South, 50)
  3. (2025-Jan, B, North, 200)
  4. (2025-Feb, A, North, 150)

Operation traces:

  • Slice Time=2025-Jan → result contains rows 1,2,3 (drop Time dimension; present Product×Region cells).
  • Dice on the sliced Jan result: Product in {A} and Region in {North,South} → rows 1,2 (1×2 sub-cube: 1 product × 2 regions).
  • Roll-up on Time from Month to Quarter (assume Jan, Feb in Q1): aggregate Sales for Product A across Jan+Feb. For Product A, Region North: 100 (Jan) + 150 (Feb) = 250. Show aggregation step explicitly.
  • Drill-down: from Quarter to Month for Product B: show Q1 total 200 then drill to Month: 200 in Jan, 0 in Feb.
  • Pivot: display rows as Region, columns as Product (swap axes) using the sliced data.

Example 3 — Short model answer (theory question) Question: Compare OLTP and OLAP in terms of schema design and typical queries. Model answer (concise): OLTP uses normalized schemas (3NF) for write performance and integrity; typical queries: single-row reads/writes, e.g., INSERT order, UPDATE balance. OLAP uses dimensional schemas (star/snowflake) optimized for read/aggregations; typical queries: GROUP BY, large-range scans, multi-dimensional aggregations (e.g., total sales by product and month). Discuss differences in indexing, concurrency, and latency; mention ETL to move data from OLTP to OLAP (data warehouse) and pre-aggregation trade-offs.

Common mistakes

  • Treating cube cells as always dense; not accounting for sparsity in storage calculations.
  • Using inconsistent units in storage calculations (mixing bytes, KB, MB without conversion).
  • Stating that MOLAP is always faster or always uses less storage — performance depends on cube density and query patterns.
  • Forgetting overhead per cell (indexes, metadata) when estimating S_cell.

For your exam

Question types you will see: definitions (OLAP/OLTP, dimensions/measures), short notes (ROLAP vs MOLAP), derivations (cube cell count, storage estimates), diagrams (draw a 3D cube and label roll-up, slice), worked numericals (compute storage and sparsity), and algorithm traces (perform OLAP operations on a small fact table).

What a full-marks answer includes:

  • For definitions: the exact, bolded term and its key properties (assumptions like ACID for OLTP, time-variant and non-volatile for data warehouse).
  • For comparisons: a table or clear points comparing schema, workloads, query types, latency, and examples.
  • For diagrams: a labelled cube with axes, a marked cell, and arrows for roll-up/drill-down/slice.
  • For numericals: show formulas, units, each arithmetic step, and a final result with units and assumptions about overheads.
  • For ROLAP/MOLAP: explain storage model, typical use-cases, and performance trade-offs.

Quick check

  1. Define OLAP in one sentence.
  2. Write the formula for maximum number of cube cells for n dimensions.
  3. What OLAP operation selects a single value of one dimension to create a sub-cube?

Answers: 1) OLAP is a class of systems optimized for complex analytical queries using aggregated, often multidimensional data. 2) N_cells = ∏_{i=1..n} c_i. 3) Slice.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?