【发布时间】:2010-08-27 06:49:26
【问题描述】:
我正在为 mysql 表使用索引。
我的查询是这样的
EXPLAIN SELECT * FROM `logs` WHERE userId =288 AND dateTime BETWEEN '2010-08-01' AND '2010-08-27'
我在字段 userId 上为此表日志建立了索引, 解释查询的结果如下。
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE logs ref userId userId 4 const 49560 Using where
问题是“我的索引是否真的有用?”...
提前致谢
@fastmultiplication
我认为在这两个字段上建立索引可能会增加 mysql 的负载,因为会有很多具有唯一性(userId 和 dateTime)的条目。 我尝试在 userId_dateTime 上添加索引,结果是
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE logs ref userId_dateTime userId_dateTime 4 const 63455 Using where
【问题讨论】:
标签: sql mysql performance