﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / SQL Server 2005 Performance Tuning  / Self referring join condition (tblx.col1 = tblx.col1) alters perf. - WHY? / 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, 21 May 2013 07:18:30 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Self referring join condition (tblx.col1 = tblx.col1) alters perf. - WHY?</title><link>http://www.sqlservercentral.com/Forums/Topic1356995-360-1.aspx</link><description>Ah, I hadn't thought about stats. I'll PM those guys cause this one has made me determined to solve it.Yes, there was a perf difference, I can't recall now. It wasn't huge, but big enough for me to notice.</description><pubDate>Tue, 25 Sep 2012 18:10:27 GMT</pubDate><dc:creator>Jason Selburg</dc:creator></item><item><title>RE: Self referring join condition (tblx.col1 = tblx.col1) alters perf. - WHY?</title><link>http://www.sqlservercentral.com/Forums/Topic1356995-360-1.aspx</link><description>[quote][b]Jason Selburg (9/10/2012)[/b][hr]Can someone explain [b]WHY[/b] adding the self referring join condition on acct.BillingType decreases the Estimated number of rows by a factor of [b]10[/b]? [/quote]Offhand... no.  The predicate exists on the object in one and not the other, and that's obviously affecting things, but it makes no particular difference.  It IS a NULL killer as mentioned above, but that's irrelevant to the results obviously.Return is 75656 in either case.  There's a VERY small handful of people I can think of offhand that might actually know where the extra row counts are coming from and what the optimizer is doing under the hood.  At a guess, it's using a different statistic set for estimation due to the connection (in any method) to that field as a restrictor and is getting a better value for the estimate, which might indicate it's time for an UPDATE STATISTICS WITH FULLSCAN on that table.Otherwise, if it's really that much of a concern since it's neither affecting the query plan nor did you mention significant runtime differences, I'd recommend you PM Paul White, Grant Fritchey, and Gail Shaw and ask them if they'd look in on this thread and can ask you the right questions to figure out the puzzle completely.  There might be one or two others who know the under the hood mechanics well enough kicking around but those three come to mind immediately to me for optimization plan gurus.</description><pubDate>Tue, 25 Sep 2012 17:52:05 GMT</pubDate><dc:creator>Evil Kraig F</dc:creator></item><item><title>RE: Self referring join condition (tblx.col1 = tblx.col1) alters perf. - WHY?</title><link>http://www.sqlservercentral.com/Forums/Topic1356995-360-1.aspx</link><description>I'm gonna try one more time to bump this and see if someone can find the answer. :hehe:</description><pubDate>Tue, 25 Sep 2012 17:35:15 GMT</pubDate><dc:creator>Jason Selburg</dc:creator></item><item><title>RE: Self referring join condition (tblx.col1 = tblx.col1) alters perf. - WHY?</title><link>http://www.sqlservercentral.com/Forums/Topic1356995-360-1.aspx</link><description>[b]BUMP[/b]Does anyone have an idea on this?</description><pubDate>Tue, 18 Sep 2012 10:22:05 GMT</pubDate><dc:creator>Jason Selburg</dc:creator></item><item><title>RE: Self referring join condition (tblx.col1 = tblx.col1) alters perf. - WHY?</title><link>http://www.sqlservercentral.com/Forums/Topic1356995-360-1.aspx</link><description>[quote][b]Matt Miller (#4) (9/11/2012)[/b][hr]Just a shot in the dark, but - how many have a NULL billingType?[/quote]Zero, it's a NOT NULL column and the results are identical. [EDIT] And by [b]results [/b]I mean the results of the two queries[/EDIT]</description><pubDate>Tue, 11 Sep 2012 13:43:54 GMT</pubDate><dc:creator>Jason Selburg</dc:creator></item><item><title>RE: Self referring join condition (tblx.col1 = tblx.col1) alters perf. - WHY?</title><link>http://www.sqlservercentral.com/Forums/Topic1356995-360-1.aspx</link><description>Just a shot in the dark, but - how many have a NULL billingType?</description><pubDate>Tue, 11 Sep 2012 13:13:12 GMT</pubDate><dc:creator>Matt Miller (#4)</dc:creator></item><item><title>Self referring join condition (tblx.col1 = tblx.col1) alters perf. - WHY?</title><link>http://www.sqlservercentral.com/Forums/Topic1356995-360-1.aspx</link><description>Can someone explain [b]WHY[/b] adding the self referring join condition on acct.BillingType decreases the Estimated number of rows by a factor of [b]10[/b]? [b]Notes:[/b]-- #HindsightFacilityList table has one row with four integers in it and no indexes.-- factARSnapshot [u](30 million rows/4 GB Data size)[/u] DDL Attached-- dimAccount [u](5 million rows/1.5 GB)[/u] DDL AttachedBoth queries are correctly using the ix_dimAccount index?![code]---- Qry3_With_Self_JoinSELECT 	atb.AccountID	,atb.FacilityID	,atb.DischargeAgingID		,atb.FinancialClassID	,atb.InsuranceProviderID	,LEFT(acct.BillingType,1)	,atb.AccountBalanceFROM #HindsightFacilityList FacList					INNER JOIN Analysis.factARSnapshot AS atb		ON facList.AccountFacilityID = atb.FacilityID 		AND atb.PeriodID=@pm_PeriodID 	INNER JOIN Analysis.dimAccount AS acct		ON acct.AccountID = atb.AccountID		AND acct.BillingType = acct.BillingType		---- Qry4_WithOUT_Self_Join		SELECT 	atb.AccountID	,atb.FacilityID	,atb.DischargeAgingID		,atb.FinancialClassID	,atb.InsuranceProviderID	,LEFT(acct.BillingType,1)	,atb.AccountBalanceFROM #HindsightFacilityList FacList					INNER JOIN Analysis.factARSnapshot AS atb		ON facList.AccountFacilityID = atb.FacilityID 		AND atb.PeriodID=@pm_PeriodID 	INNER JOIN Analysis.dimAccount AS acct		ON acct.AccountID = atb.AccountID		---AND acct.BillingType = acct.BillingType[/code]** Execution plan attached</description><pubDate>Mon, 10 Sep 2012 13:57:35 GMT</pubDate><dc:creator>Jason Selburg</dc:creator></item></channel></rss>