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. i luv forums...

i luv forums...

Scheduled Pinned Locked Moved Database
learningquestiondiscussion
7 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.
  • M Offline
    M Offline
    Mike654321
    wrote on last edited by
    #1

    really gives us novices a great place to post our beginner questions: SELECT COUNT(BookTitle) FROM Book WHERE IsFiction = 1; I am Indexing the IsFiction field, but not sure if I should be Indexing the BookTitle field too? Any expert thoughts? Thanks again!

    M J I 3 Replies Last reply
    0
    • M Mike654321

      really gives us novices a great place to post our beginner questions: SELECT COUNT(BookTitle) FROM Book WHERE IsFiction = 1; I am Indexing the IsFiction field, but not sure if I should be Indexing the BookTitle field too? Any expert thoughts? Thanks again!

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Not based on that query. If the booktitle field is in a join or a where clause then it may need an index. Take a look at the execution plan and see where the main cost is, if it says table scan then an index will help.

      Never underestimate the power of human stupidity RAH

      M 1 Reply Last reply
      0
      • M Mycroft Holmes

        Not based on that query. If the booktitle field is in a join or a where clause then it may need an index. Take a look at the execution plan and see where the main cost is, if it says table scan then an index will help.

        Never underestimate the power of human stupidity RAH

        M Offline
        M Offline
        Mike654321
        wrote on last edited by
        #3

        I am not joining on the BookTitle field...I just wasn't sure if Count needed BookTitle to be Indexed when it aggregates the count command. I will leave BookTitle un-indexed, thanks!

        1 Reply Last reply
        0
        • M Mike654321

          really gives us novices a great place to post our beginner questions: SELECT COUNT(BookTitle) FROM Book WHERE IsFiction = 1; I am Indexing the IsFiction field, but not sure if I should be Indexing the BookTitle field too? Any expert thoughts? Thanks again!

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

          You could in theory get a faster query if you make a composite index on (IsFiction, BookTitle) and booktitle are having many duplicates. But this is improbable in this case as booktitles are fairly unique, and you will have extra overhead on the inserts and updates.

          "When did ignorance become a point of view" - Dilbert

          1 Reply Last reply
          0
          • M Mike654321

            really gives us novices a great place to post our beginner questions: SELECT COUNT(BookTitle) FROM Book WHERE IsFiction = 1; I am Indexing the IsFiction field, but not sure if I should be Indexing the BookTitle field too? Any expert thoughts? Thanks again!

            I Offline
            I Offline
            i j russell
            wrote on last edited by
            #5

            It is normally good practice to have indexes on fields used in where clauses. However, if IsFiction is a bit field, it will have low selectivity (a measurement of how unique each value is) which will mean that it is highly unlikely that the query optimizer would consider using the index. You are much more likely to find that the optimizer is using a clustered index scan or a table scan.

            M 1 Reply Last reply
            0
            • I i j russell

              It is normally good practice to have indexes on fields used in where clauses. However, if IsFiction is a bit field, it will have low selectivity (a measurement of how unique each value is) which will mean that it is highly unlikely that the query optimizer would consider using the index. You are much more likely to find that the optimizer is using a clustered index scan or a table scan.

              M Offline
              M Offline
              Mike654321
              wrote on last edited by
              #6

              maybe in need 2 go back to the basics...can anyone give me a link or two of a basic tutorial that talks about optimization...i always put indexes on Where or Order By fields if I am doing joins on the Where, and if I think the tables are going to have a huge number of records. also, a simple tutorial link about the Query Optimizer and how to use it would be great too. Thanks!

              I 1 Reply Last reply
              0
              • M Mike654321

                maybe in need 2 go back to the basics...can anyone give me a link or two of a basic tutorial that talks about optimization...i always put indexes on Where or Order By fields if I am doing joins on the Where, and if I think the tables are going to have a huge number of records. also, a simple tutorial link about the Query Optimizer and how to use it would be great too. Thanks!

                I Offline
                I Offline
                i j russell
                wrote on last edited by
                #7

                What you are doing is generally a sensible approach but you need to view the Actual Execution Plan that Sql Server generates to see if they are being used by the Query Optimizer. There is a free pdf download from Red-Gate[^] that is very good. http://www.simple-talk.com/books/sql-books/sql-server-execution-plans/[^] If you are willing to spend some money, then buy this book. SQL Server 2008 Query Performance Tuning Distilled[^] I can't recommend this book highly enough. Although it is targeted at Sql2008, it's still very applicable to Sql2005 as well.

                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