Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL Server
Expertise: Beginner
Apr 7, 1999

Slow view with lots of calculations

Question:
I created a view that does a lot of calculations and references several tables. If I do a

select * from linkview
everything comes up instantaneosly. However, if I do a

select * from linkview where id='12345'
it is mind numbingly slow. Which makes it seem that the problem is not the calculations, but querying the view. I am using SQL server 6.5.

Answer:
I suggest you do the following: Run the query using a straight select statement instead of using a view. So instead of "select from view where ..." combine the SQL statement used to create the view with the clause specifying an id.

If the timing is slow, it means that you don't have the index you need to support the additional limitation (that is, id = '12345'). However, if, in fact, the query runs fine through a select statement but degrades through a view, you are facing a different issue.

I've seen cases where the plan that the Optimizer decides on for a view is not updated when an additional where clause is entered--just as in your case. For that reason, I stopped using views in many cases. To be honest, it might have been fixed in later releases or service packs. I'm not even sure I didn't pick up this prejudice from version 4.2.

The good news is that I verified that version 7 deals with this correctly.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date