How much faster is timestamp than datetime column in MySQL? How much faster is timestamp than datetime column in MySQL? sql sql

How much faster is timestamp than datetime column in MySQL?


The easiest way to find out is to write a unit test, and actually get some numbers.

My theory was that timestamp would be faster, but according to this blog I am wrong:http://dbscience.blogspot.com/2008/08/can-timestamp-be-slower-than-datetime.html

This is why I tend to get numbers, by profiling, before I decide where to optimize, as my gut feeling can be quite wrong at times.

So, it may depend on the version of MySQL you are using, but it appears that datetime may be faster.


From what I can tell, the major benefit of using TIMESTAMP over DATETIME is being able to automatically set a value to the current time on row creation and being able to set it (or another column with a little effort) to the current time on row update. This allows for an automatic created and modified date.

Because of the other limitations on the TIMESTAMP column (for example, not being to accept dates outside of a certain range or changing if the server time zone changes), DATETIME is going to be preferable if you're not needing one of the two features from above.

However, if you're merely interested in storing a Unix timestamp in the database and not needing the database to ever convert it, you could probably store it as an unsigned integer directly and achieve slightly performance.