The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+1 vote
152 views

If there are three tables to choose from -

Sailors(sid,sname); Reserves(sid,bid); Boats(bid,color)

Question is to choose a sailor who reserved a red boat.

My question is what is the difference between these two TRC expressions.
 

  1. $\{s.sid\,|\,Sailors(s) \wedge (\exists r)(Reserves(r)\, \wedge\, r.sid=s.sid \,\wedge\, (\exists b)(Boats(b)\,\wedge\,r.bid=b.bid\,\wedge\,b.colour=\, 'red' )) \}$
  2. $\{s.sid\,|\,Sailors(s) \wedge (\exists r)(\exists b)(Reserves(r)\,\wedge\, Boats(b)\, \, \wedge\, r.sid=s.sid \wedge\,r.bid=b.bid\,\wedge\,b.colour=\, 'red' ) \}$

Which of the above is correct? Are both correct? Are none correct?

in Databases by (251 points)
edited by | 152 views

2 Answers

+1 vote
Best answer
it is easily understandable when you convert both into relational algebra queries-

(1)$\pi_{sid}[sailor\Join( reserves\Join (\sigma_{color=red}  Boats))] $

(2)$\pi_{sid}[sailor\Join reserves \Join_{color=red}Boats    ]$

as you can see both will give same result "sailors who has reserved red boat" but first one has better format because there will be less no. comparison than second one .
by Boss (10.3k points)
selected by
0

@Prateek Raghuvanshi
can you explain how number of comparisons in first query will be less?

+1 vote
1. sid of sailor , who is a sailor and there exist a reserve tuple r such that r.sid = s.sid and there exist a boat b whose boat id is same as sailor reserved and whose color is red. => i think this is true

2. sid of sailor ,  there exist a reserve tuple r and there exist a boat tuple b such that r.sid is same as s.sid and r.bid is same as b.bid and color is red

i think 2nd is also true.

so both are correct
by Active (3.2k points)
0
If you could enumerate the difference. Please.

Related questions

0 votes
1 answer
7
asked Nov 6, 2017 in Databases by Parshu gate Active (3.1k points) | 184 views
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
49,832 questions
54,800 answers
189,506 comments
80,728 users