The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+20 votes

Which of the rational 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\}$
asked in Databases by Veteran (59.6k points)
edited by | 1.8k views
Should the variable t not bounded to a relation as well ? If it is not bounded to a relation then shouldn't t yield infinite no. of tupples in A,B and D. From what I have read the notation followed is { t | R(t) ^ <set of conditions> } .

Someone please explain how to read Queries 1, 2 and 3. Are they from TRC or DRC and how to interpret them in some English language!

Does not help at all !!!
Any expression whose result uses “constants / values”that do not appear in the instances of any of the database relations.     

or in Simple words

the expression which results in finite no of output is considered as Safe expression and which expression can give infinite output is unsafe.

2 Answers

+27 votes
Best answer

Answer: C.

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


answered by Boss (34.1k points)
edited by
it is unsafe because of infinite cardinality or inability to show all output ??
m not getting meaning of safe expression.
please explain
Safe expressions will give you definite number of tuples.
Can anyone give example of unsafe expression in any context / schema which does not involve negation to yield infinite tuples? I am searching for one such. Is this even possible? @Arjun sir?

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∣¬(tR1)}  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∣¬(tR1)} 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.

Generally, the tuple variable which we see in the TRC query $\{t|..\}$, this tuple variable points to all possible tuples in the universe.

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.
In Option A, B And D,

Nowhere Range for tuple variable ' t ' is mentioned

So t[A] it may points to tuple in any relation who has attribute named "A"

?? is it safe
in option A, B and D

t[A] should be equal to our tuple ===> so those are safe

 Option A:- {t∣∃u∈R1(t[A]=u[A])∧¬∃s∈R2(t[A]=s[A])} ===> you can take any tuple, but it should to equal to u[A] which is in our R1.
Got it ,

Somewhere we are restricting it !!

So query in A return any TUPLE in universe if There exists tuple in our relation R1 such that they agree on attribute A...considering first condition only

Is the equivalent SQL for (A)

Select *

From R1

Where R1.A not in (Select R2.A from R2)?

as per my knowledge, yes
–3 votes
both a) and c) should be true....can someone plz explain the correct answer
answered by Active (1.3k points)
A) A is not unsafe, because we have intersection with R1, so at max we can get all tuples from R1. There is no such restriction in C. So A is not answer

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

42,599 questions
48,601 answers
63,742 users