views:

91

answers:

1

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.

+3  A: 

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.

Mark Byers