简体   繁体   中英

sql query optimisation on MySQL

I have the below SQL query and want to know if there is a way to optimise the query.

SELECT * FROM LogEntry WHERE UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(updateTime) > 10;

Will adding index on updateTime improve the performance on something more can be done to improve the performance

Yes. You need to think of a way to remove the function on the column. So if I have the logic right:

SELECT le.*
FROM LogEntry le
WHERE le.updateTime < NOW() - interval 10 second;

This can then take advantage of an index on LogEntry(updateTime) .

There are good reasons to explicitly list the columns being returned. This only has a small effect on performance -- unless the row size is quite big.

我要做的第一件事是删除您的select *并选择特定的列

In addition to the optimisation of the request, you may think about partitioning your table. For instance, you could partition the table LogEntry on updateTime by day. It would speed your request drastically if you have a lot of data in your table.

Note: to partition your table on updateTime, updateTime must be part of the primary key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM