Clustered Index & Non Clustered Index

  • Assume that I have two tables one with Clustered index and other table with Non Clustered Index. Now I want to insert 1 million rows in both the table Then which table will perform faster (Is it Clustered index table or Non clustered Index table) and why?

  • Probably the clustered index, since the nonclustered is a second copy of the data that would have to be separately maintained.

    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
  • I'm not clear on your reason. Could you explain little further.Assume that the data inserting in clustered & non clustered index tables are different.

  • The clustered index is the table, so the table with the cluster there's only one copy of the data.

    The second table has only a nonclustered index, that means there's two structures, the heap (the table itself) and the nonclustered index. Hence two copies of the data. Hence likely to take longer to insert into.

    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
  • Got it. Thank you for your response

  • Not to mention that even if you index a very large table with a nonclustered index, if you omit a clustered index from that table, the nonclustered index may not be a huge help. If the underlying table is a heap, it takes more work for the processor to walk from the index leaf to the actual row, whereas if there is a clustered index the data is arranged in a predetermined order.

  • Clear and Nice. Appreciated!!

  • jeff.mason (7/15/2010)


    If the underlying table is a heap, it takes more work for the processor to walk from the index leaf to the actual row, whereas if there is a clustered index the data is arranged in a predetermined order.

    If the base table is a heap, the nonclustered index has the actual physical RID as a location for the data row. Hence it can go straight to the page that the row is on and fetch it.

    Order of data is irrelevant if the location of the row is known (which it will be with a heap)

    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
  • Hi Gail,

    Can you please explain, when can I use Non Clustered Index more effectively.

    Ram..

    🙂

  • Most oftenly Nonclustered indexes are created on a columns where those are columns are heavily used in query's to improve the query performance. especially where Clustered index columns are not used.

  • Have a read through this, see if it helps - http://www.sqlservercentral.com/articles/Indexing/68439/

    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
  • Gail..

    Your article is very clear for me.. thanks

    Raju.. Thanks for your reply..

    🙂

Viewing 12 posts - 1 through 11 (of 11 total)

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