mysqlsqlviewsubquery

Which one is faster view or subquery?


The question says it all. Which one is faster? And when should we use view instead subquery and vice verse when it comes to speed optimisation?

I do not have a certain situation but was thinking about that while trying some stuff with views in mysql.


Solution

  • Neither are particularly efficient in MySQL. In any case, MySQL does no caching of data in views, so the view simply adds another step in query execution. This makes views slower than subqueries. Check out this blog post for some extra info.

    One possible alternative (if you can deal with slightly outdated data) is materialized views. Check out Flexviews for more info and an implementation.