<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'SSIS', 'sql server integration services', and 'IsSorted'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=SSIS,sql+server+integration+services,IsSorted&amp;orTags=0</link><description>Search results matching tags 'SSIS', 'sql server integration services', and 'IsSorted'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Merge Join component sorted outputs [SSIS]</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2011/01/31/merge-join-component-sorted-outputs-ssis.aspx</link><pubDate>Mon, 31 Jan 2011 19:40:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:33070</guid><dc:creator>jamiet</dc:creator><description>&lt;P&gt;One question that I have been asked a few times of late in regard to performance tuning SSIS data flows is this:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;Why isn’t the Merge Join output sorted (i.e.IsSorted=True)?&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is a fair question. After all both of the Merge Join inputs are sorted, hence why wouldn’t the output be sorted as well? Well here’s a little secret, the Merge Join output IS sorted! There’s a caveat though – it is only under certain circumstances and SSIS itself doesn’t do a good job of informing you of it.&lt;/P&gt;
&lt;P&gt;Let’s take a look at an example. Here we have a dataflow that consumes data from the [AdventureWorks2008].[Sales].[SalesOrderHeader] &amp;amp; [AdventureWorks2008].[Sales].[SalesOrderDetail] tables then joins them using a Merge Join component:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/image_7C25788A.png"&gt;&lt;IMG style="BACKGROUND-IMAGE:none;BORDER-BOTTOM:0px;BORDER-LEFT:0px;MARGIN:;PADDING-LEFT:0px;PADDING-RIGHT:0px;DISPLAY:inline;BORDER-TOP:0px;BORDER-RIGHT:0px;PADDING-TOP:0px;" title=image border=0 alt=image src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_7210D75F.png" width=628 height=256&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Let’s take a look inside the editor of the Merge Join:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/image_29E31B83.png"&gt;&lt;IMG style="BACKGROUND-IMAGE:none;BORDER-BOTTOM:0px;BORDER-LEFT:0px;MARGIN:;PADDING-LEFT:0px;PADDING-RIGHT:0px;DISPLAY:inline;BORDER-TOP:0px;BORDER-RIGHT:0px;PADDING-TOP:0px;" title=image border=0 alt=image src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_06D2AA13.png" width=705 height=705&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;We are joining on the [SalesOrderId] field (which is what the two inputs just happen to be sorted upon). We are also putting [SalesOrderHeader].[SalesOrderId] into the output. Believe it or not the output from this Merge Join component is sorted (i.e. has IsSorted=True) but unfortunately the Merge Join component does not have an Advanced Editor hence it is hidden away from us. There are a couple of ways to prove to you that is the case; I could open up the package XML inside the .dtsx file and show you the metadata but there is an easier way than that – I can attach a Sort component to the output. Take a look:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/jamie_thomson/image_7200B192.png"&gt;&lt;IMG style="BACKGROUND-IMAGE:none;BORDER-BOTTOM:0px;BORDER-LEFT:0px;MARGIN:;PADDING-LEFT:0px;PADDING-RIGHT:0px;DISPLAY:inline;BORDER-TOP:0px;BORDER-RIGHT:0px;PADDING-TOP:0px;" title=image border=0 alt=image src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_288E5CD7.png" width=998 height=435&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Notice that the Sort component is attempting to sort on the [SalesOrderId] column. This gives us the following warning:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;Validation warning. DFT Get raw data: {992B7C9A-35AD-47B9-A0B0-637F7DDF93EB}: The data is already sorted as specified so the transform can be removed.&lt;/EM&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The warning proves that the output from the Merge Join is sorted!&lt;/P&gt;
&lt;P&gt;It must be noted that the Merge Join output will only have IsSorted=True if at least one of the join columns is included in the output.&lt;/P&gt;
&lt;P&gt;So there you go, the Merge Join component can indeed produce a sorted output and that’s very useful in order to avoid unnecessary expensive Sort operations downstream. Hope this is useful to someone out there!&lt;/P&gt;
&lt;P&gt;&lt;A href="http://twitter.com/jamiet"&gt;@Jamiet&lt;/A&gt;&amp;nbsp; &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;P.S. Thank you to Bob Bojanic on the SSIS product team who pointed this out to me!&lt;/P&gt;</description></item></channel></rss>