如果分开建索引: 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 的索引我想你应该比较清楚了,具体怎么建索引,看你的应用
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 的索引我想你应该比较清楚了,具体怎么建索引,看你的应用