Performance considerations when using MySQL VIEWs

依然范特西╮ 提交于 2019-12-10 10:23:19

问题


I was considering using MySQL views to provide an abstraction when pulling data from the DB. As I was looking for material on this, I came across this article, which ends with:

MySQL has long way to go getting queries with VIEWs properly optimized.

The article is from 2007. Is this still applicable? Eg: Has MySQL solved these issues?


回答1:


MySQL views work fine functionally, but they perform badly in the majority of cases.

This is because introducing even quite a simple view tends to cause a much worse query plan to be used by the optimiser. This makes using views impractical in the general case.

Often the server will materialise the entire view as a temporary table, which is not helpful for good performance (unless it happens to have only a very small number of rows in it).

So if you thought the explain plan was ok without a view, with a view it can turn terrible. This is still unresolved in the latest dev version of MySQL as far as I know.

You can have views, but don't expect decent (i.e. acceptable) performance.



来源:https://stackoverflow.com/questions/3515743/performance-considerations-when-using-mysql-views

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