R × S |
R = {1, 2}; S = {2, 4}; R × S = { (1,2), (1,4), (2,2), (2,4) } |
|
|
|
Nested-loop cartesian-product algorithm:
Let M = # available buffers; /* ------------------------------------------- Outer loop: read M-1 block of S ------------------------------------------- */ while ( S has more data blocks ) { read M-1 data blocks of S; Reset R; /* ------------------------------------------- Innerloop: read through R and compute × ------------------------------------------- */ while ( R has more data blocks ) { read 1 data block of R; for ( each tuple s ∈ M-1 blocks of S and each tuple t ∈ 1 blocks of R ) do { output (s, t); } } } |
Graphically:
|
Comment:
|
Algorithm read S once: # disk I/Os = B(S) |
|
|
Observation:
|
B(R) = 10,000 B(S) = 5,000 M = 101 |
Configuration: (1) Use 100 buffers to hold tuples of S (2) Use 1 buffers to scan R |
Configuration: (1) Use 100 buffers to hold tuples of R (2) Use 1 buffers to scan S |
|