【发布时间】:2011-01-09 06:52:04
【问题描述】:
我在表格中搜索时依赖于 2 个字段:field1、field2。它们在所有记录中都不是唯一的,既不是单独的也不是组合的。
所以我正在为它们添加索引:
方法一:
alter table xx add index (field1, field2);
alter table xx add index (field2);
方法二:
alter table xx add index (field1);
alter table xx add index (field2);
我的问题是这两种方法之间有什么区别(如果有的话)?对于以下每个选择查询:
select * from table xx where field1 = ??
select * from table xx where field2 = ??
select * from table xx where field1 = ?? and field2 = ??
select * from table xx where field1 = ?? or field2 = ??
哪种方法更好?
那么,哪种方法更适合这个查询?
select * from table xx where field1 = ?? and field2 = ??
【问题讨论】: