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

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

问题描述

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

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天全站免登陆