We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Group By ROLLUP produces a*((b+1)(c+1)) + 1 rows.
This is because if we have ROLLUP(D1,D2,D3) we can decompose it to ROLLUP(D1,D2), that has a(b+1) +1 rows, because we can think about it as the cartesian product between D1 and (D2 + NULL item), plus the NULL,NULL final row. So with ROLLUP(D1,D2,D3), we know that each D1 row can be grouped with b rows of D2, that is {(D1.1, D2.1),...,(D1.1,D2.b),....} but then, each D2.x row, can be combined with c rows of D3, that is {(D1.1, D2.1,D3.1),...,(D1.1,D2.b, D3.c),...}.
But, we'll have for each D2 row also the tuple (D1.x, D2.y_, NULL), and for each D1 row the tuple (D1.x,NULL,NULL), that results in the a*[b*(c+1)+1]+1 final formula.
with D1,D2,D3,D4 columns, and D4 with d distinct values, ROLLUP(D1,D2,D3,D4) generates a*[b*[c*(d+1)+1]+1] + 1 rows.
GROUP BY CUBE instead is the cartesian product of (a+1)(b+1)(c+1), since (a+1), etc.. are all the current rows plus the NULL value.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
OLAP Operation Types
You are viewing a single comment's thread. Return to all comments →
Group By ROLLUP produces a*((b+1)(c+1)) + 1 rows. This is because if we have ROLLUP(D1,D2,D3) we can decompose it to ROLLUP(D1,D2), that has a(b+1) +1 rows, because we can think about it as the cartesian product between D1 and (D2 + NULL item), plus the NULL,NULL final row. So with ROLLUP(D1,D2,D3), we know that each D1 row can be grouped with b rows of D2, that is {(D1.1, D2.1),...,(D1.1,D2.b),....} but then, each D2.x row, can be combined with c rows of D3, that is {(D1.1, D2.1,D3.1),...,(D1.1,D2.b, D3.c),...}. But, we'll have for each D2 row also the tuple (D1.x, D2.y_, NULL), and for each D1 row the tuple (D1.x,NULL,NULL), that results in the a*[b*(c+1)+1]+1 final formula.
with D1,D2,D3,D4 columns, and D4 with d distinct values, ROLLUP(D1,D2,D3,D4) generates a*[b*[c*(d+1)+1]+1] + 1 rows.
GROUP BY CUBE instead is the cartesian product of (a+1)(b+1)(c+1), since (a+1), etc.. are all the current rows plus the NULL value.