Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL VIEW vs. embedded query, which one is faster?

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);

I want to convert it to:

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

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

like image 642
yegor256 Avatar asked Dec 15 '25 11:12

yegor256


1 Answers

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.

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.

like image 143
OMG Ponies Avatar answered Dec 17 '25 01:12

OMG Ponies



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!