What does this sentence mean: Clustered indexes are stored physically on the table?

后端 未结 6 662
予麋鹿
予麋鹿 2020-12-29 07:58

How are clustered indexes stored on a hard disk? What is the logical order?

How do non-clustered indexes work?

6条回答
  •  萌比男神i
    2020-12-29 08:28

    It means that a clustered index determined the physical order in which records in a table are actually stored. Non-clustered indices are simply lists of key values stored separately that enable fast lookups in other orderings than the clustered/physical ordering.

    Quick example: a table with ID (primary key), FirstName, LastName and Car containing three people: 0=The Stig (Llana), 1=Jeremy Clarkson (DB9), 2=Richard Hammond (911), 3=James May (Lambo) and a clustered index on LastName and a non-clustered index on Car would store the actual lines of data in the table in this physical order on disk:

    ID FirstName LastName Car
    1  Jeremy    Clarkson DB9
    2  Richard   Hammond  911
    3  James     May      Lambo
    0  The       Stig     Llana
    

    The nonclustered index would also store something like:

    Car   ID
    911   2
    DB9   1
    Lambo 3
    Llana 0
    

提交回复
热议问题