When is the inner query of the exists statment ran?

  • Is the inner query of the exists statement ran for each outer query check? Or is it done before? My inner query is joining to tables from the outer query, so it seems to me that the inner query would be running concurrently - but I really don't know for sure and my results don't indicate that it is.

    I have several scripts in my stored procedure that either update or insert to a specific table. The results are not what I'm expecting and appear to work better when I have pseudo cursors around each script (although still not working quite right). However, the performance is terrible and takes twice as long for my stored procedure to run.

    I appreciate any assistance someone can give me.

  • It's done as part of the query. How depends on what kind of plan the optimiser comes up with. For an EXISTS, it can usually turn that into a semi-join and process it much the same way as a normal join.

    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 for your quick response!

Viewing 3 posts - 1 through 2 (of 2 total)

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