MySQL 视图比普通查询更快吗?

发布于 2024-10-13 19:47:06 字数 136 浏览 2 评论 0原文

我有一个使用许多连接(实际上是 8 个)的复杂查询。我正在考虑将其简化为视图。经过一番研究后,我可以看到简单性和安全性方面的好处。但我没有看到任何提到速度的内容。

视图的工作方式是否类似于预编译查询的预编译语句?使用视图是否有显着的性能提升?

I have a complex query using many joins (8 in fact). I was thinking of simplifying it into a view. After a little research I can see the benefits in simplicity and security. But I didn't see any mentions of speed.

Do views work like prepared statements, where the query is pre-compiled? Is there any notable performance gain from using views?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜清冷一曲。 2024-10-20 19:47:06

不,视图只是一个存储的文本查询。您可以对其应用 WHEREORDER,执行计划将根据这些子句进行计算。

No, a view is simply a stored text query. You can apply WHERE and ORDER against it, the execution plan will be calculated with those clauses taken into consideration.

月朦胧 2024-10-20 19:47:06

视图基本上是一个存储的子查询。 之间本质上没有区别,

SELECT *
FROM someview

SELECT *
FROM (
    SELECT somestuff 
    FROM underlying table
);

只是视图更便携,因为您不必每次想要使用它返回的任何数据时都编写底层查询。

A view's basically a stored subquery. There's essentially no difference between:

SELECT *
FROM someview

and

SELECT *
FROM (
    SELECT somestuff 
    FROM underlying table
);

except the view's a bit more portable, as you don't have to write out the underlying query each time you want to work with whatever data it returns.

吃→可爱长大的 2024-10-20 19:47:06

有时它会有所帮助,但这并不是灵丹妙药。我见过视图有助于性能,但我也见过它损害性能。视图可以强制实现,如果 MySQL 没有为您选择一个好的访问路径,这有时可以为您提供更好的访问路径。

It can sometimes help, but it's no silver bullet. I've seen a view help performance, but I've also seen it hurt it. A view can force materialization, which can sometimes get you a better access path if MySQL isn't choosing a good one for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文