7

I wonder whether sql server calculate views every time when someone query the views. It is because everytime I query the views, it take such a long time.

And when I tried to shorten the time by selecting only top 10 rows from the view, it takes the same amount of time. I suspect sql server need to calculate the view for the whole table even if I only want a few rows from the view, am I right?

6

Yes, a view is just a macro (unless indexed). The behaviour is well known.

See Tony Rogerson's article. You can see it yourself in the query plans too. The view doesn't exist on the query plan because it can't exist as a macro

Also note the "Predicate Pushing" phenomenon when you filter or TOP on views

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.