• edited by
38,476 views
71 71 votes

Consider a database that has the relation schemas EMP(EmpId, EmpName, DeptId), and DEPT(DeptName, DeptId). Note that the DeptId can be permitted to be NULL in the relation EMP. Consider the following queries on the database expressed in tuple relational calculus.

  1. {$t$ | $\exists$u $\in$ EMP(t[EmpName] = u[EmpName] $\wedge$ $\forall$v $\in$ DEPT(t[DeptId] $\neq$ v[DeptId]))}
  2. {$t$ | $\exists$u $\in$ EMP(t[EmpName] = u[EmpName] $\wedge$ $\exists$v $\in$ DEPT(t[DeptId] $\neq$ v[DeptId]))}
  3. {$t$ | $\exists$u $\in$ EMP(t[EmpName] = u[EmpName] $\wedge$ $\exists$v $\in$ DEPT(t[DeptId] $=$ v[DeptId]))}

Which of the above queries are safe?

  1. I and II only
  2. I and III only
  3. II and III only
  4. I, II and III

8 Answers

0 0 votes

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:

QueryFreeBound
Itu, v
IItu, v
IIItu, 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. 

0 0 votes
Answer: D. I, II and III

A TRC query is safe if, for every finite database, its result is also finite.

Query I:
∃u ∈ EMP restricts t[EmpName] to values from the finite EMP relation. Hence, the result is finite. So I is SAFE.

Query II:
Both u and v are taken from the finite relations EMP and DEPT. Therefore, the result is finite. So II is SAFE.

Query III:
t[EmpName] comes from finite EMP and t[DeptId] must match a value from finite DEPT. Hence, the result is finite. So III is SAFE.

Therefore, all three queries are safe.

Correct Answer: D. I, II and III
Answer:
Position:
Show:

Related questions

73 73 votes
5 answers 5 answers
22.0k
22.0k views
Arjun asked Feb 14, 2017
21,976 views
Consider a database that has the relation schema CR(StudentName, CourseName). An instance of the schema CR is as given below.$$\begin{array}{|c|c|} \hline \textbf{Student...
125 125 votes
5 answers 5 answers
43.9k
43.9k views
Arjun asked Feb 14, 2017
43,904 views
In a database system, unique timestamps are assigned to each transaction using Lamport's logical clock. Let $TS(T_{1})$ and $TS(T_{2})$ be the timestamps of transactions ...
97 97 votes
3 answers 3 answers
24.5k
24.5k views
Arjun asked Feb 14, 2017
24,452 views
The following functional dependencies hold true for the relational schema $R\left \{V,W,X,Y,Z \right \}$:$V \rightarrow W$$VW \rightarrow X$$Y \rightarrow VX$$Y \rightarr...
3 3 votes
0 0 answers
1.8k
1.8k views
Warlock lord asked Jan 19, 2018
1,849 views
Is the query below safe? {t | ∃u ∈ EMP(t[EmpName] = u[EmpName] ∧ ∀v ∈ DEPT(t[DeptId] == v[DeptId]))}Please explain why.