MySQL中的嵌套视图有什么问题吗? [英] Is there anything wrong with nested Views in MySQL

查看:412
本文介绍了MySQL中的嵌套视图有什么问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个视图引用另一个视图有什么问题吗?例如,说我有一个
用户表

Is there anything wrong with having one view reference another view? For example, say I have a users table

CREATE TABLE `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
);

然后出于参数的观点,只显示所有用户

Then for the sake of argument a view that just shows all users

CREATE VIEW all_users AS SELECT * FROM users

然后一个视图只返回他们的 first_name last_name

And then a view that just returns their first_name and last_name

CREATE VIEW full_names AS SELECT first_name, last_name FROM all_users

是否存在基于一个视图的性能问题另一个?我们还假装这是最简单的例子,一个现实世界的场景将会更加复杂,但是同样的一般概念是基于另一个视图的一个视图。

Are there performance issue with basing one view off another? Let's also pretend this is the simplest of examples and a real world scenario would be much more complex, but the same general concept of basing one view of another view.

推荐答案

这取决于 ALGORITHM 使用。 TEMPTABLE可以是相当昂贵的,而MERGE应该与使用表直接相同,所以没有损失。

It depends on the ALGORITHM used. TEMPTABLE can be pretty expensive while MERGE should be the same as using the table directly so no loss there.

这篇关于MySQL中的嵌套视图有什么问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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