1. Like selection, projection reduces the size of relations.
It is advantageous to apply projections early. Consider this form of our example query:
â…¡bname;assets ((( ∑ccity="Port Chester"(customer)) ∝ deposit) ∝ branch)
2. When we compute the subexpression
(( ∑ccity="Port Chester"(customer)) ∝ deposit)
we obtain a relation whose scheme is
(cname, ccity, bname, account#, balance)
3. We can eliminate several attributes from this scheme. The only ones we need to retain are those that
- appear in the result of the query or
- are needed to process subsequent operations.
4. By eliminating unneeded attributes, we reduce the number of columns of the intermediate result, and thus its size.
5. In our example, the only attribute we need is bname (to join with branch). So we can rewrite our expression as:
â…¡bname,assets (( â…¡bname(( ∑ccity="Port Chester"(customer)) ∝ deposit)) ∝ branch)
6. Note that there is no advantage in doing an early project on a relation before it is needed for some other operation:
- We would access every block for the relation to remove attributes.
- Then we access every block of the reduced-size relation when it is actually needed.
- We do more work in total, rather than less!
