資料庫中,Indexes可以加速Table的搜尋、排序、group functions 等操作。Index 由 Index key及 Pointers組成,Index key 是 Table 的欄位(一欄或多欄)的值(單個或複合值),Pointer 可以指向Index Key 值對應的資料列。因此DBMS可以先分析Index,依據Index key的值做條件篩選再去取得原始資料列,而不用一開始full scan整個table。
Index 種類
Index的類型可以分為以下幾種:
Hash Index
index 的 key 為原始 column 的 Hash value,適合相等條件的查詢。
B-tree Index
由 self-balanced tree 的構造有序建造 Index,Leaf node 為index key value 及 pointer,適合 key 欄位值重複少的情況。
Bitmap Index
用bit將column值呈現於index key,適合一些 key Column為值少重複多的屬性類型,如此一來Index的體積較小。
B+ Tree
由於Leaf Node為有序且可以水平遍歷,因此比起 B-tree Index 有範圍查詢的優勢。