IN or OR

  • I was under the impression that an 'IN' would be faster than an 'OR' statement, but I just did some timetesting and found the OR statement ran just a little bit faster.

     

    Start 2006-05-12 09:47:22.773

    --AND (lead_status_id = 3 OR lead_status_id = 4)

    Finish  2006-05-12 09:47:24.680 1.907 TOTAL seconds

    -------------------------------------------

    Start 2006-05-12 09:51:21.230

    and lead_status_id in (3,4)

     Finish 2006-05-12 09:51:23.153 -1.923 TOTAL seconds

  • if the IN statement was running accross a bigger list, like  in(SELECT X FROM SOME TABLE),

    I would expect it should be faster, because it would bailout as true on the first occurance of where the result was true,

    the equivilent OR would probably result in a table scan;

    when comparing just two values, I'm not surprised the OR is a bit faster.

    They are really close timewise, i bet if you repeated ti several times, the results might be even closer.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks for your help once again Lowell!!

  • Both are bad.

    Put your values into temp table and join it to the tables from your query.

    _____________
    Code for TallyGenerator

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

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