NON-Clustered Indexes on table but no Clustered Indexes

  • No formal process.

    If I'm considering the indexes from missing indexes DMV, first I'll make sure there are no partial redundancies within the index recommendations. I'll also make sure that there are no existing indexes that I can widen.

    Once that's done, I'll get all the queries that run against that table (from the metadata if all access is via SP, or from profiler if they're not), run them, get their current performance characteristics. Create the new index, or alter an existing one, run the queries again and see if there's been an improvement.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Mohit K. Gupta (5/1/2009)


    If you are just using non-clustered indexes and heap; it will first cause a RID Lookup anytime you access anything in that table via a Index Seek. That is when an index seek operation completes it will have to go back to main heap to get the data. In addition when you are inserting, deleting, and updating records in the table the heap can become fragmented and there is no way to defrag it because of how heap are stored. So the access speed, updates, and deletes can take long time.

    Hi there, I have also found a large table with no clustered indexes and four non-clustred indexes. I can see that one of these non-clustered indexes is being used in the query, but I don't understand what happens then with the RID Lookup - since there is no clustered index does SQL Server have to scan the whole heap? In which case, why bother with an index at all! Hope I'm making sense 🙂 I'm thinking of adding a clustered index to the table, but it's from a 3rd party app, so I need to be very careful (i.e. break the test system first!).

  • JTS: RID Lookup is used to retrieve information from the table that is not part of the index. For example lets say you have a table with col1, col2, col3, col4. You have a non-clustered index on col1. You execute "Select * from Table1 Where Col1 = 123"; system will do a quick seek on col1 to get RID information for all the values in col1 where it is 123. Then using the RID information it will go to the heal to get the remaining information requested by the query, namely col2, col3, and col4. RID tells SQL Server where the row is physically located and for a singleton requests is fairly quick. However if you have scans or range retrieval of the information it can get expensive :).

    Answer you question, should you add Clustered Index? Since this is a 3rd party application most likely not a good idea as most 3rd party vendors will void warranty if people change their database or application. So please take that into consideration. However define large table for me? If the table has more then 1000 pages, maybe look at considering a cluster index. Alternative you might be able to convert one of your non-clusters indexes to clustered. Test, test, and test... before you implement anything :).

    Cheers!

    [font="Arial"]---

    Mohit K. Gupta, MCITP: Database Administrator (2005), My Blog, Twitter: @SQLCAN[/url].
    Microsoft FTE - SQL Server PFE

    * Some time its the search that counts, not the finding...
    * I didn't think so, but if I was wrong, I was wrong. I'd rather do something, and make a mistake than be frightened and be doing nothing. :smooooth:[/font]

    How to ask for help .. Read Best Practices here[/url].

  • Mikey01 (5/1/2009)


    I should point out the process creates over 150 tables in total.... and is probably spread across a couple 100,000 lines of SQL & 250 stored procs

    That seems a bit much even for a really complicated process. What does this process actually do?

    My recommendation would be to forget about indexing for now. A whole lot of people think that Temp Tables and While Loops are somehow better than a cursor. Neither is acceptable and the number of Temp Tables and procs you've identified strongly indicates such RBAR. Start by checking to find out if the stored procs are set based or if they're only handling one agonizing row at a time.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • What about tables that don't have a unique value? How do I create a unique clustered index? Is that even possible without an identity of some sort? Can I make an index on a table that is non-unique clustered without making it a heap?

Viewing 5 posts - 16 through 19 (of 19 total)

You must be logged in to reply to this topic. Login to reply