Reputation: 6273
the mysql certification guide suggests that views can be used for:
but from how to implement search for 2 different table data?
And maybe you're right that it doesn't work since mysql views are not good friends with indexing. But still. Is there anything to search for in the shops table?
i learn that views dont work well with indexing so, will it be a big performance hit, for the convenience it may provide?
Upvotes: 35
Views: 26947
Reputation: 143
MySQL views, according to the official MySQL documentation, are stored queries that when invoked produce a result set.
A database view is nothing but a virtual table or logical table (commonly consist of SELECT query with joins). Because a database view is similar to a database table, which consists of rows and columns, so you can query data against it.
Upvotes: 13
Reputation: 1062
According to http://www.mysqltutorial.org/introduction-sql-views.aspx
A database table should not have calculated columns however a database view should.
I tend to use a view when I need to calculate totals, counts etc.
Hope that help!
Upvotes: 3
Reputation: 48048
A view can be simply thought of as a SQL query stored permanently on the server. Whatever indices the query optimizes to will be used. In that sense, there is no difference between the SQL query or a view. It does not affect performance any more negatively than the actual SQL query. If anything, since it is stored on the server, and does not need to be evaluated at run time, it is actually faster.
It does afford you these additional advantages
Upvotes: 24
Reputation: 40685
This mysql-forum-thread about indexing views gives a lot of insight into what mysql views actually are.
Some key points:
Upvotes: 18
Reputation: 21
One more down side of view that doesn't work well with mysql replicator as well as it is causing the master a bit behind of the slave.
http://bugs.mysql.com/bug.php?id=30998
Upvotes: 2