SQL Server 中的 CTE 与视图性能 [英] CTE vs View Performance in SQL Server

查看:77
本文介绍了SQL Server 中的 CTE 与视图性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个更快:

  1. 来自 cte 的查询
  2. 从视图中查询

(在复杂查询中).我有一个复杂的查询,我还有第一个复杂的查询.为第一个复杂查询和查询创建视图或使用 cte 是否更快?

(in Complex Queries). I have a complex query and i have another complex query from the first one.Is it faster to create a view for the first complex query and query from the view or use cte?

推荐答案

视图是一个永久的对象,结果可以被索引,而 CTE 是临时的,只有在使用时才创建,所以不太灵活.将复杂的查询分解成索引视图比分解成 CTE 的效率更高.确保所有表都被正确索引将是最有效的,这可能比担心视图与 CTE 更能提高性能.

A view is a permanent object and the results can be indexed, while a CTE is temporary and created only when used so less flexible. It will be more efficient to break apart your complex query into indexed views than into CTE's. It will be most efficient to ensure all of the tables are properly indexed, which will probably do more for performance than worrying about views vs. CTE's.

这篇关于SQL Server 中的 CTE 与视图性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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