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. which answer is right?

which answer is right?

Scheduled Pinned Locked Moved Database
databasesql-serversysadminperformancequestion
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
    mctramp168
    wrote on last edited by
    #1

    I have a table containing production information that your users query frequently, They specifically use this query most often (that is only use name to search in the where condition): SELECT Name,Description,Vendor,Instock,Price FROM Products where Name='name' Have a nonclustered index on this table on the Name column,but your users are complaining the query is still too slow,what can you do to speed it up? A、modify the index to include the Description,vendor,Instock, and price columns as nonkey columns. B、Create a new nonclustered index on the Description,vendor,Instock, and price as nonkey columns. C、Create a new clustered index on the Description,vendor,Instock, and price as nonkey columns. D、You can't do anything to speed up this query. Database is MS SQL SERVER. Above four choices, which answer is right?please tell the reason.Thanks

    A B 2 Replies Last reply
    0
    • M mctramp168

      I have a table containing production information that your users query frequently, They specifically use this query most often (that is only use name to search in the where condition): SELECT Name,Description,Vendor,Instock,Price FROM Products where Name='name' Have a nonclustered index on this table on the Name column,but your users are complaining the query is still too slow,what can you do to speed it up? A、modify the index to include the Description,vendor,Instock, and price columns as nonkey columns. B、Create a new nonclustered index on the Description,vendor,Instock, and price as nonkey columns. C、Create a new clustered index on the Description,vendor,Instock, and price as nonkey columns. D、You can't do anything to speed up this query. Database is MS SQL SERVER. Above four choices, which answer is right?please tell the reason.Thanks

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Surely its obvious? Look at the select SELECT Name,Description,Vendor,Instock,Price FROM Products where Name='name' and the options: B and C - why will creating these indices help? The search is on name only. D - of course it can be speeded up This leaves A. By including the other columns on the non-clustered index only the index will be read, therefore saving the read from the underlying table. Hope this explains it, it really is a bit of a no-brainer question.

      Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

      M M 2 Replies Last reply
      0
      • A Ashfield

        Surely its obvious? Look at the select SELECT Name,Description,Vendor,Instock,Price FROM Products where Name='name' and the options: B and C - why will creating these indices help? The search is on name only. D - of course it can be speeded up This leaves A. By including the other columns on the non-clustered index only the index will be read, therefore saving the read from the underlying table. Hope this explains it, it really is a bit of a no-brainer question.

        Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

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

        You know it would never occur to me to add these other fields into the index, I would leave it at D. The penalty of AED on that table/index would outweigh the benefits I would have thought. Taking that advice to the next level and you get something like - every table that is in a select query should carry an index with every field in it!

        A 1 Reply Last reply
        0
        • M Mycroft Holmes

          You know it would never occur to me to add these other fields into the index, I would leave it at D. The penalty of AED on that table/index would outweigh the benefits I would have thought. Taking that advice to the next level and you get something like - every table that is in a select query should carry an index with every field in it!

          A Offline
          A Offline
          Ashfield
          wrote on last edited by
          #4

          Mycroft Holmes wrote:

          The penalty of AED on that table/index would outweigh the benefits I would have thought.

          Based on the OP "I have a table containing production information that your users query frequently" implies to me that there are many more reads than writes, so once the index is created there is little overhead - however, based on the info given, that is not certain so you may be correct. In real life you make a judgement call based on your knowledge of the system.

          Mycroft Holmes wrote:

          I would leave it at D

          Not if you have a load of irate users on your back :) In reality, the guy wanted to know the answer to an interview/exam question, and I would put my money on adding the other columns to the index being what they were looking for.

          Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

          M 1 Reply Last reply
          0
          • A Ashfield

            Surely its obvious? Look at the select SELECT Name,Description,Vendor,Instock,Price FROM Products where Name='name' and the options: B and C - why will creating these indices help? The search is on name only. D - of course it can be speeded up This leaves A. By including the other columns on the non-clustered index only the index will be read, therefore saving the read from the underlying table. Hope this explains it, it really is a bit of a no-brainer question.

            Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

            M Offline
            M Offline
            mctramp168
            wrote on last edited by
            #5

            Thank you for your kindly help!

            1 Reply Last reply
            0
            • M mctramp168

              I have a table containing production information that your users query frequently, They specifically use this query most often (that is only use name to search in the where condition): SELECT Name,Description,Vendor,Instock,Price FROM Products where Name='name' Have a nonclustered index on this table on the Name column,but your users are complaining the query is still too slow,what can you do to speed it up? A、modify the index to include the Description,vendor,Instock, and price columns as nonkey columns. B、Create a new nonclustered index on the Description,vendor,Instock, and price as nonkey columns. C、Create a new clustered index on the Description,vendor,Instock, and price as nonkey columns. D、You can't do anything to speed up this query. Database is MS SQL SERVER. Above four choices, which answer is right?please tell the reason.Thanks

              B Offline
              B Offline
              Bassam Saoud
              wrote on last edited by
              #6

              I would keep the index on Name and create another index on Name,Description,Vendor,Instock,Price * This should solve any Bookmark problem - have you ran execution plan on your query? if this is a heavily 'write' table, you will pay the price when rebuilding indexes

              1 Reply Last reply
              0
              • A Ashfield

                Mycroft Holmes wrote:

                The penalty of AED on that table/index would outweigh the benefits I would have thought.

                Based on the OP "I have a table containing production information that your users query frequently" implies to me that there are many more reads than writes, so once the index is created there is little overhead - however, based on the info given, that is not certain so you may be correct. In real life you make a judgement call based on your knowledge of the system.

                Mycroft Holmes wrote:

                I would leave it at D

                Not if you have a load of irate users on your back :) In reality, the guy wanted to know the answer to an interview/exam question, and I would put my money on adding the other columns to the index being what they were looking for.

                Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

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

                Ashfield wrote:

                In reality, the guy wanted to know the answer to an interview/exam question

                It definitely feels like a theory question that has no basis in reality. I would have trouble answering D as I know I don't know everything and I hate having to answer that to irate users, so I would be looking for the E option - more research required.

                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