我有一个表,数据量很大,我在第一个和第二个字段上建立了两个索引
后来发现还可以在一个索引中包含两个字段这样建立,请问,分别建立索引和一个索引包含多个字段两种情况之间的性能上的异同,多谢多谢!!

解决方案 »

  1.   

    如果分开建索引:
    create index idx1 on test(a);
    create index idx2 on test(b);则查询时:
    where a=...  可以用到 idx1的索引
    where b=...  可以用到 idx2的索引
    where a=... and b=... 就可能在两个索引中选择一个或者两个都用,也可能两个都不用,取决于优化器根据相关统计信息的判断.如果只建一个复合索引:
    create index idx1 on test(a,b);则查询时:
    where a=...  可以用到 idx1的索引
    where b=...  没有索引可以用
    where a=... and b=... 可以用到 idx1 的索引我想你应该比较清楚了,具体怎么建索引,看你的应用