Reputation: 167
Every bit of literature I've found on this topic suggests that the advantage of using views lies in how much cleaner it makes the code. What I'd like to know is if I fire multiple selects one after the other, will the latency (Apache to MySQL to Apache multiple times) be significantly higher than using a complicated view. I have a scenario where I can take one of two approaches:
What would help me deliver pages faster to my users?
Any help based on actual observation or proven documentation will be welcome.
Thanks.
SR
Upvotes: 2
Views: 6950
Reputation: 5397
Views don't modify the performance of your database. The performance is the same as the select it includes. The views are not used to increment performance or deliver pages faster, they are used for two things:
Upvotes: 10
Reputation: 142208
It depends.
On the one hand, 90% of a simple query is in the overhead (communication, parsing, etc). So, fewer roundtrips to the server is better.
On the other hand, a query (with or without VIEWs
) that is too complex may do things less efficiently than you could do by breaking it down into simple steps.
I say VIEWs
are syntactic sugar, not a performance benefit. (@nacho says it better.)
I have built many complex pages, with, say, 40 queries in it. Performance is decent. I locate any "slow" queries (the SlowLog is handy for this), then optimize them.
I also find it better to build a page with extra info on it, rather than forcing the user to click on something to bring up another page. That is, doubling the number of SELECTs
(costing of a few milliseconds) can lead to a better UI.
Upvotes: 3