How to design index
Index design:
1) Think of which columns should be included.
unique column to enable index unique scan
most queried columns to enable index full scan or fast index full scan
2) Think of the order of the columns in the index.
Use the most popular column order in query to avoid to sort during the query
3) Think of the DESCEND attribution of the column in the index.
To avoid to sort in desc, you need to define the column with desc during index creation
4) Think of the cluster factor of index
The lower of the cluster factor, the faster of the full table scan/index (fast) full scan
中文版:
1。 考虑要包含哪些字段。
在unique key上建立索引有利与进行index unique scan
对于定义了很多字段的表,如复合索引的建立应包含最常查询的字段,有这样有利与查询使用index full scan和index fast full scan来代替full table scan
2。考虑字段在索引中的位置。
字段在索引中的位置决定了使用该索引的查询的数据输出顺序。因此按经常出现在order by中字段的顺序来建立索引,有利与避免不必要的排序,减少不必要的I/O
3. 考虑索引中字段的DESCEND属性。
往往在查询最近的十条记录时会使用倒序,因此正确的设置DESCEND属性,有利与减少排序。
4。考虑索引的cluster factor.
Cluster factor越小,表明被索引字段的相似数据的物理位置越集中,而用来读取数据所需的I/O则越少。