Performance Issue w/ IF Exists

  • Hi,

    We are encountering an issue while querying a very large table.

    While working in QA,

    if we just do a select * ... it comes back in about 1 second.

    if we so an if exists(select *...) it takes around 10 seconds.

     

    I thought if exists was supposed to be the fastest way??

    Anyone ese experience this issue?

     

    Thanks

     

  • Can you post the queries you are using in context?



    Once you understand the BITs, all the pieces come together

  • I have had this problem before when dealing with a trigger and the virtual inserted/deleted tables.

    What I had to do was change the if exists(select * ...) to if (select count(*) ...) > 0

    I thought that the if exists() should be faster as well, and it is in most cases (for me anyway).  But for this situation, it was out for the count(*). 

    Jarret

  • I might be flamed again , but I think EXISTS will almost always be faster than using COUNT(*).

    But as Thomas already said, without having the query code and, maybe the table structure any advise will be like a shot in the dark.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Thank you for the posts,

     

    We did our own testing and optimizing and found the same thing, using a count was 6Xs faster than the If Exists().  I had always thought I learned that If Exists was always the way to go...

    It was happening on a large table with about .75 mill records.

     

Viewing 5 posts - 1 through 5 (of 5 total)

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