简体   繁体   English

如何优化最频繁的MySQL SELECT查询

[英]How to optimize the most frequent MySQL SELECT query

I have a MySQL table with millions of records, and there are hundreds of records inserted into the table every day. 我有一个包含数百万条记录的MySQL表,每天有数百条记录插入该表中。

In the front-end, it displays the most recent 100 records using the query: 在前端,它使用查询显示最近的100条记录:

SELECT * FROM 
table_a 
ORDER BY creation_time DESC 
LIMIT 100

Every time a user visits the page, it will scan through the large table and perform the sorting. 每次用户访问该页面时,它都会扫描大表并执行排序。 The procedure looks very resources consuming. 该过程看起来非常耗资源。

I find that there is a VIEW in MySQL. 我发现MySQL中有一个VIEW Does it help to optimize the performance if I create a view to store the results? 如果创建一个视图来存储结果,是否有助于优化性能? Is the view synchronized with the original table? view是否与原始表同步? Or any other means to boost the query performance? 还是任何其他手段来提高查询性能?

Thanks! 谢谢!

You can try following things to speed up your query: 您可以尝试以下操作来加快查询速度:

1. Select only required column(s) instead of all (*) in SELECT Query.
2. Create Indexes on creation_time.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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