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

On Indexes and Views Expand / Collapse
Author
Message
Posted Tuesday, September 9, 2008 2:07 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, December 2, 2014 8:26 AM
Points: 775, Visits: 1,203
Oops, didn't know I have to use NOEXPAND to use Indexed Views
all this time I thought when I selected on my view, it used the Clustered Index

Good thing it wasn't slowing anything down


SQLServerNewbie

MCITP: Database Administrator SQL Server 2005
Post #566460
Posted Tuesday, September 9, 2008 3:32 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, December 12, 2014 6:18 PM
Points: 8, Visits: 157
Thank you for an interesting article!
The company I work for is still using SQL Server 2000. I tried the example and it seem like the NOEXPAND just gave an extra overhead to the query. It didn't expand without the tag, and with the tag it took a little bit more resources. Without NOEXPAND total cost was 0.0634, with NOEXPAND it was 0.0642.

My question is if anyone knows the best practice for SQL Server 2000? Shall I use NOEXPAND to be prepared for a possible migration to SQL Server 2005?

Post #566508
Posted Tuesday, September 9, 2008 6:08 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, November 24, 2014 4:29 PM
Points: 752, Visits: 920
lage_bergstrom (9/9/2008)
Thank you for an interesting article!
The company I work for is still using SQL Server 2000. I tried the example and it seem like the NOEXPAND just gave an extra overhead to the query. It didn't expand without the tag, and with the tag it took a little bit more resources. Without NOEXPAND total cost was 0.0634, with NOEXPAND it was 0.0642.

My question is if anyone knows the best practice for SQL Server 2000? Shall I use NOEXPAND to be prepared for a possible migration to SQL Server 2005?



Lage,

All of my testing was on SQL Server 2005 and 2008 (and all my references are specifically for 2005), but I believe the same things apply to 2000, and if you are using something other than Enterprise Edition you likely want to use noexpand where it is appropriate.

As for the time trials, make certain you are testing them in separately and not in a batch, otherwise the caching, execution plan generation, etc will cause one portion to affect the others. When I try running them together in one batch, my results are inconsistent with it coming out faster with the noexpand sometimes and without other times. When I run them separately the one with noexpand comes out slightly, but consistently better. Of course, I kept these sample sizes small, if you increase the table sizes the difference becomes much more marked.

To provide an anecdote, I once reduced a query that was being run routinely from taking over an hour to taking less than a minute by indexing the view and adding with (noexpand). But that was a very large query which needed several joins against large tables.

(edited to correct a typo)


---
Timothy A Wiseman
SQL Blog: http://timothyawiseman.wordpress.com/
Post #566542
Posted Wednesday, September 10, 2008 2:16 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, December 12, 2014 6:18 PM
Points: 8, Visits: 157
Thank you Timothy for your answer. This was really useful.

Lage
Post #566659
Posted Wednesday, October 22, 2008 4:31 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, December 18, 2014 10:22 AM
Points: 914, Visits: 2,051
I would like to use an indexed view in our ERP system (SS 2000 Enterprise) but I'm paranoid because it's a canned system and we don't have the source, I'm afraid that I could break something. I have two areas where performance is routinely very sub-par and I'm certain indexed views would bring performance up to proper levels.

The system has a lot of design problems, but I'm stuck with it, so that's the way it is. I'd probably lose the indexed views whenever they did an upgrade, but recreating them would be a minimal hassle.


-----
Knowledge is of two kinds. We know a subject ourselves or we know where we can find information upon it. --Samuel Johnson
Post #590165
Posted Thursday, October 23, 2008 1:35 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, November 24, 2014 4:29 PM
Points: 752, Visits: 920
It is unlikely that you would break something, though it is possible since it will try to enforce things like unique constraints onto the base tables. Also, schemabinding may prevent schanges to the table schemas which could cause a problem during an upgrade.

The better question is what do they gain you? If you are frequently accessing it through SSMS or if you can change the GUI code so that it can take advantage of the indexed views, then the performance improvements can be extremely impressive. But, if you are primarily accessing the system through a closed source GUI that you cannot direct to take advantage of the indexed view, then it will do you little if any good.

(As a side note, Enterprise edition can use the index on the view if it is useful when you query against the base tables in certain cases, but it does not make a lot of since to create an indexed view with that in mind. If you want to improve access to the base tables themselves, it makes more sense to create the appropriate indexes on them. That is more of an incidental benefit if you are also using the index on the view to access the view.)


---
Timothy A Wiseman
SQL Blog: http://timothyawiseman.wordpress.com/
Post #590290
Posted Thursday, October 23, 2008 9:52 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, December 18, 2014 10:22 AM
Points: 914, Visits: 2,051
Thanks for the reply, Tim. I'd have to research the schema, off-hand I cannot say that all the tables have PKs, clustered or otherwise. I have two specific performance problems, one I can't remember the details of without researching it. The other involves two tables where I need a subset, and because of the table size, a filtered indexed view would (I think) give that report good performance.

In this case, the data is being read by an Access report, not through the GUI, so that concern doesn't apply.


-----
Knowledge is of two kinds. We know a subject ourselves or we know where we can find information upon it. --Samuel Johnson
Post #590565
Posted Wednesday, March 4, 2009 12:47 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, December 5, 2014 2:22 PM
Points: 1,586, Visits: 1,860
Question:

I see the Pros of creating Indexed Views, but what are the Cons? Seems I read somewhere that the materialized view has to exist somewhere. Is that in memory or on a physical disk?
When loading data, will this slow down the load? Can the view be disabled during a load and then reconstructed (I'm sure that's not the best term to use)?

I am in the middle of a debate on whether we go this approach or a different approach. Any input would be greatly appreciated.
Thanks!
Post #668607
Posted Saturday, March 7, 2009 4:18 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, November 24, 2014 4:29 PM
Points: 752, Visits: 920
Carla;

There are definitely numerous design considerations.

First, the view has to be schema bound. This makes it harder to change any objects the view depends on (you have to remove schema binding first, make the change, and then recreate it). In a mature database where the schema rarely changes this is of limited concern of course, but in a newly created database this can become tedious.

Next, as you said, the index has to be stored on disk. Depending on the size of the table and number of columns involved, this can be quite substantial. Also, it will slow down write operations on the tables involved. In most cases, this will not be a substantial amount, but it can be a consideration for tables that receive a lot of updates.

Then, if you are not in enterprise edition, you have to deal with the complexity of the query hints to actually use the index (this is handled by the engine in Enterprise Edition.) Also, it will add complexity if you use replication and both servers are not in Enterprise Edition (the engine in Enterprise edition will handle almost all of it for you, but in Standard Edition you have to do a lot more of it manually).

In many cases, the advantages to using an indexed view will greatly outweigh the disadvantages, but these are all things that must be considered.


---
Timothy A Wiseman
SQL Blog: http://timothyawiseman.wordpress.com/
Post #671022
Posted Monday, March 9, 2009 7:56 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, December 5, 2014 2:22 PM
Points: 1,586, Visits: 1,860
Thanks for the reply.
I did set up a couple for testing, and since we have the Standard edition, I set up some queries with the hints. They worked great, greatly reducing the query time. But you pointed out a couple disadvantages, including the maintenance issues, especially since our database is still evolving. The jury is still out on which way we will go.
Thanks again.
Post #671506
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse