Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Performance question

Performance question

Scheduled Pinned Locked Moved Database
questionperformancehelptutorial
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Johnny J
    wrote on last edited by
    #1

    Does anybody know if there is a performance difference between these two example queries:

    SELECT * FROM tblFox WHERE stringFieldValue IN ('Ring-ding-ding-ding-dingeringeding!', 'Wa-pa-pa-pa-pa-pa-pow!')

    SELECT * FROM tblFox WHERE stringFieldValue='Ring-ding-ding-ding-dingeringeding!' OR stringFieldValue= 'Wa-pa-pa-pa-pa-pa-pow!'

    ???? I would Google it if I knew what to enter to get a relevant answer... :sigh:

    Anything that is unrelated to elephants is irrelephant
    Anonymous
    -----
    The problem with quotes on the internet is that you can never tell if they're genuine
    Winston Churchill, 1944
    -----
    I'd just like a chance to prove that money can't make me happy.
    Me, all the time

    T J T D 4 Replies Last reply
    0
    • J Johnny J

      Does anybody know if there is a performance difference between these two example queries:

      SELECT * FROM tblFox WHERE stringFieldValue IN ('Ring-ding-ding-ding-dingeringeding!', 'Wa-pa-pa-pa-pa-pa-pow!')

      SELECT * FROM tblFox WHERE stringFieldValue='Ring-ding-ding-ding-dingeringeding!' OR stringFieldValue= 'Wa-pa-pa-pa-pa-pa-pow!'

      ???? I would Google it if I knew what to enter to get a relevant answer... :sigh:

      Anything that is unrelated to elephants is irrelephant
      Anonymous
      -----
      The problem with quotes on the internet is that you can never tell if they're genuine
      Winston Churchill, 1944
      -----
      I'd just like a chance to prove that money can't make me happy.
      Me, all the time

      T Offline
      T Offline
      tsunamigang
      wrote on last edited by
      #2

      I did not know exactly that there is performance difference. But query using IN will reduce your typing and looks good. If there are few more data to search in OR condition, You type field name again and again??

      1 Reply Last reply
      0
      • J Johnny J

        Does anybody know if there is a performance difference between these two example queries:

        SELECT * FROM tblFox WHERE stringFieldValue IN ('Ring-ding-ding-ding-dingeringeding!', 'Wa-pa-pa-pa-pa-pa-pow!')

        SELECT * FROM tblFox WHERE stringFieldValue='Ring-ding-ding-ding-dingeringeding!' OR stringFieldValue= 'Wa-pa-pa-pa-pa-pa-pow!'

        ???? I would Google it if I knew what to enter to get a relevant answer... :sigh:

        Anything that is unrelated to elephants is irrelephant
        Anonymous
        -----
        The problem with quotes on the internet is that you can never tell if they're genuine
        Winston Churchill, 1944
        -----
        I'd just like a chance to prove that money can't make me happy.
        Me, all the time

        J Offline
        J Offline
        Jorgen Andersson
        wrote on last edited by
        #3

        Depends on what database you're using and what indexes you have in place, but normally the query optimizer would realize that they are the same thing.

        Politicians are always realistically manoeuvering for the next election. They are obsolete as fundamental problem-solvers. Buckminster Fuller

        1 Reply Last reply
        0
        • J Johnny J

          Does anybody know if there is a performance difference between these two example queries:

          SELECT * FROM tblFox WHERE stringFieldValue IN ('Ring-ding-ding-ding-dingeringeding!', 'Wa-pa-pa-pa-pa-pa-pow!')

          SELECT * FROM tblFox WHERE stringFieldValue='Ring-ding-ding-ding-dingeringeding!' OR stringFieldValue= 'Wa-pa-pa-pa-pa-pa-pow!'

          ???? I would Google it if I knew what to enter to get a relevant answer... :sigh:

          Anything that is unrelated to elephants is irrelephant
          Anonymous
          -----
          The problem with quotes on the internet is that you can never tell if they're genuine
          Winston Churchill, 1944
          -----
          I'd just like a chance to prove that money can't make me happy.
          Me, all the time

          T Offline
          T Offline
          thatraja
          wrote on last edited by
          #4

          Johnny J. wrote:

          Does anybody know if there is a performance difference between these two example queries:

          Not so much difference I think. But I prefer IN instead of OR in this case. Using IN you could write cleaner query. What would you do if there're 10+ OR conditions in your query?

          Johnny J. wrote:

          I would Google it if I knew what to enter to get a relevant answer... :sigh:

          I tried http://www.google.com/search?q=SQL+IN+vs+OR[^] & got this one SQL Speed Test: IN vs OR[^]

          thatraja

          Code converters | Education Needed No thanks, I am all stocked up. - Luc Pattyn When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute

          1 Reply Last reply
          0
          • J Johnny J

            Does anybody know if there is a performance difference between these two example queries:

            SELECT * FROM tblFox WHERE stringFieldValue IN ('Ring-ding-ding-ding-dingeringeding!', 'Wa-pa-pa-pa-pa-pa-pow!')

            SELECT * FROM tblFox WHERE stringFieldValue='Ring-ding-ding-ding-dingeringeding!' OR stringFieldValue= 'Wa-pa-pa-pa-pa-pa-pow!'

            ???? I would Google it if I knew what to enter to get a relevant answer... :sigh:

            Anything that is unrelated to elephants is irrelephant
            Anonymous
            -----
            The problem with quotes on the internet is that you can never tell if they're genuine
            Winston Churchill, 1944
            -----
            I'd just like a chance to prove that money can't make me happy.
            Me, all the time

            D Offline
            D Offline
            David Mujica
            wrote on last edited by
            #5

            If you are using SQL Server, you could use "Show Execution Plan" and see if there is a difference. If you are using Oracle, I believe there is a 1000 element limit to the "IN" clause. At a previous company I worked for we got bit by this. (This was a while ago, maybe Oracle 9, it may not be an issue now)

            J 1 Reply Last reply
            0
            • D David Mujica

              If you are using SQL Server, you could use "Show Execution Plan" and see if there is a difference. If you are using Oracle, I believe there is a 1000 element limit to the "IN" clause. At a previous company I worked for we got bit by this. (This was a while ago, maybe Oracle 9, it may not be an issue now)

              J Offline
              J Offline
              Jorgen Andersson
              wrote on last edited by
              #6

              Oracle still has this limit (in older versions it was 256 elements) The purpose with the limit is that parsing the query is quite resource demanding and if you're having more than 1000 elements in an in statement they're claiming that you're doing something wrong anyway. Use an array instead.

              Politicians are always realistically manoeuvering for the next election. They are obsolete as fundamental problem-solvers. Buckminster Fuller

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups