Clustered vs Non-clustered Index: Key Differences with Example

Clustered vs Non-clustered Index: Key Differences with Example

What is an Index?
An Index is a key built from one or more columns in the database that speeds up fetching rows from the table or view. This key helps a Database like Oracle, SQL Server, MySQL, etc. to find the row associated with key values quickly.

Two types of Indexes are:

Clustered Index
Non-Clustered Index
In this tutorial, you will learn:

What is an Index?
What is a Clustered index?
What is Non-clustered index?
Characteristic of Clustered Index
Characteristics of Non-clustered Indexes
An example of a clustered index
An example of a non-clustered index
Differences between Clustered Index and NonClustered Index
Advantages of Clustered Index
Advantages of Non-clustered index
Disadvantages of Clustered Index
Disadvantages of Non-clustered index

 

Differences between Clustered Index and NonClustered Index

Advantages of Clustered Index
The pros/benefits of the clustered index are:

Clustered indexes are an ideal option for range or group by with max, min, count type queries
In this type of index, a search can go straight to a specific point in data so that you can keep reading sequentially from there.
Clustered index method uses location mechanism to locate index entry at the start of a range.
It is an effective method for range searches when a range of search key values is requested.
Helps you to minimize page transfers and maximize the cache hits.
Advantages of Non-clustered index
Pros of using non-clustered index are:

A non-clustering index helps you to retrieves data quickly from the database table.
Helps you to avoid the overhead cost associated with the clustered index
A table may have multiple non-clustered indexes in RDBMS. So, it can be used to create more than one index.
Disadvantages of Clustered Index
Here, are cons/drawbacks of using clustered index:

Lots of inserts in non-sequential order
A clustered index creates lots of constant page splits, which includes data page as well as index pages.
Extra work for SQL for inserts, updates, and deletes.
A clustered index takes longer time to update records when the fields in the clustered index are changed.
The leaf nodes mostly contain data pages in the clustered index.
Disadvantages of Non-clustered index
Here, are cons/drawbacks of using non-clustered index:

A non-clustered index helps you to stores data in a logical order but does not allow to sort data rows physically.
Lookup process on non-clustered index becomes costly.
Every time the clustering key is updated, a corresponding update is required on the non-clustered index as it stores the clustering key.

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(43)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2021-06-28 cookie category
2021-06-28 cannot apply the specified columns kentico
2020-06-28 古墓惊魂 关卡奖励的宝藏
2019-06-28 What is 'typeof define === 'function' && define['amd']' used for?
2019-06-28 jQuery .closest()
2019-06-28 jquery.fileupload-image-editor.js
2019-06-28 event.currentTarget
点击右上角即可分享
微信分享提示