数据库视图是否影响查询性能? [英] Do database views affect query performance?

查看:1063
本文介绍了数据库视图是否影响查询性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据库视图是否只是简化数据访问的方法,还是在访问视图时提供性能优势,而不是仅仅运行视图所基于的查询?我怀疑视图在功能上等效于只是将视图数据上的每个查询添加存储视图查询,是正确的还是有其他细节和/或优化发生?

Are database views only a means to simplify the access of data or does it provide performance benefits when accessing the views as opposed to just running the query which the view is based on? I suspect views are functionally equivalent to just the adding the stored view query to each query on the view data, is this correct or are there other details and/or optimizations happening?

推荐答案

虽然在视图中运行的某个查询和在视图外部运行的同一查询应该等效执行,但是当需要一起连接两个视图时,事情会变得更加复杂。您可以很容易地将不需要的表带入查询中,或者冗余地使用表。数据库的优化器在创建良好的查询执行计划时可能会有更多的麻烦。因此,虽然视图可以非常好地允许更细粒度的安全性等,但它们不一定对模块化有好处。

Although a certain query running inside a view and the same query running outside of the view should perform equivalently, things get much more complicated quickly when you need to join two views together. You can easily end up bringing tables that you don't need into the query, or bringing tables in redundantly. The database's optimizer may have more trouble creating a good query execution plan. So while views can be very good in terms of allowing more fine grained security and the like, they are not necessarily good for modularity.

这篇关于数据库视图是否影响查询性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆