February 9, 2009 at 7:27 am
Bob Hovious (2/6/2009)
Give this a try at least. It runs faster with your test data.I use glue tables all the time too... but always in this format:
select blah
from tableA a
join glueAB glue on glue.acolumn = a.column
join tableB b on b.column = glue.bcolumn
Here's the revision.
----------------------------------------------------------------------------------------------
SELECT C.Citizenship_ID
FROM (select person_ID,iso_code
From data_xfer.citizen_xfer AS CX
JOIN data_xfer.ntm_iso_country_xref AS NICX ON CX.ctrycd = NICX.ntm_code
JOIN (SELECT ISNULL(data_xfer.person_xfer.person_no, dbo.Persons.ntmaa_person_no) AS personno, dbo.Persons.Person_ID
FROM data_xfer.person_xfer
RIGHT OUTER JOIN dbo.Persons ON data_xfer.person_xfer.primary_person_no = dbo.Persons.ntmaa_person_no
) AS P ON CX.personno = P.personno
) as newDT
JOIN dbo.Citizenships AS C ON newDT.Person_Id = C.Person_Id AND
newDT.iso_code = C.Country_Code
Tried it this morning and got the same odd query plan and performance.
Thanks for the effort.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
February 9, 2009 at 9:50 am
I appreciate your giving it a shot and giving me a reply, Jack.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
February 9, 2009 at 10:52 am
Garadin (2/8/2009)
Is it good practice then to add all criteria to the derived tables instead of the outer query? Guess that makes more sense overall anyways.
I hate to use the ol' cliche`, but "It depends"...
If the inner queries can do their thing correctly when you add row limiting criteria to them, then I'll do that in the inner queries for two reasons...
1. Makes troubleshooting easier
2. Main goal of any code to use/touch/return only the rows and columns needed.
Sounds obvious to a lot of folks, but many miss doing that.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 9, 2009 at 1:43 pm
Jeff Moden (2/9/2009)
Garadin (2/8/2009)
Is it good practice then to add all criteria to the derived tables instead of the outer query? Guess that makes more sense overall anyways.
I hate to use the ol' cliche`, but "It depends"...
If the inner queries can do their thing correctly when you add row limiting criteria to them, then I'll do that in the inner queries for two reasons...
1. Makes troubleshooting easier
2. Main goal of any code to use/touch/return only the rows and columns needed.
Sounds obvious to a lot of folks, but many miss doing that.
Yep. I think I used to always do this... and somewhere in the past couple months I'd started putting all the criteria into the outer query. I think this was a case where the easier something is to do, the less you think about it, and the less you think about it... BOOM.
February 16, 2009 at 11:25 am
I used to get burned on this in SQL 2000 and ever since I've always used the same WHERE clause in the glue table. Since then I've never had a problem.
I've always thought of the glue table more as a 'stub' table, but I guess 'glue' might be a better description.
Todd Fifield
Viewing 5 posts - 16 through 19 (of 19 total)
You must be logged in to reply to this topic. Login to reply