Another way to reduce the size of temporary results is to choose an optimal
ordering of the join operations.
Natural join is associative:
Although these expressions are equivalent, the costs of computing them may
differ.
Look again at our expression
we see that we can compute depositbranch first
and then join with the first part.
However, depositbranch is likely to be a large
relation as it contains one tuple for every account.
The other part,
is probably a small relation (comparatively).
So, if we compute
first, we get a reasonably small relation.
It has one tuple for each account held by a resident of Port Chester.
This temporary relation is much smaller than
depositbranch.
Natural join is commutative:
Thus we could rewrite our relational algebra expression as:
But there are no common attributes between customer and
branch, so this is a Cartesian product.
Lots of tuples!
If a user entered this expression, we would want to use the
associativity and commutativity of natural join to transform this
into the more efficient expression we have derived earlier (join with
deposit first, then with branch).