I am writing a query that basically pulls multiple columns from multiple views. Is it better to index each views for faster performance?
query i.e. A to G are views
SELECT A.C1, B.C1
FROM A INNER JOIN B on A.C3=B.C3
Inner join C on C.C2 = B.C2
inner join D on D.C4 = C.C4
...
Inner join H ON H.C5 = G.C5
where <some condition>
Each views (A to H) are pulling data from different tables. None of the views are indexed (I don’t see anything when I expand the INDEX folder within the view’s tree). Should I add index in each of these views for faster performance? If so, should I add index on the columns I am using for ON JOIN clause?
Thank you
First, enable the “Include Actual Execution Plan” and run your query to see where the performance hit is. Look for “Table scan” as a possible culprit.
If nothing obvious is found, try Query -> “Analyze query in database engine tuning advisor”. SQL server will suggest some indexes to add. Don’t just apply them all but compare against the existing queries to make sure you aren’t adding too much overlap.
As nkj said, optimze queries on tables before indexing the views.