Question

I'm currently working on a project where maintenance is a major concern. So, naturally the lead designers don't want to have any unnecessary code repeated.

We have some complex Views that query data. No I've been tasked to make another complex View but my instructions are to query from other Views. After noticing some serious speed issues with a copy of Production data, I noticed my View was calling a View which called another View which called another View! (ie: View A references View B which references View C which references View D - in my case every view is a query over tables all within the same database)

While I am aware of the principle of interchangeability in regards to views and tables (ie: there is no distinction between actual relations and virtual relations), but could I expect performance issues? Should I make a view that doesn't reference another view?

Was it helpful?

Solution

Views are expanded before they are executed. There should be no performance penalty for any level of nested views.

If there is performance loss, it might be because the nested views are doing more work than you require. SQL Server can only optimise so far. Especially query hints or forced sort operations like select top 100 percent ... can make a nested query slow.

My advise is to use the most readable, most maintainable alternative. If you encounter performance issues, it's early enough to consider optimising a few views!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top