Can UNION ALL be faster than JOINs or do my JOINs just suck?

后端 未结 5 1038
旧时难觅i
旧时难觅i 2020-12-18 10:19

I have a Notes table with a uniqueidentifier column that I use as a FK for a variety of other tables in the database (don\'t worry, the uniqu

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 10:28

    I may be wrong, but I think that you will get a better performance if you rewrite you JOIN version to

    SELECT N.*  
    FROM Notes N  
    LEFT JOIN Leads L ON N.TargetUniqueID = L.UniqueID AND L.LeadID = @LeadID  
    LEFT JOIN Quotes Q ON N.TargetUniqueID = Q.UniqueID  AND Q.LeadID = @LeadID
    WHERE Q.LeadID IS NOT NULL OR L.LeadID IS NOT NULL
    

提交回复
热议问题