Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

To retrieve data joining techniques is applied according to situation.

There
are three joining techniques.

• Nested loop join


• Sort merge join
• Hash join

Nested Loop Join:

✔ High selective query mean less queries or no of rows returned is


less than 1%.
✔ Low selective mean more queries or no of rows returned is more
than 1%.

Best case:

When the outer table qualifying rows are less than the dinner table rows.

(Qualifying rows mean that comes after the result)

Worst Case:

When the outer table rows are more than the inner table rows.

Whose qualifying rows are small are considered as small table.

Sort-Merge Table:

Two operations are done

✔ Sort operation
✔ Merge operation

Best case:

If u has two tables and both are pre-sorted and fit in memory. The cost u
has to calculate is only merge cost.

Worst case:

If u has two tables and both are not pre-sorted and not fit in memory. The
cost u has to calculate is sorting cost + merge cost.

Examples:

If u have available memory k=150kb, one table R=100kb and other table
S=50kb.the tables are not sorted,then calculate i/o cost?

Sorting cost=r+s=100+50=300kb
Merge cost= r+ s=100+50=300kb

✔ If u have available memory k=25kb, one table R=100kb and other


table S=50kb.the tables are not sorted,then calculate i/o cost?

In this case the available memory is small and table size is large so we do
sort ,partition and merge.

(R*log(r/k)+(S*log(s/k))+(r+s)

(100*log(100/25))+(50*log(50/25))+(R+S)=

Note:100/25 is portioning cost.4 partitions is created so easily fits in


memory.

Hash joins:

No sorting is required

Best case:

Tables easily fits in the memory.

Worst case:

Tables cant fits in the memory.

Examples:

If u have available memory k=150kb, one table R=100kb and other table
S=50kb.calculate i/o cost=?

Merge cost= r+ s=100+50=300kb

Only merge cost is added because no sorting is required in hash.

If u have available memory k=25kb, one table R=100kb and other table
S=50kb.the tables are not sorted, then calculate i/o cost?

In this case the available memory is small and table size is large so we do
partition and merge.

(R*log(s/k)+(S*log(s/k))+(r+s)

(100*log(50/25))+(50*log(50/25))+(100+50)=

Note:50/25 is portioning cost.4 partitions is created so easily fits in


memory.

You might also like