Click here to Skip to main content
15,883,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on a summary (some sort of simple reporting of data) to help me explain my customers how much time I've spent in the different parts of the projects I work in.

I need to be able to filter the existing data, to show the amount of hours of each kind I've worked in each week/month/year while the project was on...

I've thought of a big (for me that I'm not used to it +/- 80 lines) SQL clause that prepares all the data, but then I'm having problems to filter it at will, so I've thought of creating a view using that SQL clause and then filter it afterwards.

And then the other question appeared... is it faster to have views ready or making the query every time?

What I have tried:

Nothing, just asking for some information...
Posted
Updated 21-Jun-20 16:34pm

1 solution

Short: A View can cache the results if you apply an index for future queries which leads to improved performance for subsequent requests. Otherwise, a View is just an alias for regular-SQL query.

Check out these posts to understand why a View is faster than a plain-SQL query:
sql - Is a view faster than a simple query? - Stack Overflow[^]
database - Performance of VIEW vs. SQL statement - Stack Overflow[^]
indexing - How do I get MySQL to use an INDEX for view query? - Stack Overflow[^] (definitely read this one!)

It all boils down to whether the View you are creating/using/executing is being indexed or not. If you are not using any indexes, and are plain-old-executing the query, then a View is likely to be an alias for the SQL query, only. The performance part comes, when you handle the indexes on the view and let MySQL reuse the results from previous queries.
 
Share this answer
 
v2
Comments
Joan M 22-Jun-20 8:07am    
Thanks for this answer, it's more or less what I imagined, but nice to see it confirmed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900