Does SQL Server expand a view's sql inline during execution? -
let's have (hypothetical) table called table1 500 columns , there view called view1
select column1, column2,..., column500, computedorforeignkeycolumn1,... table1 inner join foreignkeytables ..... now, when execute
select column32, column56 view1 which 1 of below 3 sql server turn into?
query #1:
select column32, column56 (select column1, column2,..., column500, computedorforeignkeycolumn1,... table1 inner join foreignkeytables ......) v query #2:
select column32, column56 table1 query #3:
select column32, column56 (select column32, column56 table1) v the reason i'm asking have wide table , view sitting on top of (that inner joins bring texts foreign key ids) , can't figure out if sql server fetches columns , selects ones needed or fetches needed (while ignoring unnecessary joins etc)...if former view not best performance.
sql server query compilation can split phases:
- parsing
- binding
- optimization
view resolution performed during binding. @ stage view reference replaced definition. @ point, unused view columns present.
the next stage optimization, bound syntax tree transformed execution plan. optimizer considers many kinds of manipulations on execution plan increase efficiency, , removing unused columns 1 of basic. @ point, unused column references removed.
so answer question, unused columns in view definition will not impact performance, since optimizer smart enough remove them.
note: answer assumes view not indexed. indexed views, resolution process works differently, , there view maintenance overhead updates of base tables.
Comments
Post a Comment