I have a reporting web application that graphs information based on aggregations done in a series of nested sql views (3 levels deep). The last nested view is called from a stored procedure within the entity framework code. The performance penalty of this has begun to take its toll, as it struggles to get data and times out:
In Sql profiler there’s 360,000+ reads and CPU @ 28313. In addition, I can’t even open the third level view in SQL without timing out.
The first view simply gathers data from the several tables and aggregates. The second performs calculations on this data such as date differences, time zone adjustments, and averages. The third finalizing these calculations and presents a summary of the required data. The third view is the one I query from.
What is a good strategy for untangling nested views, in general? Specifically if you have calculations that need to be done in SQL server, but can only be done once data has been combined into a certain level, what’s a better strategy than nested views?
Thanks for any help you can provide!
You can include any view as a subquery, however, I doubt that in itself will help performance in this case. It will enable you to look at parts of the views and possibly put any shared parts into table variables or temporary tables.
If you could share more information, that might help.
I advise you: