Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Materialized Views


Materialized Views

Author
Message
DBABC
DBABC
SSC Veteran
SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)

Group: General Forum Members
Points: 249 Visits: 482
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
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14375 Visits: 9729
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
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: Administrators
Points: 36048 Visits: 18736
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
My Blog: www.voiceofthedba.com
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44994 Visits: 39880
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.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
GSquared
GSquared
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14375 Visits: 9729
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
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)SSC-Forever (44K reputation)

Group: General Forum Members
Points: 44994 Visits: 39880
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. Smile

--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.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Hossam AlFraih
Hossam AlFraih
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 97
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. w00t

But remember, it always depends! ;-)

Good luck.
Patibandla
Patibandla
Valued Member
Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)

Group: General Forum Members
Points: 60 Visits: 178
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.
Patibandla
Patibandla
Valued Member
Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)

Group: General Forum Members
Points: 60 Visits: 178
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..
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24171 Visits: 37936
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.

Cool
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)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search