Indexing datetime in MySQL

Posted by User1 on Stack Overflow See other posts from Stack Overflow or by User1
Published on 2010-05-11T17:11:00Z Indexed on 2010/05/11 17:14 UTC
Read the original article Hit count: 207

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about datetime