Professional Documents
Culture Documents
Let r and s are two relations. Let they are subjected to join
operation as represented by:
r r.A=s.B s,
where A and B are set of attributes or sets of attributes of
relations r and s.
Now the join operation between relations can achieved by
the following several techniques:
• Nested-Loop join .
• Block Nested–Loop join .
• Indexed Nested-Loop join.
• Merge join.
• Hash join.
Figure 1.
From the above figure , we see that :
Relation
elation r is called the outer relation and relation s is
called the inner relation of the join.
ts and tr are tuples, tr . ts denote tuple constructed by
concatenating the attribute values of the tuples.
Figure 2.
br( tT + tS ) + nr * c
where,
nr is the number of records in relation r.
c is the cost of a single section.
br denotes the number of blocks containing
records of r.
This cost formula indicates that it is generally the most
efficient way to use the one with fewer tuples as the outer
relation , if indices are available on both relations r and s.
Merge join:-
Hash Join :
/* partition s */
For each tuple ts in s do
Begin
i:=h(ts [j]);
[j]);
Hsi:= Hsi {ts } ;
End
/*partition r*/
For each tuple tr in r do
Begin
i:=h( tr [j]);
H r := H r { tr } ;
i i
End
/*perform join on each partition */
For i:= 0 to n do
h
Begin
Read H s and build an in-memory hash index on it.
i
Begin
Probe the hash index on H s to locate all tuples t
i s
Begin
add tr t to the result
s
end
end
end