Indexing Date and Time in MySQL
What is the best way to index datetime in MySQL? Which method is faster:
- Store datetime as double (via unix timestamp)
- Store datetime as date and time
An application that generates timestamp data can output any format. Unfortunately datetime will be the key for this particular data structure, so speed will matter.
Also, is it possible to make an index for the expression? For example, an index on UNIX_TIMESTAMP(mydate)
, where mydate is a field in a table and UNIX_TIMESTAMP is a mysql function. I know Postgres can do this . I think there should be a way in mysql too.
+2
source to share
2 answers
I don't think any method will be much faster than the other, but if you choose 'datetime' it will be much easier to work with standard time functions.
MySQL does not support functional indexes .
+3
source to share