All Exams Test series for 1 year @ ₹349 only
Question

Consider a fact table in an OLAP application: Facts(D1, D2, val), where D1 and D2 are its dimension attributes and val is a dependent attribute. Suppose attribute D1 takes 3 values and D2 takes 2 values, and all combinations of these values are present in the table Facts. How many tuples are there in the result of the following query?
SELECT D1, D2, sum(val)
FROM Facts
GROUP BY CUBE (D1, D2);

The correct answer is
12

Fact Table Tuple Count with GROUP BY CUBE

This solution calculates the number of tuples generated by a $GROUP BY CUBE$ query on a given fact table structure.

Understanding GROUP BY CUBE

The $GROUP BY CUBE$ clause generates all possible grouping combinations (grouping sets) for the specified dimensions, including the grand total. For dimensions D1 and D2, the grouping sets are:

  • $(D1, D2)$: Aggregation for every combination of D1 and D2 values.
  • $(D1)$: Aggregation for each D1 value (subtotal across D2).
  • $(D2)$: Aggregation for each D2 value (subtotal across D1).
  • $()$: The grand total (aggregation across all dimensions).

Fact Table Dimensions

The problem specifies a fact table with dimensions:

  • Dimension $D1$ has 3 distinct values.
  • Dimension $D2$ has 2 distinct values.

It's stated that all combinations of these values exist in the fact table.

Calculating Tuple Count

We can determine the total number of tuples by summing the counts from each grouping set:

  • Tuples for $(D1, D2)$: Number of D1 values $\times$ Number of D2 values = $3 \times 2 = 6$.
  • Tuples for $(D1)$: Number of D1 values = $3$.
  • Tuples for $(D2)$: Number of D2 values = $2$.
  • Tuple for $()$ (Grand Total): $1$.

Total tuples = $6 + 3 + 2 + 1 = 12$.

Alternatively, a direct formula for the size of a $CUBE$ operation on dimensions with $n_1, n_2, ..., n_k$ distinct values is:

$ (n_1 + 1) \times (n_2 + 1) \times \dots \times (n_k + 1) $

For this case (D1 and D2):

$ (3 + 1) \times (2 + 1) $

$ 4 \times 3 $

$ 12 $

Final Result

The query using $GROUP BY CUBE (D1, D2)$ will produce 12 tuples.

Was this answer helpful?

Important Questions from Data Warehouse Modelling

  1. Consider that the visualization of a 3-dimensional data cube is showing Sales Quantity for each combination of the attributes Product Type, Month and Country.

    From this, if we want to further visualize the Sales Quantity for each combination of Product Type, Month and State, which of the following OLAP operations should be performed?
  2. Consider the concept hierarchies as shown in the figure.

    Which of the following options denotes the total number of possible data cuboids from these concept hierarchies?

     

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App