MySQL VIEW与嵌入式查询,哪个更快? [英] MySQL VIEW vs. embedded query, which one is faster?

查看:93
本文介绍了MySQL VIEW与嵌入式查询,哪个更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用视图优化MySQL嵌入式查询,但不确定是否会产生效果:

I'm going to optimize a MySQL embedded query with a view, but I'm not sure whether it will give an effect:

SELECT id FROM (SELECT * FROM t);

我想将其转换为:

CREATE VIEW v AS SELECT * FROM t; 
SELECT id FROM v;

我听说过SQL Server中的索引视图",但是我不确定MySQL.任何帮助,将不胜感激.谢谢!

I've heard about "indexed views" in SQL Server, but I'm not sure about MySQL. Any help would be appreciated. Thanks!

推荐答案

SQL Server中的索引视图通常称为物化视图",MySQL不支持.与其他供应商相比,MySQL的VIEW支持非常有限-限制在其文档中列出了.

Indexed views in SQL Server are generally called "materialized views", which MySQL does not support. MySQL's VIEW support is rather limited in comparison to other vendors - the restrictions are listed in their documentation.

普通视图仅仅是准备好的SQL语句-使用您提供的两个示例之间没有区别.在某些情况下,优化程序可以将WHERE子句从视图中进行选择,将其推入VIEW查询中,但这完全超出了您的控制范围.

A normal view is merely a prepared SQL statement - there's no difference between using the two examples you provided. In some cases, the WHERE clause when selecting from a View can be pushed into the VIEW query by the optimizer, but it's completely out of your control.

这篇关于MySQL VIEW与嵌入式查询,哪个更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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