|
最初由 yoptim 发布
[B]only consider on performance tuning one query:
select * from tab1 where f1 = ? and f2 = ?
how to determine the index key order of the composite index on f1 and f2? I mean, which one should we used ? index on (f1,f2) or index on (f2,f1) ? And what should we consider when creating composite index?
select count (distinct f1) from tab1
4
select count (distinct f2) from tab1
3129
Thanks, [/B]
这是一个很具体的问题了,如果要做出分析 希望能够提供一下 f1,f2的字段类型,数据表中的总记录数,以及数据表中f1,f2数值的具体分布情况, 数据表的总宽度(所有字段长度之和) 才能做更精准的判断。
通常来讲,当列f1,f2的数值分布都比较均匀的情况下,可以采用(f2,f1)的方法建立组合索引。
另外,可以通过观察SQL语句的查询计划和执行语句的IO开销来判断那种组合索引对于查询更加有效。 |
|