SQL Server 查看性能
如果我在 SQL Server 中定义了一个视图,如下所示:
CREATE View V1
AS
SELECT *
FROM t1
INNER JOIN t2 ON t1.f1 = t2.f2
ORDER BY t1.f1
我是否应该期望视图之间存在性能差异
SELECT * FROM V1 WHERE V1.f1 = 100
并避免像这样的视图
SELECT *
FROM t1
INNER JOIN t2 ON t1.f1 = t2.f2
WHERE t1.f1 = 100
ORDER BY t1.f1
?
除了需要集中复杂的查询之外,我们没有任何理由使用视图。
谢谢
If I have defined a view in SQL Server like this:
CREATE View V1
AS
SELECT *
FROM t1
INNER JOIN t2 ON t1.f1 = t2.f2
ORDER BY t1.f1
Should I expect performance differences between
SELECT * FROM V1 WHERE V1.f1 = 100
and just avoiding view, like this
SELECT *
FROM t1
INNER JOIN t2 ON t1.f1 = t2.f2
WHERE t1.f1 = 100
ORDER BY t1.f1
?
We don't have any reason to use views except the need to centralize complex queries.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不应该有性能损失。
视图的作用就是简化复杂的查询。
如果您关心性能 - 请阅读 SQL Server 中的索引视图:
There should be no performance penalty.
Simplifying complex queries is what views are for.
If performance is something you are concerned about - read about indexed views in SQL Server:
通常,您不应期望性能差异,但应检查查询的执行计划。
如果您将视图连接到视图上,那么执行计划可能不是最优的,并且包含对本可以合并的同一表的重复访问。此外,视图和谓词推送< /a>.
Generally you shouldn't expect performance differences but check the execution plans for your queries.
If you are joining Views onto Views then the execution plans can be sub optimal and contain repeated accesses to the same table that could have been consolidated. Also there can be issues with views and predicate pushing.