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; } |
|
|
|
Graphically:
|
|
Consequently:
|
|
Graphically:
|
Disk read/write: 3 B(R) blocks
P-1
Transfered: ----- blocks
P
|
3
Disk read/write: --- B(R) blocks
P
P-1
Transfered: ----- blocks
P2
|
(Transfer cost can be ignored in shared nothing processors)