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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Is this query bad.....?

Is this query bad.....?

Scheduled Pinned Locked Moved Database
questiondatabaseperformancecode-review
5 Posts 4 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.
  • H Offline
    H Offline
    Hum Dum
    wrote on last edited by
    #1

    Select Min(Priority) from Outbox where [Transmitted] = false and [FolderId] IN (7,8) and
    [Deleted] = false and [InterfaceNo] =@InterfaceNo and [SwitchingAddressNo] NOT IN
    (Select [SwitchingAddressNo] from AddressBook where [Block] = true and [Deleted] = false

    The above query i wrote, and its working fine. I want to know the performance related issues with this? If its ugly? then how can i improve the same.

    P D 2 Replies Last reply
    0
    • H Hum Dum

      Select Min(Priority) from Outbox where [Transmitted] = false and [FolderId] IN (7,8) and
      [Deleted] = false and [InterfaceNo] =@InterfaceNo and [SwitchingAddressNo] NOT IN
      (Select [SwitchingAddressNo] from AddressBook where [Block] = true and [Deleted] = false

      The above query i wrote, and its working fine. I want to know the performance related issues with this? If its ugly? then how can i improve the same.

      P Offline
      P Offline
      PSK_
      wrote on last edited by
      #2

      You are using NOT IN in you query, it is not good for the query performance as the query is not going to use benefits of indexes defined on the table and will use a sequential scan on the entire table, try to use NOT EXISTS.

      WWW, WCF, WWF, WPF, WFC .... WTF

      P 1 Reply Last reply
      0
      • P PSK_

        You are using NOT IN in you query, it is not good for the query performance as the query is not going to use benefits of indexes defined on the table and will use a sequential scan on the entire table, try to use NOT EXISTS.

        WWW, WCF, WWF, WPF, WFC .... WTF

        P Offline
        P Offline
        programmervb netc
        wrote on last edited by
        #3

        Does this apply to all DBs? I have never used NOT EXISTS...

        Humble Programmer

        P 1 Reply Last reply
        0
        • H Hum Dum

          Select Min(Priority) from Outbox where [Transmitted] = false and [FolderId] IN (7,8) and
          [Deleted] = false and [InterfaceNo] =@InterfaceNo and [SwitchingAddressNo] NOT IN
          (Select [SwitchingAddressNo] from AddressBook where [Block] = true and [Deleted] = false

          The above query i wrote, and its working fine. I want to know the performance related issues with this? If its ugly? then how can i improve the same.

          D Offline
          D Offline
          Don Burton
          wrote on last edited by
          #4

          Indexes and Index Hints - possibly.

          1 Reply Last reply
          0
          • P programmervb netc

            Does this apply to all DBs? I have never used NOT EXISTS...

            Humble Programmer

            P Offline
            P Offline
            PSK_
            wrote on last edited by
            #5

            I am sure about SQL Server, Oracle and Sybase but no idea about other DB servers.

            WWW, WCF, WWF, WPF, WFC .... WTF

            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