in Databases
3,815 views
4 votes
4 votes
Suppose you are given relations r(A, B) and s(A, C). Suppose that r has 10000 tuples, and s has 5000 tuples. Suppose attribute r.A has 1001 distinct values, and s.A also has 1001 distinct values. The maximum possible size of the join result is
in Databases
by
3.8k views

4 Comments

Type of join not mentioned. But how many tuples would result from a natural join? Can it be calculated from the above data?
0
0
Is     answer  5000
0
0
I think , some foreign key constraints may be given ????
0
0

4 Answers

4 votes
4 votes
Best answer

Refering page no. 121 - 123 of    http://cs.iit.edu/~cs525/slides/allhandouts.pdf 

CASE 2 : W = R1 Join R2 when X ∩ Y = A

T(W) = T(R2) * T(R1) / max{ V(R1,A), V(R2,A) }

where V(R1,A) = Max distinct column A tuples in Relation R1

   and  V(R2,A) = Max distinct Column A tuples in Relation R2

it should be (10000*5000)/1001 = 49950

A B
1 a1
1 a2
1 a3
1 a4
1 a5
2 b1
2 b2
2 b3
2 b4
2 b5
A C
1 u
1 v
2 w
2 y
2 z

R1(A,B) Join R2 (A,C) = 10*5/2 = 25 Tuples 

selected by

17 Comments

can   u pls elaborate with table
0
0
no, it will 25 only....
0
0
@Ashish I want to say  if there are two relation given for eg. R(A,B) and S(A,C).

here comman attribute is A, but it is not PK of any table. if R has total 10 tuples but only 2 distinct values. and S also has 2 distinct values with 5 total number of tuples.( same case as in your given eg)

Then R natural join with S, will give max 37 tuples. this is what I want to say..ignore my first comment.
0
0
@ Reena...what you want to say by "Then R natural join with S, will give max 37 tuples"....it is a relational instance, at particular instant of time it is fixed and therefore, it will give value 25 only...
0
0
If two relation R ans S, with tuples m and n respectively
1) if no attribute is comman then maximum no of tuples in natural join will be "mn".
2) but if any attribute is comman but not the key of any Table then in this case also max tuples will be "mn".
this is what I found,check it
1
1
@Nitish, I am not taking this perticular instance.
My statement is with respect to this question.
0
0
yes, this is what you are saying is true....but why are you saying that it will make 37 tupples...it is relational instance...there is nothing like minimum or maximum tupples for a relational instance...it will give fixed amount of tupples..
0
0

I am not taking above instance. 

 if there are two relation given for eg. R(A,B) and S(A,C)

I only considered the features of that table, not the values of tuples. 

0
0
@Reena ...can   u pls elaborate your answer with table (using data from above tables)... (its just because even i solved and found 25 tuples only)
0
0
see, what I am saying

yes its true for the above table answer is 25. what I actually want to say, read my all comments again!
0
0
i dint get ur query wrt to above table pls clear that... and ur first comment which said something about 37 tuples
0
0
I rremoved that comment. My mistake!!
0
0

If two relation R ans S, with tuples m and n respectively
1) if no attribute is comman then maximum no of tuples in natural join will be "mn".
2) but if any attribute is comman but not the key of any Table then in this case also max tuples will be "mn".
this is what I found,check it

2nd statement is wrong, if we consider @venkat_sirvisetti 's answer.
Please correct it! 

1
1
@Shyam take an instance and check it by yourself.

If anything wrong in that statement,then let me know!!
0
0
In this question, R and S has attribute "A" common but max no of tuples possible is not 10000*5000, hence I asked to correct it, if I misunderstood your 2nd statement then please clarify further.
0
0
That is because further conditions are also applied in the relations.
1
1
Now I understood properly :)
0
0
7 votes
7 votes
Considering natural join property where tuples are joined when the values of the common attributes are equal, the maximum joins wil be in this scenario:

In relation r, there are 1001 distinct values of A. Since total of 10000 tuples in r, we get 8,999 tuples with repeated values of A

Similary in realtion s, there are 1001 distinct values of A. Since total of 5000 tuples in s, we get 3,999 tuples with repeated values of A.

The maximum joins happen when all tuple are repeated with same value.

Hence total maximum joins possbile is (9000*4000) + 1000 = 36001000.

1 comment

reshown by
yes,true 36000100 is the answer.
1
1
1 vote
1 vote

Consider this Scenario : 

R (A,B) : 10000 rows ( showing Seperate Values Of A and B for a tuple/row)

A Tuples ( a1,a2,.......,a1001, (a1001,........ a1001) 8999 times ) B Tuples ( b1,b2,b3,.........,b10000 )

S (A,C) : 5000 rows ( showing Seperate Values Of A and C for a tuple/row)

A Tuples ( a1,a2,.......,a1001, (a1001,........ a1001) 3999 times ) C Tuples ( c1,c2,c3,.........,c5000 )

Now Making Join Of Both (Natural Join) ( For each tuple of R matching with Each tuple of S on basis of Common Column A)

For a1 : Match Found : 1 ; a2 : Match Found 1 ; ................ ; a1000 : Match Found 1 ; (Inidividual Match (A) :1000 )

For a1001 :

Match Found  : For R -> A ( row no 1001) : With S ->  A (row no 1001)

                         For R -> A ( row no 1001) : With S ->  A (row no 1002)

                         ... So 4000 matches for R -> A ( row no 1001 )  .... Similarly 4000 matches for R -> ( row no 1002)  ....

                         For Others : 8999 a1001's of relation R  -> Matches by Duplicate (B) :  9000 * 4000 = 36 * 10^6 

Total Matches  : (A) + (B) : 36000000 + 1000 = 36001000. (Answer)

P.S. : Here we are taking as many as duplicates in Relation R and S ; because we need to find maximum number of tuples. 

0 votes
0 votes
ans is 1001. am is crt

Related questions

2 votes
2 votes
1 answer
4