﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Jason Brimhall  / Join Operations – Nested Loops / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 18 Jun 2013 21:57:53 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>[quote][b]Mark-101232 (2/1/2013)[/b][hr]Interesting stuff, thanks![/quote]You're welcome.</description><pubDate>Mon, 04 Feb 2013 08:12:08 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>Hi there.I appreciate you taking the time to go in detail regarding the hows and whys of optimization in this scenario. While i cannot attest to your example at the moment, i will try in the future. Thanks!</description><pubDate>Sat, 02 Feb 2013 20:31:02 GMT</pubDate><dc:creator>nopeqwerty</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>Interesting stuff, thanks!</description><pubDate>Fri, 01 Feb 2013 08:44:16 GMT</pubDate><dc:creator>Mark-101232</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>[quote][b]Bharat Panthee (1/8/2011)[/b][hr]Very nice article, Thanks ![/quote]Thank you Bharat.</description><pubDate>Mon, 10 Jan 2011 07:19:16 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>Very nice article, Thanks !</description><pubDate>Sat, 08 Jan 2011 22:39:33 GMT</pubDate><dc:creator>Bharat Panthee</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>[quote][b]Lempster (1/7/2011)[/b][hr]Jason, thanks for the article. Just one point: after forcing the optimizer to use a Nested Loop you state, [quote]By trying to force the optimizer to use a Nested Loops where the query didn't really warrant it, we did not improve the query and it could be argued that we caused more work to be performed.[/quote]Yet you've improved the query time (compared to when no query hint was used) by nearly 50%. Of course the logical reads have gone through the roof and that may or may not be a problem depending on the amount of memory and CPU on the box in question, but if it's just query execution time you're interested in, I would argue that you have improved it.I definitley agree that in the vast majority of cases one should leave the optimizer to pick the 'best' plan (we should really say 'optimal' as it may take way too long to actually find the 'best' plan) and use query hints with extreme caution.ThanksLempster[/quote]Good points.  It was due to the increased logical reads that one may argue that more work is being done.  But yes, based on execution time, you are correct.Thanks for the comments.</description><pubDate>Fri, 07 Jan 2011 08:21:13 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>Excellent article Jason.  Well done, it explains clearly and concisely how best to use the nested loop, and when it should be used.Nic</description><pubDate>Fri, 07 Jan 2011 06:45:34 GMT</pubDate><dc:creator>Nic-306421</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>Jason, thanks for the article. Just one point: after forcing the optimizer to use a Nested Loop you state, [quote]By trying to force the optimizer to use a Nested Loops where the query didn't really warrant it, we did not improve the query and it could be argued that we caused more work to be performed.[/quote]Yet you've improved the query time (compared to when no query hint was used) by nearly 50%. Of course the logical reads have gone through the roof and that may or may not be a problem depending on the amount of memory and CPU on the box in question, but if it's just query execution time you're interested in, I would argue that you have improved it.I definitley agree that in the vast majority of cases one should leave the optimizer to pick the 'best' plan (we should really say 'optimal' as it may take way too long to actually find the 'best' plan) and use query hints with extreme caution.ThanksLempster</description><pubDate>Fri, 07 Jan 2011 04:57:30 GMT</pubDate><dc:creator>Lempster</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>[quote][b]Solomon Rutzky (1/4/2011)[/b][hr][quote][b]CirquedeSQLeil (1/4/2011)[/b][hr]True it is a bit unfair to illustrate it that way (I alluded to that unfairness as well).  An important part of that comparison is to show how the query optimizer changes the join operator when fewer records are required.  Since an indexed nested loops works better with fewer records, the optimizer will choose that.  That was really the main point.[/quote]Got it.  Thanks.[/quote]You're welcome.My apologies if it was misleading.</description><pubDate>Tue, 04 Jan 2011 14:18:13 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>[quote][b]CirquedeSQLeil (1/4/2011)[/b][hr]True it is a bit unfair to illustrate it that way (I alluded to that unfairness as well).  An important part of that comparison is to show how the query optimizer changes the join operator when fewer records are required.  Since an indexed nested loops works better with fewer records, the optimizer will choose that.  That was really the main point.[/quote]Got it.  Thanks.</description><pubDate>Tue, 04 Jan 2011 14:11:18 GMT</pubDate><dc:creator>Solomon Rutzky</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>[quote][b]Solomon Rutzky (1/4/2011)[/b][hr]Hey Jason.  Nice article and one question.  In your two main examples the difference is the WHERE condition that constrains the results to 10 rows as opposed to the full 10,000 in the table.  Is it fair to compare the query times (and make implications on the differences of the JOIN types) given that they are different queries?  One is asked to get 10 rows and the other query gets all 10,000 so naturally they would not take the same amount of time, right?  Maybe that is not the point you were trying to get across to begin with, but my initial thought as to the speed increase wasn't that it was due to the different JOIN type but instead to only pulling 10 rows.  I wonder if there is a way to show two queries that pull the same amount of rows but are written differently so as to force the different JOIN types (Merge vs Nested Loop).Thanks and take care,Solomon...[/quote]True it is a bit unfair to illustrate it that way (I alluded to that unfairness as well).  An important part of that comparison is to show how the query optimizer changes the join operator when fewer records are required.  Since an indexed nested loops works better with fewer records, the optimizer will choose that.  That was really the main point.</description><pubDate>Tue, 04 Jan 2011 14:06:12 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>Hey Jason.  Nice article and one question.  In your two main examples the difference is the WHERE condition that constrains the results to 10 rows as opposed to the full 10,000 in the table.  Is it fair to compare the query times (and make implications on the differences of the JOIN types) given that they are different queries?  One is asked to get 10 rows and the other query gets all 10,000 so naturally they would not take the same amount of time, right?  Maybe that is not the point you were trying to get across to begin with, but my initial thought as to the speed increase wasn't that it was due to the different JOIN type but instead to only pulling 10 rows.  I wonder if there is a way to show two queries that pull the same amount of rows but are written differently so as to force the different JOIN types (Merge vs Nested Loop).Thanks and take care,Solomon...</description><pubDate>Tue, 04 Jan 2011 13:50:27 GMT</pubDate><dc:creator>Solomon Rutzky</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>[quote][b]mtillman-921105 (1/4/2011)[/b][hr]'Makes perfect sense Jason, thanks again.- Mark[/quote]You're welcome.</description><pubDate>Tue, 04 Jan 2011 10:27:38 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>'Makes perfect sense Jason, thanks again.- Mark</description><pubDate>Tue, 04 Jan 2011 10:25:41 GMT</pubDate><dc:creator>mtillman-921105</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>[quote][b]mtillman-921105 (1/4/2011)[/b][hr]Well thought-out and illustrated Jason, thanks! :cool:So should we always check queries returning just a few rows to see if a forced Nested Loop would help?  [/quote]I would say proceed very cautiously.  The DB Engine does an excellent job of determining which join operation to use.  I would certainly say to verify indexes first and then check your query.  If after that, you still see a performance issue - go ahead and try the hint but be careful about it.</description><pubDate>Tue, 04 Jan 2011 10:11:03 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>Well thought-out and illustrated Jason, thanks! :cool:So should we always check queries returning just a few rows to see if a forced Nested Loop would help?  </description><pubDate>Tue, 04 Jan 2011 10:01:26 GMT</pubDate><dc:creator>mtillman-921105</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>Thanks Wayne, Steve and zlthomps.</description><pubDate>Tue, 04 Jan 2011 08:38:09 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>Nice job, Jason. Good explanation, and looking forward to reading about the other join types.</description><pubDate>Tue, 04 Jan 2011 08:20:10 GMT</pubDate><dc:creator>Steve Jones - SSC Editor</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>Thanks for the article, very good read.</description><pubDate>Tue, 04 Jan 2011 07:13:32 GMT</pubDate><dc:creator>zlthomps</dc:creator></item><item><title>RE: Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>Good, thorough article Jason. Thanks!</description><pubDate>Tue, 04 Jan 2011 01:27:39 GMT</pubDate><dc:creator>WayneS</dc:creator></item><item><title>Join Operations – Nested Loops</title><link>http://www.sqlservercentral.com/Forums/Topic1042172-2650-1.aspx</link><description>Comments posted to this topic are about the item [B][url=http://www.sqlservercentral.com/articles/JOIN/71733/]Join Operations – Nested Loops[/url][/B]Thanks to those who helped review this for me.  Their suggestions and insight were very helpfulGail ShawWayne SheffieldChris Morris</description><pubDate>Mon, 03 Jan 2011 23:25:23 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item></channel></rss>