Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Databases 5841 DATA CUBE. Index of Content 1. The “ALL” value and ALL() function 2. The New Features added in CUBE 3. Computing the CUBE and.

Similar presentations


Presentation on theme: "Advanced Databases 5841 DATA CUBE. Index of Content 1. The “ALL” value and ALL() function 2. The New Features added in CUBE 3. Computing the CUBE and."— Presentation transcript:

1 Advanced Databases 5841 DATA CUBE

2 Index of Content 1. The “ALL” value and ALL() function 2. The New Features added in CUBE 3. Computing the CUBE and ROLLUP 4. Maintaining the CUBE and ROLLUP

3 3.3 The ALL Value - Each “ALL” value is actually represents a set. - The set over which the aggregation was computed. Ex. Model.ALL ={Toyota, Ford, Nissan} Ex2.

4 The ALL() Function - ALL() function generates the set. - ALL() applied to any other value returns NULL. Ex. Model.ALL = ALL(Model) = {Toyota, Ford, Nissan} Year.ALL = ALL(Year) = {2011, 2012, 1990} Color.ALL = ALL(Color) = {Red, Blue, Gray}

5 The Reasons to Avoid the ALL Value Introduction of ALL makes things complicated - ALL becomes a new keyword denoting the set value. - ALL is similar to NULL make many special cases. - What if SQL does not support Set-Value?

6 3.4 Avoiding the ALL Value Inspired by the ALL() function: A substitution of implementing the ALL value - Use GROUPING() (a boolean function) to discriminate between NULL and ALL - Use NULL value in the coulmn instead of ALL value Output: (NULL,NULL,NULL,524,True,True,True)

7 Example: QUERY: SELECT Model, Year, Color, SUM(sales), GROUPING(Model), GROUPING(Year), GROUPING(Color) FROM Sales GROUP BY CUBE Model, Year, Color; Output: (NULL,NULL,NULL,524,True,True,True) Compare to : (ALL,ALL,ALL,524) Note. True means it is the ALL value

8 Example1. 4. Two New Features Added in CUBE

9 What About the Percentage of Total Sales? Example1.

10 Now we can reference to the sub-aggregate value. 1. Reference to the sub-aggregate:

11 2. Index of a Value How to select a data in 2-D CUBE?

12 2. Index of a Value How to select a data in 2-D CUBE?

13 2. Index of a Value How to select a data in 2-D CUBE? What if we want to select a V in N-Dimension?

14 2. Index of a Value When the dimension goes higher, it is even harder to describe a point in a CUBE. A query is too long to write.

15 With the index, it is easier to query the data in the CUBE. Especially with a higher dimension CUBE. cube.v(:i, :i, :k)

16 5. Computing the CUBE and ROLLUP - It is all about Aggregate Function F() Ex. SUM(), COUNT(), AVERAGE() Generalize: GROUP BY -> ROLLUP -> CUBE Basic Way to Compute: - ROLLUP: Sort the table on the aggregating attributes and then compute the aggregate functions. - CUBE: UNION of many ROLLUP, so the naïve way to compute is union.

17 The Aggregate Function Call the aggregate function for each new value and invokes the aggregate function to get the final value Init (&handle) Iter (&handle, value) Value = Final(&handle) Start() – Initialize and allocate a scratchpad Next() – When each value to be aggregated End() – Compute and return the aggregate value and then deallocate the scratchpad

18 GROUP BY review Output: GROUP BY Query:

19 ROLLUP review For N-Dimension need N UNIONs ROLLUP Query: Output: ROLLUP: Sort the table on the aggregating attributes and then compute the aggregate functions.

20 ROLLUP review For N-Dimension need N UNIONs ROLLUP Query: Output:

21 CUBE review

22

23

24

25 2 N - Algorithm

26 In 3-D CUBE, the Iter() will be called 8 times BRANDMODELCOLORNUMBER MAZDASPEED6BLACK3 MAZDASPEED6ALL5 MAZDAALLBLACK30 ALLSPEED6BLACK3 MAZDAALL 50 ALL BLACK70 ALLSPEED6ALL5 100

27 In 3 dimension CUBE, the Iter() will be called 8 times. BRANDMODELCOLORNUMBER MAZDASPEED6BLACK3 MAZDASPEED6ALL5 MAZDAALLBLACK30 ALLSPEED6BLACK3 MAZDAALL 50 ALL BLACK70 ALLSPEED6ALL5 100

28 Distributive Function Def. Aggregate function F() is distributive, if there is a function G() such that Example: COUNT(), MIN(), MAX() and SUM() - Can be divided into many sub-aggregates - F() = G(), but COUNT() - For COUNT(), G() = SUM() and F()=COUNT() - Both G(),F() return single value

29 IDAge 115 220 355 42 57 636 711 888 940 Distributive Function: COUNT() COUNT1() COUNT2() COUNT3()

30 IDAge 115 220 355 42 57 636 711 888 940 Distributive Function: COUNT() COUNT1() COUNT2() COUNT3() SUM()

31 Algebraic Function Def. Aggregate function F() is algebraic if there is an M-tuple valued function G() and a function H() that Example: Average(), Center-of-Mass(), MaxN() - Can be divided into many sub-aggregates - Sub-aggregate returns Set-Value - G() returns M-tuple and H() returns single value - For F() = AVERAGE(): G()={value,count}, H()= SUM(value)/SUM(count)

32 IDAge 115 220 355 42 57 636 711 888 940 Algebraic Function: Average()

33 IDAge 115 220 355 42 57 636 711 888 940 G1()={SUM1(), COUNT1} G2()={SUM2(), COUNT2()} G3()={SUM3(), COUNT3()} Algebraic Function: Average()

34 IDAge 115 220 355 42 57 636 711 888 940 H() = SUM()/COUNT() Algebraic Function: Average() G1()={SUM1(), COUNT1} G2()={SUM2(), COUNT2()} G3()={SUM3(), COUNT3()}

35 Holistic Function Def. Aggregate function F() is holistic if there is no constant bound on the size of the storage needed. Example: Median(), MostFrequent() and Rank() - Must go through every data - Can not separate in to sub-aggregate The most efficient way: 2 N -algorithm (the slowest)

36 IDAge 115 220 355 42 57 636 711 888 940 Algebraic Function: Rank() Have to go through each data!

37 The Aggregate Function in CUBEs Call the aggregate function for each new value and invokes the aggregate function to get the final value Init (&handle) Iter (&handle, value) Value = Final(&handle)

38 The Aggregate Function in CUBEs Call the aggregate function for each new value and invokes the aggregate function to get the final value Init (&handle) Iter (&handle, value) Value = Final(&handle) Super-aggregates: Iter_super(&handle, &handle)

39 Distributive Function To Compute the Distributive Function Value: where Aggregate Function F(), Cardinality C, and Dimension N Color Model Time (Model, Color, Time) (ALL, Color, Time) (Model, ALL, Time) (ALL, ALL, ALL) 3D CUBE (ALL, ALL, Time)

40 Distributive Function Iter_super(&handle, &handle)

41 How about INSERT, DELETE and UPDATE? UPDATE = DELETE + INSERT Is it the same?

42 6. Maintaining Cubes and Roll-Ups F() = Max() Distribute for SELECT and INSERT Holistic for DELETE UPPDATE is DELETE plus INSERT


Download ppt "Advanced Databases 5841 DATA CUBE. Index of Content 1. The “ALL” value and ALL() function 2. The New Features added in CUBE 3. Computing the CUBE and."

Similar presentations


Ads by Google