Scanning a mysql table from the bottom

不打扰是莪最后的温柔 提交于 2019-12-08 13:17:17

问题


When i run a mysql select statement, it takes very long because i have already previously deleted a very large number of rows.

Is there a way for the table to start scanning from the bottom, as opposed to from the top?


回答1:


A query does not scan the table in any particular order; it might do so if it happens to traverse a particular index in order (e.g. a range scan), which MIGHT be because you used an ORDER BY.

Databases just don't work like that. You cannot rely on their behaviour in that way.

If you're doing a full table scan, expect it to take a while, particularly if you've deleted a lot of rows recently. However, it will take even longer if you have lots of rows.

Ensure that the query uses indexes instead. Looks at the explain plan and make sure it uses indexes.




回答2:


Maybe you need an additional index for your table. It also doesn't hurt to issue OPTIMIZE TABLE and ANALYZE TABLE occasionally. Query performance shouldn't be affected by having deleted rows, even large numbers of rows, provided you have suitable indexes.



来源:https://stackoverflow.com/questions/2857720/scanning-a-mysql-table-from-the-bottom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!