Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2004
    Posts
    91

    Unanswered: speed tests (in vs. specified)

    Hi Everyone -

    We were discussing select speeds the other day,
    the question comes in at...

    what is faster, a standard query with specifies the search critera
    i.e. select * from xyz where a='A' or a='B'
    or is the IN a better way to go....

    select * from xyz where a in ('A', 'B')

    we ran the tests in performance analyzer,
    but they were the same results....

    maybe i'm smoking the stuff - but i thought the
    useage of the IN causes a full table scan for each
    of the items in the in clause

    please advise

    take care
    tony

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    you were smoking the stuff and you need to share.

    the query processor is smarter than that. there is no difference between IN and a list of Or's except IN is a little more readable IMO.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Dec 2002
    Posts
    1,245
    Quote Originally Posted by Thrasymachus
    you were smoking the stuff and you need to share.

    the query processor is smarter than that. there is no difference between IN and a list of Or's except IN is a little more readable IMO.
    He wasn't smoking the same stuff as one of my developers. My developer thought it would be a lovely idea to cursor through (on the client side in java) a recordset building one-by-one the values for his IN statement. He thought this would be more efficient that passing the SELECT statement used to build the recordset.

    It worked when there were only a few hundred records in the database. It got a little ugly when he tried to build an IN statement with 9,000+ values.

    Ugh.

    hmscott
    Have you hugged your backup today?

  4. #4
    Join Date
    Oct 2004
    Posts
    91
    wowzers

    another red letter day....

    thanks for the infor

    take care
    tony

  5. #5
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Or you could load the values o a table and join to it

    http://weblogs.sqlteam.com/brettk/ar...5/05/1312.aspx
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •