Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Nested View Performance

Author  Topic 

Ixalmida
Starting Member

4 Posts

Posted - 2009-10-26 : 14:43:27
I am trying to optimize a complex nested view. I'm using a nested view mainly to avoid building one big, complex query. But the views are really only 2 levels deep - a top-level view joined to seven secondary, table-based views. Each of the table-based views takes a few seconds to run, but the top-level view often times out.

I need to find a way to improve the performance of my nested views. My questions below are based on what I suspect might be causing the performance issues:

1) Should I put a repeated WHERE clause in every view, in only one view, or only in the top-level view? For example, the non-indexed text fields "Company_Code" and "Job_Number" contain many irrelevant values that I have to eliminate, but these fields bind all the views together. So the following conditions apply to every view I use:

WHERE (Company_Code LIKE '[UC]0[12]') AND (Job_Number NOT LIKE '%[CW]%') AND (Job_Number NOT LIKE '%MAST%') AND
(Job_Number NOT LIKE '%TEST%')
** (Note: I cannot eliminate the leading % signs because the number of leading characters may vary.)

2) Would it improve the execution plan if I just eliminate all the secondary views and integrate all the sub-queries into a single view?

Thanks for any help you can give me.
   

- Advertisement -