What is Merge Join Transformation?
You may have gone through this question a lot of time while working that what is the thumb rule to use Look Up transformation or Merge Transformation. Lets have a simple rule for that:
While using Lookup component, thumb rule is to make sure that the largest table i.e. a fact table gets streamed into the component and the smallest table i.e dimension table gets cached. The reason behind this is that the table that gets cached will block the flow while it is loaded into the memory, so it is good to have it as small as possible.
So, if the table to be cached in memory is large, use the MERGE Join component. But there are few pre-requisites that one must follow while working on the Merge Join:
- It requires the inputs to be sorted in the same way.
- We need to set ISSORETD property TRUE in advanced editor of input source component.
- But till now, we have told the component that the data is sorted but in which order? Under Input/Output properties of source component, we need to check the value of SortKeyPosition for the particular columns that are used for sort. If the column is not sorted then vale of SortKeyPosition must be 0. If the sorting is in ascending order, the value should be positive and if it is in descending order then it should be in negative.
For example, lets take a query:
select empID, empName, EmpDepttID from employees order by empid , empName
for this, value of my SortkeyPosition would be
Merge Join transformation, gives us the option to use Inner Join, Left Outer Join and Full Outer Join.
Looking at the above figure, one must wonder, where is the option to use Right outer join. On Join Type combo, select Left outer join, this will activate Swap Inputs button, which allows you to use right outer join by just placing your join table on left. Something I liked :)
About the Author: Girish Khullar, writes about SQL Server, Integration Services and Business Intelligence. He is Microsoft Certified Professional.