Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a MySQL view faster than a normal query?

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?

like image 410
DisgruntledGoat Avatar asked Jan 25 '11 02:01

DisgruntledGoat


People also ask

Which query is faster in MySQL?

MySQL full-text search (FTS) is far much faster than queries using wildcard characters.

Should I use views in MySQL?

Views should be used when:Simplifying complex queries (like IF ELSE and JOIN or working with triggers and such) Putting extra layer of security and limit or restrict data access (since views are merely virtual tables, can be set to be read-only to specific set of DB users and restrict INSERT )

Which is faster select from table or view?

there is no difference. A view is just a stored query which can be referred to in sql queries as though they are tables. Note that this does not apply to materialized views. A view is only a query stored in the data dictionary: it is not going to make your query run faster or slower.

Does view improve performance?

A view in and of itself will not increase performance. With that said depending on the database engine you are using there are things you can do with a view. In SQL Server you can put an index on the view (Assuming the view fits a variety of requirements). This can greatly improve the performance.


1 Answers

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.

like image 158
Larry Lustig Avatar answered Sep 26 '22 06:09

Larry Lustig