Left Join Perfomance

  • Quick one..

    Which generally performs best.

    Left join BIG TABLE to Smaller table

    or

    Left Join Smaller Table to BIG TABLE

    I would guess Left join BIG TABLE to Smaller table

  • To be honest, performance is irrelevant in this case.

    If you need all the rows from a large table and matching rows from a small table, then LargeTable LEFT OUTER JOIN SmallTable

    If you need all the rows from a small table and matching rows from a large table, then SmallTable LEFT OUTER JOIN LargeTable

    They produce different results (assuming that there are non-matching rows, if there aren't use INNER JOIN) and hence cannot be switched one to the other for performance reasons (unless the users like getting incorrect results fast)

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks

    What I will be questioning is if the LEft joins in the code are actually valid or simply a lack of understanding of which joins to use.

    I can see some code with excessive left joins amongst many other things.

    Correct to assume if you want to find where there is no match IF NOT EXIST will perform quicker.

  • WHERE EXISTS, not IF NOT EXISTS

    Very, very, very slightly more efficient.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks,

    Saved me a lot of time googling.

  • There's 5 posts on my blog on the subject if you want the full detail.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I'll take a look now.

    Thanks

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply