Is the field in MySQL time stamped with int or timestamp?? Because there are more range queries on this field when querying? Which performance would be better.

under the premise that the created_at column is indexed.
the data volume of the table is tens of millions of levels.
explain shows that the number of rows scanned is 2 million
select count (*) from users where created_at < "2018-08-28 0000lv 00lv 00" and created_at > =" 2018-08-0100lv 0000"
count is about four or five hundred thousand. This kind of range query created_at uses int timestamp or timestamp performance which is better

May.12,2021

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,.

Menu