Outer Apply.

  • Hi,

    I am working in performance team. I need some help in improving query performance.

    In my query they wrote several left outer joins. I want to improve the performance by using outer apply which is similar to left outer join

    Suppose in left outer join

    select colm1,colum2

    from TableA A

    left outer join TableB B

    on A.colm1=B.col2.

    For this above query how to write by using outer apply.

    In this query, I don't have any functions but I want test the performance by changing into outer apply instead of left outer join.

  • Why? That's not the kind of query you'd use apply for. Apply isn't a magic performance enhancement.

    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
  • Have you looked at the execution plans to determine how the optimizer is resolving the existing queries. As Gail said, APPLY doesn't seem like the right tool here.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Look at the excecution plan and IO Results to check for any missing indexes and heavy CPU and memory joins,

    Changing joins will not impact the speed of query.

  • Bhaskar.Shetty (5/26/2014)


    Changing joins will not impact the speed of query.

    It can. Apply used inappropriately can cause massive performance degradation.

    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
  • It can. Apply used inappropriately can cause massive performance degradation.

    Oh... I messed it up... Yes you are right Apply will have a impact on performance.. Thaks for correcting me...

  • I thought compare to left outer join, outer Apply is better!

    Also when you are looking for performance improvement which one is important?

    I mean total elapsed time or CPU time. If we find total elapsed time is less and CPU time is higher after you did some modification to the code, shall we give that recommendation to the client?

    Which one we have to consider in query tuning CPU time or total elapsed time?

  • Apples and watermelons

    Joins are for when you want to relate two tables or subqueries. Apply is for when you want to run a function or subquery once for every row of the outer table.

    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 Gila.

    Please let me know,

    Which one we have to consider in query tuning CPU time or total elapsed time? If our modification raise one time and reduce another shall we consider that modification?

  • Please post unrelated questions in a new thread

    And forgive me if this sounds insulting, but do you do any research at all before asking here? If the answer to that is 'no', may I suggest that you acquaint yourself with a good search engine and do your own research on any topic that bothers you and ask here when you can't find the answer.

    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

Viewing 10 posts - 1 through 9 (of 9 total)

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