What is the optimized version of the relation algebra expression…
2014
What is the optimized version of the relation algebra expression \(\pi_{A1}(\pi_{A2}(\sigma_{F1}(\sigma_{F2}(r))))\) where \(A1, A2\) are sets of attributes in \(r\) with \(A1 \subset A2\) and \(F1,F2\) are Boolean expressions based on the attributes in \(r\) ?
- A.
\(\pi_{A1}(\sigma_{(F1 \wedge F2)}(r))\) - B.
\(\pi_{A1}(\sigma_{(F1 \vee F2)}(r))\) - C.
\(\pi_{A2}(\sigma_{(F1 \wedge F2)}(r))\) - D.
\(\pi_{A2}(\sigma_{(F1 \vee F2)}(r))\)
Attempted by 284 students.
Show answer & explanation
Correct answer: A
Final optimized expression: π_{A1}(σ_{(F1 ∧ F2)}(r))
Reason:
Combine the two selections: applying the selection with F2 and then with F1 requires both predicates to hold, so σ_{F1}(σ_{F2}(r)) = σ_{(F1 ∧ F2)}(r).
Merge the two projections: projecting to A2 and then to A1 is the same as projecting directly to A1 when A1 is a subset of A2, so π_{A1}(π_{A2}(X)) = π_{A1}(X) for any relation X.
Apply these reductions to the original expression to get π_{A1}(σ_{(F1 ∧ F2)}(r)).
Caveat: do not replace conjunction with disjunction when composing selections, and be cautious about pushing projections before selections if the predicates reference attributes that would be removed by the projection.
A video solution is available for this question — log in and enroll to watch it.