One Pass Algorithm Presented By: Presented By: Farzana Forhad Farzana Forhad ID : 107
Agenda Agenda One pass Algorithm- what it means? Tuple-at-a-Time Unary Operations Binary operations: R ∩ S, R U S, R – S
One-pass Algorithms In query optimization, some methods involve reading the data only from the disk, that is one pass algorithm.In query optimization, some methods involve reading the data only from the disk, that is one pass algorithm. They work only when at least one of the arguments of the operation fits in main memory.They work only when at least one of the arguments of the operation fits in main memory.
Tuple-at-a-Time The tuple-at-a-time operations sigma(R) and pi(R) have obvious algorithms, regardless of whatever the relation fits in main memory.The tuple-at-a-time operations sigma(R) and pi(R) have obvious algorithms, regardless of whatever the relation fits in main memory. We read the blocks of R one at a time into an input buffer, perform the operation on the tuple, and more the selected tuples or the projected tuples to the output buffer.We read the blocks of R one at a time into an input buffer, perform the operation on the tuple, and more the selected tuples or the projected tuples to the output buffer.
Tuple-at-a-Time If R is initially on disk, then the cost is whatever I takes perform a table-scan or index-scan of R.If R is initially on disk, then the cost is whatever I takes perform a table-scan or index-scan of R. The cost, typically it is B if R is clustered and T if it is not clustered.The cost, typically it is B if R is clustered and T if it is not clustered. Input bufferOutput buffer Unary operator
Unary Operations Duplicate elimination (R)- To eliminate duplicates we can read each block of R at a time, and check… If it is the first time for the tuple, in which case we copy it to the output, or If we have seen the tuple before, we must not output the tuple. Assumption: B( (R)) <= M
Unary Operations Grouping- For a MIN(a) or MAX(a) aggregate, record the minimum and maximum value.For a MIN(a) or MAX(a) aggregate, record the minimum and maximum value. For any COUNT aggregation, add one for each tuple of the group that is seen.For any COUNT aggregation, add one for each tuple of the group that is seen. For SUM(a), add the value of attribute a to the accumulated for its group.For SUM(a), add the value of attribute a to the accumulated for its group. AVG(a) is the hard case.AVG(a) is the hard case.
Binary operations Binary operations: R ∩ S, R U S, R – S Assumption: min(B(R), B(S)) <= M Scan one table first, then the next, eliminate duplicates Cost: B(R)+B(S)