• edited by
16,991 views
62 62 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\}$

10 Answers

Best answer
56 56 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
16 16 votes

Answer should 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. 

• edited by
3 3 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 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
1 1 vote
The relations that result in infinite number of tuples are considered to be unsafe operations. And so safe operations give us finite number of tuples. But here option (C) gives us infinite number of tuples as it results in tuples which are not belonging to R and since they are infinite.
0 0 votes

Imagine we have two tables: R1(A,B,C) and R2(A,M,N) where "u" and "s" denote tuples from each relation respectively. 

The output tuple "t" should satisfy the following condition:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(a) SAFE

t[A]=u[A] AND NOT(t[A]=s[A])

This means: the attribute will be present in the output tuple "t" if it is the attribute A from R1​, and that same value of A should not appear in R2​.

From this analysis, there is no possibility of the relation generating an infinite output.
Thus, option (a) is safe and the correct answer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(b) SAFE

In predicate logic, "for all" (∀) is usually followed by implication (⇒), keeping things simple.

If all u[A] in R1​ are "x", then " t " will have that value from R2
If not, the result is empty.

This clearly means the output won’t be infinite, so the query is safe.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(c) UNSAFE

Assume R is a finite set. Then NOT R means we're considering everything not in R, which has no defined boundary. It could include an infinite number of unknown values.

So, as simple as that , the result can be infinite, making it unsafe.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(d) SAFE

Here, the output will include only those values of A that are common to both R1(A)and R2(A).
Basically, it’s like saying, “Give me what’s in both friend circles.”

 

Answer:
Position:
Show:

Related questions

90 90 votes
5 answers 5 answers
15.2k
15.2k views
Kathleen asked Sep 14, 2014
15,240 views
Suppose the adjacency relation of vertices in a graph is represented in a table Adj $(X,Y).$ Which of the following queries cannot be expressed by a relational algebra ex...
85 85 votes
9 answers 9 answers
20.8k
20.8k views
Kathleen asked Sep 14, 2014
20,816 views
Consider a relation geq which represents "greater than or equal to", that is, $(x,y) \in $ geq only if $y \geq x$.create table geq ( ib integer not null, ub integer not n...
188 188 votes
8 answers 8 answers
79.8k
79.8k views
Kathleen asked Sep 14, 2014
79,792 views
$R(A,B,C,D)$ is a relation. Which of the following does not have a lossless join, dependency preserving $BCNF$ decomposition?$A \rightarrow B, B \rightarrow CD$$A \righta...
13 13 votes
4 answers 4 answers
4.4k
4.4k views
go_editor asked Feb 8, 2018
4,354 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...