Set Operations in Relational Algebra

Context: FIT2094_MOC · union, intersect, difference on relations · require union-compatible operands · the FIT1058 set operations applied to data

Quick Revision

  • 🎯 Objective: set ops on relation bodies ➔ union , intersect , difference .
  • 📦 Core Components: require union-compatible operands (same arity, compatible domains).
  • ⚡ Key Constraint: difference is not symmetric (); duplicates auto-collapse.

📝 Core

1. The Operations

  • Union = tuples in either (duplicates once).
  • Intersection = tuples in both.
  • Difference = tuples in not .

2. Union-Compatibility

  • Same arity ➔ same number of attributes.
  • Compatible domains ➔ positionally matching domains.
  • Mandatory ➔ else the result isn’t a well-formed relation.

3. Symmetry

  • Symmetric ➔ union, intersection commute.
  • Asymmetric ➔ difference: .

Key identities:

⚖️ Core Decision Matrix

OperationSymbolSymmetric?Result
unionyeseither
intersectionyesboth
differencenoin A not B
preconditionunion-compatible

When It Flips: these are exactly the FIT1058 set operations on the tuple sets — inclusion–exclusion and De Morgan carry over, with union-compatibility as the new precondition. Closure holds, so set ops compose with σ/π and joins. Unlike joins (different schemas), set ops need identical schemas.

📊 Exam Execution Trace

Manual Execution Trace

STOREA, STOREB:

Step / StateOpResult
0 (Init)
1
2
3

⚠️ Common Mistakes

  • 💡 Union-compatibility required ➔ same arity + positionally compatible domains (both (product_id, product_name)); difference is directional.

🧠 Active Recall