How are clustered indexes stored on a hard disk? What is the logical order?
How do non-clustered indexes work?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This means that the data in the table are stored in a
B-Treeaccording to the order of theCLUSTERED PRIMARY KEY(or the clustering columns).This name is in my opinion a little bit confusing. The same concept in
Oracleis calledindex-organized tablewhich I find much more descriptive.Non-clustered indexes contain the value of the indexed columns along with the pointer to the record they are originated from.
The "clustered index" is the table itself; the "non-clustered" index is an ordered copy of some of the table’s columns.
If you "create" a clustered index, the table is rearranged. That’s why you cannot have more than one "clustered index" on a table: the table cannot be arranged in more than one order.
If you create a secondary index, the shadow copy of the table is created, holding the values of the indexed columns and the pointers to the records they are from. Whenever the table changes, the copy is changed too (the engine takes care of that automatically).
Non-clustered table
The table is not ordered.
Clustered table
The table is ordered on
id.Clustered table with a secondary index
The table is orderer on
id, the index is ordered on(col1, id)