Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Simple view question regarding indexes Expand / Collapse
Author
Message
Posted Thursday, April 17, 2014 5:36 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, August 28, 2014 6:55 AM
Points: 122, Visits: 188
Do views take advantage of the underlying tables' indexes or does one need to add an index with the view being schema bound?
Post #1562616
Posted Thursday, April 17, 2014 6:23 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 6:24 PM
Points: 23,397, Visits: 32,246
Yes, the queries used to define views will take advantage of the indexes on the underlying tables if they assist in the return of data from those tables.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1562624
Posted Thursday, April 17, 2014 7:32 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, August 28, 2014 6:55 AM
Points: 122, Visits: 188
Thanx. So, what's the advantage of adding an index to a view?
Post #1562649
Posted Thursday, April 17, 2014 7:37 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 4:28 PM
Points: 43,028, Visits: 36,193
If the view has an index, SQL may not need to go to the base tables at all.

Bear in mind there are a massive set of restrictions around indexed views. Not all views can be indexes.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1562656
Posted Thursday, April 17, 2014 9:35 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, August 28, 2014 6:55 AM
Points: 122, Visits: 188
Thanx.
Post #1562724
Posted Thursday, April 17, 2014 2:42 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: 2 days ago @ 12:20 PM
Points: 246, Visits: 661
NineIron (4/17/2014)
Thanx. So, what's the advantage of adding an index to a view?


When you access a non-indexed view, SQL will expand the query that defines the view to access the data that is needed. Let's say you have a view with an aggregation in it. SQL will chug through and re-calculate the aggregation every time you access the view. If you index the view, the aggregation may not need to be recalculated every time.

There are lots of caveats and drawbacks too, but that is one use case.
Post #1562859
Posted Friday, April 18, 2014 4:51 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, August 28, 2014 6:55 AM
Points: 122, Visits: 188
Thanx.
Post #1562963
Posted Friday, April 18, 2014 5:52 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 4:38 AM
Points: 7,211, Visits: 6,353
FYI: Indexed Views don't do well on high-volume insert tables.

I also seem to recall that trying to update the schema of underlying tables used in Indexed Views (WITH SCHEMABINDING) is nigh-on impossible without first dropping the view.


Brandie Tarvin, MCITP Database Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1562978
Posted Friday, April 18, 2014 6:20 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, August 28, 2014 6:55 AM
Points: 122, Visits: 188
Thanx. My environment is basically reporting off of a DataWarehouse so, performance of the report/query is most important. Could I ask..........if the underlying table(s) is not indexed or poorly indexed (I have little control over this), will an indexed view work to speed up performance?
Post #1562989
Posted Friday, April 18, 2014 6:25 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 4:38 AM
Points: 7,211, Visits: 6,353
NineIron (4/18/2014)
if the underlying table(s) is not indexed or poorly indexed (I have little control over this), will an indexed view work to speed up performance?


Yes and no. The problem is that an indexed view uses cached data. So in that respect, yes. But when you have to refresh that data, it's still relying on the underlying tables. Plus it depends on what indexes you put in the view. There are lots of ways to screw up an index and make a query worse. I've done about half of them over the years. @=)

Of course, the best way to know the answer to any "performance saving solution" for sure is to test this in a Dev or sandbox server. See for yourself.


Brandie Tarvin, MCITP Database Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1562994
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse