MySQL:我可以索引日期时间字段吗?MySQL不会这样做


mysql> create index index_questions_on_publishedAt on questions(publishedAt);
ERROR 1317 (70100): Query execution was interrupted
mysql> select count(*) from questions;
+----------+
| count(*) |
+----------+
|   491773 | 
+----------+
1 row in set (1.02 sec)
# Is it even reasonable for this query to take 1 second?
mysql> select count(*) from questions where publishedAt <= '2011-08-23 19:52:01' and publishedAt >= '2011-08-23 19:49:44';
+----------+
| count(*) |
+----------+
|       30 | 
+----------+
1 row in set (0.71 sec)
MySQL info: Server version: 5.1.41-3ubuntu12.10 (Ubuntu)

我的大多数查询都测试不同的时间范围,每个时间段的内容都是在不断变化中,所以我不能在这里缓存太多。耐心等待任何建议…谢谢。

我有一个有725K条记录的表,下面是我的结果:

  • 创建索引前:
    • 在没有索引的条件下计数:0.59秒
    • 无条件计数:0.8秒
  • 在datetime字段上创建索引:2.28秒
    • 状态计数:0.07秒

希望这能回答你的问题。

你的索引创建似乎被某事或某人打断了,但我会仔细检查日志文件,看看是否有任何事情发生在那里。

最新更新