SQL Server 中的 CTE 与视图性能

编程入门 行业动态 更新时间:2024-10-26 19:35:26
本文介绍了SQL Server 中的 CTE 与视图性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

哪个更快:

  • 来自 cte 的查询
  • 从视图中查询
  • (在复杂查询中).我有一个复杂的查询,我还有第一个复杂的查询.为第一个复杂查询和查询创建视图或使用 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 与视图性能

    本文发布于:2023-10-13 14:23:44,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1488203.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:视图   性能   SQL   Server   CTE

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!