it is recommended that you use timestamp. If you need to use timestamp for a range query, you can add an index to this column.
if timestamp takes up less space in terms of data types, but timestamp has a feature that will be automatically updated to the current time when it is updated. Just pay attention to this
try, range query, int and timestamp, int performance is better, tried many times, used multiple tables, the amount of table data is in tens of millions of levels, and the rows in the explain result is about 10 million, select count (1) from.. Timestamp takes almost four times as long as int every time.
if you want to visualize
, that is, to make it easy to see the data in the database, it is recommended to save it as datetime
, and timestamp
also exists the threshold of 2038
.
in other words, since you consider int
instead of bigint
or varchar
, you can choose seconds
by default.
in this case, it is recommended to use datetime
.
https://dev.mysql.com/doc/ref.
MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval.
This conversion operation of type
TIMESTAMP may slow down the query compared to INT,.