开发者

Indexing datetime in MySQL

What is the best way to index a datetime in MySQL? Which method is faster:

  1. Store the datetime as a double (via unix timestamp)
  2. Store the datetime as a datetime

The application generating the timestamp data can output either format. Unfortunately, datetime will be a key for this particular data structure so speed will matter.

Also, is it possible to make an index on an expression? For example, index on UNIX_TIMESTAMP开发者_高级运维(mydate) where mydate is a field in a table and UNIX_TIMESTAMP is a mysql function. I know that Postgres can do it. I'm thinking there must be a way in mysql as well.


I don't think either method will be much faster than the other, but if you choose a 'datetime' it will be a lot easier to operate with the standard date time functions.

MySQL doesn't support functional indexes.


I think using an integer will be faster because where datetime >= '2010-09-30 01:31:41' will never hit an index. However where intTimestamp >= 237492347 will.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜