SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Self referring join condition (tblx.col1 = tblx.col1) alters perf. - WHY?


Self referring join condition (tblx.col1 = tblx.col1) alters perf. - WHY?

Author
Message
Jason Selburg
Jason Selburg
SSCertifiable
SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)

Group: General Forum Members
Points: 6782 Visits: 4115
Can someone explain WHY adding the self referring join condition on acct.BillingType decreases the Estimated number of rows by a factor of 10?

Notes:

-- #HindsightFacilityList table has one row with four integers in it and no indexes.

-- factARSnapshot (30 million rows/4 GB Data size) DDL Attached

-- dimAccount (5 million rows/1.5 GB) DDL Attached

Both queries are correctly using the ix_dimAccount index?!


---- Qry3_With_Self_Join
SELECT
atb.AccountID
,atb.FacilityID
,atb.DischargeAgingID
,atb.FinancialClassID
,atb.InsuranceProviderID
,LEFT(acct.BillingType,1)
,atb.AccountBalance
FROM #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.AccountBalance
FROM #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



** Execution plan attached

______________________________________________________________________

Personal Motto: Why push the envelope when you can just open it?

If you follow the direction given HERE you'll likely increase the number and quality of responses you get to your question.

Jason L. Selburg
Attachments
ExPlan_Self_Join.sqlplan (33 views, 152.00 KB)
DDL.zip (8 views, 3.00 KB)
Matt Miller (4)
Matt Miller (4)
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28683 Visits: 19002
Just a shot in the dark, but - how many have a NULL billingType?

----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Jason Selburg
Jason Selburg
SSCertifiable
SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)

Group: General Forum Members
Points: 6782 Visits: 4115
Matt Miller (#4) (9/11/2012)
Just a shot in the dark, but - how many have a NULL billingType?


Zero, it's a NOT NULL column and the results are identical. [EDIT] And by results I mean the results of the two queries[/EDIT]

______________________________________________________________________

Personal Motto: Why push the envelope when you can just open it?

If you follow the direction given HERE you'll likely increase the number and quality of responses you get to your question.

Jason L. Selburg
Jason Selburg
Jason Selburg
SSCertifiable
SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)

Group: General Forum Members
Points: 6782 Visits: 4115
BUMP

Does anyone have an idea on this?

______________________________________________________________________

Personal Motto: Why push the envelope when you can just open it?

If you follow the direction given HERE you'll likely increase the number and quality of responses you get to your question.

Jason L. Selburg
Jason Selburg
Jason Selburg
SSCertifiable
SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)

Group: General Forum Members
Points: 6782 Visits: 4115
I'm gonna try one more time to bump this and see if someone can find the answer. Hehe

______________________________________________________________________

Personal Motto: Why push the envelope when you can just open it?

If you follow the direction given HERE you'll likely increase the number and quality of responses you get to your question.

Jason L. Selburg
Evil Kraig F
Evil Kraig F
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19993 Visits: 7660
Jason Selburg (9/10/2012)
Can someone explain WHY adding the self referring join condition on acct.BillingType decreases the Estimated number of rows by a factor of 10?


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.


- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Jason Selburg
Jason Selburg
SSCertifiable
SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)

Group: General Forum Members
Points: 6782 Visits: 4115
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.

______________________________________________________________________

Personal Motto: Why push the envelope when you can just open it?

If you follow the direction given HERE you'll likely increase the number and quality of responses you get to your question.

Jason L. Selburg
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search