Which of the rational calculus expression is not safe?

- $\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\}$
- $\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\} $
- $\left\{t \mid \neg (t \in R_1)\right\} $
- $\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\}$

### 4 Comments

## 5 Answers

Answer: C.

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

Reference: http://nptel.ac.in/courses/IIT-MADRAS/Intro_to_Database_Systems_Design/pdf/3.1_Tuple_Relational_Calculus.pdf

### 14 Comments

Consider a relational schema R1 and generally it can take infinite values if domains of attributes aren't restricted.So for any finite instances of relation {*t*∣¬(*t*∈*R*1)} will generate instance with infinite tuples so it is unsafe.

eg. R1(Roll Number, Marks) and consider domain of Roll number +ve integers. restriction on marks doesn't matter.

consider a instance of R1

Roll Number | Marks |
---|---|

1 | 22 |

2 | 78 |

now this {*t*∣¬(*t*∈*R*1)} will generate all possible value that can be in roll number and Marks exclusing (1,22) and (2,78). That will be infinite so this query is unsafe.

Now, when you say $\{t| t \in R\}$ where R is any relation, then we have bounded the number of tuples, the tuple variable t can refer and it will be always in the domain of R and not outside it, so it will refer to finite tuples.

When we say $\{t| \lnot(t\in R)\}$, means all tuples not in relation R, and there can be many tuples which are not R or not in R, and hence infinite result set and hence an unsafe query.

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