Home > mysql > Clustered indexes Vs Non-clustered indexes

Clustered indexes Vs Non-clustered indexes

A clustered index is a special type of index that reorders the records in the table are physically stored. In non-technical way, you are telling the database to store close values to one another on the disk. This means, a table can have only one clustered index. This has the benefit of rapid scan / retrieval of records on any operation with clustered index values.

Writing to a table with a clustered index can reduce the speed, if clustered index is other than primary key. The reason is to rearrange the records.

For e.g.
I have two tables.
1) User
2) Order

User
———-
ID
Name
Address

Order
———-
ID
UserID
Price

If i need to get all orders of one user, than you can create clustered index on UserID of Order table. So all records of particular records will be physically stored to each other. This will speed up when we retrieve records.

A nonclustered index is a special type of index that stores the records in logical order rather than physical order. This means, a table can have many non clustered indexes. More non clustered indexes per table means more time it takes to write new records.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: