哪个更快:
(在复杂查询中).我有一个复杂的查询,我还有第一个复杂的查询.为第一个复杂查询和查询创建视图或使用 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 与视图性能
发布评论