Safety is asking:
Can the result be guaranteed to be finite?
you shouldn't get distracted by the ∀ versus ∃ when determining safety.
When checking a TRC query for safety:
1. Find the free variables.
2. Ask whether their possible values/tuples are restricted
to finite database relations.
3. Check whether negation/complement can make them range
over the unrestricted universe.
For all three:
| Query | Free | Bound |
|---|
| I | t | u, v |
| II | t | u, v |
| III | t | u, v |
(D) — all three are safe.
The important question is:
Can the query produce infinitely many possible output tuples from the unrestricted universe?
Here, t is constrained through:
∃u ∈ EMP
(
t[EmpName] = u[EmpName]
∧ ...
)
Since u must come from the finite relation EMP, the EmpName of the output t must correspond to an existing EMP tuple.
That bounds the possible results.
The v variables are also explicitly restricted:
v ∈ DEPT
so they range only over the finite DEPT relation rather than over the entire universe.
Hence all three are safe.