edited by
8,754 views
46 votes
46 votes

Which of the following relational calculus expression is not safe?

  1. $\left\{t \mid \exists u \in R_1\left(t[A] = u[A]\right) \land \neg \exists s \in R_2 \left(t[A] = s[A]\right)\right\}$
  2. $\left\{ t \mid \forall u \in R_1\left(u[A]="x" \Rightarrow \exists s \in R_2\left(t[A] = s[A] \land s[A] = u[A]\right)\right) \right\} $
  3. $\left\{t \mid \neg (t \in R_1)\right\} $
  4. $\left\{t \mid \exists u \in R_1\left(t[A]=u[A]\right) \land \exists s \in R_2 \left(t[A] = s[A]\right)\right\}$
edited by

6 Answers

Best answer
45 votes
45 votes

Answer: C.

It returns tuples not belonging to R1 (which is infinitely many). So, it is not safe.

Reference: https://people.cs.pitt.edu/~chang/156/10calculus.html

edited by
2 votes
2 votes
Well it’s obvious that the answer is (C).

But can anyone verify my analysis of other Options?

Option (A) : Prints values which are in column A of R1,but not in Column A of R2.

Option (B) : It will print ‘x’ every time it is in column A of R1 and in atleast one time in column A of R2. Oh wait ,bcoz it is a Set ,’x’ will be printed only once!

Option (D) : Prints values if which are in column A
of both relations R1 & R2
2 votes
2 votes

{t∣¬(t∈R1)}

If we run this query the tuples we get does not belong to the instances of relation R1, so according to definition this expression is unsafe.

ANSWER: C

 

2 votes
2 votes

Answer will be $B,C.$

TRC Queries in both Option B, C are Unsafe Queries. 

Definition of “Unsafe TRC Expression”: Any expression whose result uses “constants / values” that do not appear in the instances of any of the database relations.  

Option B:

NOTE that “$x$” is some constant value, in the domain of variable $A.$

Case 1:

If the instance of $R_1$ has at least one tuple where $R_1.A = $ ”$x$” & the instance of $R_2$ also has at least one tuple where $R_2.A = $ ”$x$” then the result of the TRC query will be a table with single column named $A$ and only one row with value “$x$”.

Case 2:

If the instance of $R_1$ has at least one tuple where $R_1.A = $ ”$x$” BUT the instance of $R_2$ also has NO tuple where $R_2.A = $ ”$x$” then the result of the TRC query will be an Empty table with single column named $A$ i.e. Output is Empty.

Case 3:

If the instance of $R_1$ has NO tuple where $R_1.A = $ ”$x$” then every value in the domain of attribute $A$ will satisfy the condition given in the TRC query & hence, will appear in the output. Hence, in this case, we get an infinite number of tuples in the output.

Hence, Query in Option B is Unsafe. 

Answer:

Related questions

128 votes
128 votes
6 answers
3
7 votes
7 votes
3 answers
4
go_editor asked Feb 8, 2018
2,045 views
Consider a relation examinee (regno, name, score), where regno is the primary key to score is a real number.Write an SQL query to list the regno of examinees who have a s...