One should use timestamps rather than datetimes as timestamps are four bytes and datetimes are eight bytes, right? This makes sense as smaller indexes and tables are faster than larger ones. However, when I was trying to quantify the improvement (I’m strange that way), I found the exact opposite - when used as a criteria, a timestamp is slower than a datetime. Often much slower.
For example, for this simple sql, when purchaseDate was a timestamp, the query took about 9.4 seconds and the datetime version took about 4.3 seconds. In this case the data was in memory.
select sum(unit) from Sale where purchaseDate >= '2001-07-01' and purchaseDate < '2001-08-01'
I did other tests, such as when data wasn’t cached and there was io, and I found cases where datetimes were much faster than timestamps, differences so extreme I’m hesitant to report them until I have a better explanation of what is …
[Read more]