- [SQL] Compare Operator - 比較基本索引型態成本效率:介紹所有索引的特性,此篇文章再細說 Heap, Clustered 與 NonClustered Index 比較之間關係
 
- "NonClustered Index" 的 row locator 就是儲存 
 
- "Heap" 的 Row ID (RID) 
 
- "Clustered" 的索引 "鍵值資料行"
 
- 資料庫使用 Adventure Works for SQL Server 2012 的資料表 Production.Product 產生 2 種不同資料表
 
- tbProduct01:NonClustered Index (Name)
 
- tbProduct02:Clustered (ProductID), NonClustered Index (Name)
 
select ProductID, Name from tbProduct01 where Name = 'Chainring'
select ProductID, Name from tbProduct02 where Name = 'Chainring'
- 查詢結果
 
- 查詢 1. 資料表建立為 "NonClustered Index",而 "NonClustered Index" 的 row locator 指向 "Heap" 的 Row ID (RID)。輸出資料行缺乏 ProductID,因此透過 "RID 查閱" 取得該資料行資料
 
- 查詢 2. 依據 Clustered 建立 NonClustered Index,而 "NonClustered Index" 的 row locator 指向 "Clustered" 的 "鍵值資料行" ProductID。輸出資料行 ProductID 與 Name 包括在 "NonClustered Index" 內,因此不需要額外使用 "查閱"
 
- Result:
 
- 四個基本的 "索引" 可看待四種不同的 "資料表" 型態
 
- Heap
 
- Clustered
 
- NonClustered Index
 
- NonClustered ColumnStore Index
 
- NonClustered Index 除了自己的 "鍵值資料行" 之外,row locator 是指向
 
- Row ID 
 
- Clustered 的 "鍵值資料行" (依據資料表有無建立 Clustered)
 
- 因此 NonClustered Index 額外包括 
 
- Heap 資料表的 "Row ID"
 
- Clustered 的 "鍵值資料行"
 
- REF:
 
 
沒有留言:
張貼留言