1

Is there performance reasons to use views?

I realize this answer might be different per database. I'm using MS SQL but am curious about any database really. Does a view in general cause a performance optimization over its raw sql query equivalent?

Only thing I can think of is the select string size itself sent to the server... which is almost never a factor that anyone cares about.

3
  • Check the execution plan. But in general, there shouldn't be a difference
    – user1822
    Commented Apr 15, 2017 at 11:56
  • ok sql server for example won't be able to pre-compile the statement or something to make it faster? Commented Apr 15, 2017 at 11:59
  • @NicholasDiPiazza, views are not pre-compiled. Views are generally just an encapsulation of a SQL statement but can be materialized by created an index on a view. Use caution with nested views as those are more difficult for SQL server to optimize.
    – Dan Guzman
    Commented Apr 15, 2017 at 12:09

1 Answer 1

4
  1. Creating view will not give you any performance gain but may help you with abstraction of underlying object and management of object level security for your users.
  2. Using Index view can definitely help you by preparing data (aggregate, computation etc) before hand but you need to be careful as explained in detail here.
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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