Slideshow:
γL ( R ) |
Note: L can be one of the following functions:
|
R = (x,y) R = { (a,2), (a,3), (b,1), (b,3) } γavg(y) ( R ) = { (a, 2.5), (b, 2.0) } |
initialize a search structure H on grouping attributes of γ; /* ========================================================= Process the statistics for each group ========================================================= */ while ( R has more data blocks ) { read 1 data block in buffer b; for ( each tuple t ∈ b ) { /* ===================================================== We need a search structure H to implement the test t ∈ H efficiently !!! We can use hash table or some bin. search tree ====================================================== */ if ( t ∈ H ) { Update the statistics for group(t); } else { insert t in H; Initialize the statistics for group(t); } } } /* ========================================================= Now we can output the aggregate function for each group ========================================================= */ for ( each group ∈ H ) { Output group search key + statistics; } |
The statistics depends on the aggregate function applied:
Aggregate function Statistics --------------------------------------------------------------- min current min value in each group max current max value in each group count current size of each group sum current running sum for each group avg current running sum for each group + current size of each group |
initialize a search structure H on grouping attributes of γ; while ( R has more data blocks ) { read 1 data block in buffer b; for ( each tuple t ∈ b ) { /* ===================================================== We need a search structure H to implement the test t ∈ H efficiently !!! We can use hash table or some bin. search tree ====================================================== */ if ( t ∈ H ) { if ( value(t) > max( group(t) ) ) { max ( group(t) ) = value(t) ; } } else { insert t in H; max ( group(t) ) = value(t) ; } } } for ( each group ∈ H ) { Output group search key + max( group ); } |
|
Explanation:
|
|
|
Recall:
|