DIVISION Operation
DIVISION Operation
Most relational algebra operations (SELECT, PROJECT, JOIN) answer existential queries:
-
Does there exist a matching tuple?
-
Find employees who work on project X
But some queries are universal in nature:
Find employees who work on all projects that John Smith works on
This “for all” requirement is exactly what the DIVISION (÷) operation is designed for.
👉 DIVISION captures universal quantification (“all”, “every”).
Intuition Behind DIVISION
Think of DIVISION as answering:
Which values are associated with every value in another set?
In general terms:
-
We have a numerator relation (larger relation)
-
We divide it by a denominator relation (a set of required values)
-
The result contains those tuples that are related to all denominator values
Example
Query:
Retrieve the names of employees who work on all the projects that ‘John Smith’ works on
Step-by-Step Explanation
Step 1: Find John Smith
-
This selects the EMPLOYEE tuple for John Smith.
-
We now know Smith’s Ssn.
Step 2: Find Projects John Smith Works On
-
Join
WORKS_ONwithSMITH -
Project only the project numbers
-
Result:
SMITH_PNOS(Pno) = all projects that John Smith works on
This relation becomes the denominator in the division.
Step 3: Create Employee–Project Pairs
-
This relation lists every employee and every project they work on
-
Schema:
SSN_PNOS(Essn, Pno)
This is the numerator in the division.
Step 4: Apply DIVISION
Meaning:
Select those
Essnvalues such that for every project in SMITH_PNOS,
the pair ⟨Essn, Pno⟩ exists in SSN_PNOS
In plain English:
👉 Employees who work on all projects that John Smith works on
The result contains only Ssn values.
Step 5: Get Employee Names
-
Join the resulting SSNs with EMPLOYEE
-
Project names
-
Final answer: employee names
Formal Definition of DIVISION
Let:
-
R(Z) be the numerator relation
-
S(X) be the denominator relation
-
X ⊆ Z
-
Y = Z − X
Then:
The result of
R ÷ Sis a relation T(Y) such that a tuple t is in T
if and only if, for every tuple tS in S, there exists a tuple tR in R where:
tR[X] = tS
tR[Y] = t
📌 This is the key sentence students must understand.
Meaning of the DIVISION Operation
For a tuple t to appear in the result T of a DIVISION operation:
-
The values in t must appear in the numerator relation R
-
In combination with every tuple in the denominator relation S
In other words:
A tuple is included in the result only if it is associated with all values present in the denominator relation.
Role of the Denominator Relation
-
The denominator relation S acts as a restricting relation
-
It does not contribute attributes to the result
-
Instead, it specifies a set of required values
The DIVISION operation selects only those tuples from the numerator relation R that:
-
Match every value in S
-
Satisfy the condition of universal participation
Key Insight
-
The numerator relation R provides the candidate tuples
-
The denominator relation S enforces the “for all” condition
-
Only those tuples in R that are related to all tuples in S appear in the result
Visual Interpretation
What Happens Conceptually?
-
R contains many (A, B) pairs
-
S contains required A values
-
DIVISION returns those B values that appear with every A in S
In Figure 8.8(b):
-
b1andb4appear with all A values in S → included -
b2,b3miss at least one A → excluded
Why DIVISION Is Hard to Implement Directly
-
DIVISION is not primitive
-
It can be expressed using PROJECT, CARTESIAN PRODUCT, and SET DIFFERENCE
From the book:
This formulation:
-
Generates candidates
-
Eliminates those missing required combinations
Key Points
✔ DIVISION answers “for all” queries
✔ Denominator specifies required values
✔ Result includes only tuples satisfying every requirement
✔ SQL does not directly support DIVISION
✔ Implemented using NOT EXISTS, GROUP BY + HAVING, or nested queries in SQL
Summary
DIVISION returns those tuples that are related to all tuples in another relation.


Comments
Post a Comment