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

Materialized Views Expand / Collapse
Author
Message
Posted Wednesday, July 30, 2008 12:31 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, October 31, 2014 12:50 PM
Points: 248, Visits: 477
One of my query is using 4-5 tables using Inner or Left Outer joins.
These tables are the main tables of the Db and contains alot of data. Also multiple user & multiple applications are inserting data in these tables as well. So will a materialized view by joining these 4-5 tables will give any performance benefit? Or it will be even more overhead?



Thanks,
Usman
Post #543805
Posted Wednesday, July 30, 2008 1:03 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Monday, November 17, 2014 12:50 PM
Points: 13,872, Visits: 9,598
It depends.

If you have a lot of selects on certain conditions, then a materialized view based on those conditions can increase performance for those selects.

On the other hand, materialized views, like any index, do slow down insert/update/delete operations.

In many cases, the slight slow-down on those is worth the large speed-up on selects, but this requires doing some research and making sure the view is exactly what you need.

Used correctly, a materialized view can speed up lots of things. Used poorly, they can slow down lots of things.


- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #543842
Posted Wednesday, July 30, 2008 2:23 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 8:25 PM
Points: 31,279, Visits: 15,740
I tend to agree with the views expressed above. It can be a useful tool, if you consider the load on your system for Ins/Upd/Del






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #543903
Posted Wednesday, July 30, 2008 7:44 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 11:20 PM
Points: 35,552, Visits: 32,148
usman.tanveer (7/30/2008)
One of my query is using 4-5 tables using Inner or Left Outer joins.
These tables are the main tables of the Db and contains alot of data. Also multiple user & multiple applications are inserting data in these tables as well. So will a materialized view by joining these 4-5 tables will give any performance benefit? Or it will be even more overhead?

Thanks,
Usman


I believe that a materialized view will cause you a world of hurt in this particular case because of all the inserts you say you'll be doing.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #544016
Posted Monday, August 4, 2008 7:56 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Monday, November 17, 2014 12:50 PM
Points: 13,872, Visits: 9,598
Jeff Moden (7/30/2008)
usman.tanveer (7/30/2008)
One of my query is using 4-5 tables using Inner or Left Outer joins.
These tables are the main tables of the Db and contains alot of data. Also multiple user & multiple applications are inserting data in these tables as well. So will a materialized view by joining these 4-5 tables will give any performance benefit? Or it will be even more overhead?

Thanks,
Usman


I believe that a materialized view will cause you a world of hurt in this particular case because of all the inserts you say you'll be doing.


It depends. It will slow down the inserts, but if those are generally single-table, single-row inserts, the performance hit on that might be negligible. What isn't mentioned is what queries the view will be supporting.

Even with lots of inserts, you can still have a net gain if you have a lot of complex queries that are called frequently.

I've even had a net gain in insert speed in one case, because of an indexed view that was used by those inserts (Insert...Select). Slowed down the insert part, but gained even more from the select part. (Supported complex business rules in an upsert situation.) Went from 600 ms to 40 ms on a common transaction in that database.


- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #546102
Posted Monday, August 4, 2008 7:33 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 11:20 PM
Points: 35,552, Visits: 32,148
Actually, Gus' answer is the best answer... "It depends". This is the kind of thing that you need to test.

Gus, good point about the net gain on things like Insert/Select. :)


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #546458
Posted Tuesday, April 12, 2011 7:00 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Sunday, August 10, 2014 2:10 PM
Points: 12, Visits: 91
Indexed Views will helps by pre-computing aggregations and store them in the index. Moreover, joining tables can be pre-join and results data can be stored.
This can speed up your queries by approx. 50-75% in general.

But remember, it always depends!

Good luck.
Post #1092039
Posted Tuesday, August 21, 2012 5:41 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, November 4, 2014 4:28 AM
Points: 53, Visits: 169
It is truly not suggestible to use an Indexed View when the tables are highly transactional as you mentioned. But if the priority is reporting then you can use the materialized views with NOLOCK on the Tables.
Post #1347724
Posted Tuesday, August 21, 2012 5:47 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, November 4, 2014 4:28 AM
Points: 53, Visits: 169
Rather you should keep in mind that you will not be allowed to do any properties that affect the deterministic nature of an indexed view like full-text predicates or references to other views aggregation operations etc..
Post #1347726
Posted Tuesday, August 21, 2012 8:16 AM


SSC-Insane

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

Group: General Forum Members
Last Login: Today @ 4:21 AM
Points: 20,801, Visits: 32,723
I am going to join in with the "It depends" group. You need to test if a materialized view is going to help or not. There really is no definative answer here.

Test it, and let us know if it helped or hindered you in this situation.



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 #1347817
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse