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


How to improve insert performance


How to improve insert performance

Author
Message
kokila-416295
kokila-416295
Grasshopper
Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)

Group: General Forum Members
Points: 19 Visits: 255
Dear all,

We are facing performance problem in inserting into table.

Detail

Table Size: 2 GB
Index: cluster index on identity column, three non cluster index
index size: 3 GB
cluster index insert
row count:38968909

the insert statement is part of the procedure and the proc is executed by multiple users simultaneously. And CPU utilization is reaching 100% and SOS_Scheduler_yield wait type is occurring.

Particularly the insert statement in the procedure is costing 203%

Please provide your valuable suggestion and it would be greate if any body explain how insert will work againts the table which is having no of cluster and noncluster index

Thanks
kokila k
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45145 Visits: 39923
When is the last time you did any maintenance on the indexes of the table?

--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
Jody Claggett-376930
Jody Claggett-376930
Valued Member
Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)Valued Member (58 reputation)

Group: General Forum Members
Points: 58 Visits: 199
1. Make sure your stored procedure is not recompiling every time it is run. (RECOMPILE = ON).

2. Check the index fragmentation using sys.dm_db_index_physical_stats.

3. Check out this post on that wait type http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=790196&SiteID=1.

4. I assume you know what the stored proc is doing, but just in case run a Profiler trace to get an idea of the processes being executed.

_______________________________
[size="5"]Jody Claggett
SQL Server Reporting Analyst
[/size]
TheSQLGuru
TheSQLGuru
SSCertifiable
SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)

Group: General Forum Members
Points: 5970 Visits: 8313
Table Size: 2 GB
Index: cluster index on identity column, three non cluster index
index size: 3 GB
cluster index insert
row count:38968909


Soooo, you have just 2GB of data yet 3 NC indexes total up to 3GB? Did you perchance use DTA and now you have 3 indexes which each have 50-75% of the columns in the table included in them??

Best,

Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru at GMail
James Horsley
James Horsley
SSC-Enthusiastic
SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)

Group: General Forum Members
Points: 163 Visits: 451
In addition to the other posts you will always have a "hotspot" on the last data page of a clustered index on and identity column - this is because the data pages and last clustered index pages of a table with a clustered index are the same. Because the ID's increment the next row inserted will always end up being inserted to the last data page of the index - so there is a lot of contention for that data page.

It may be better to have a different index as the clustered index - obviously this might hurt performance elsewhere so it would require testing and a lot more info re data - but e.g. if you could cluster on say a user identifier column in the table then the contention for the clustered index page would only be against the same user's inserts.

Also remember that though indexes are good for lookup they will always hurt insert performance - so carefully examine the other indexes on the table to see if they are optimal




James Horsley
Workflow Consulting Limited
Richard Fryar
Richard Fryar
SSC Veteran
SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)SSC Veteran (289 reputation)

Group: General Forum Members
Points: 289 Visits: 1171
Check for an insert trigger.

I've seen ridiculously inefficient triggers resulting in high CPU and IO.


Check Your SQL Servers Quickly and Easily
www.sqlcopilot.com
TheSQLGuru
TheSQLGuru
SSCertifiable
SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)SSCertifiable (6K reputation)

Group: General Forum Members
Points: 5970 Visits: 8313
Richard Fryar (9/2/2008)
Check for an insert trigger.

I've seen ridiculously inefficient triggers resulting in high CPU and IO.


That is indeed a good one, Richard, and one that is often simply overlooked!

Best,

Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru at GMail
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45145 Visits: 39923
James Horsley (9/2/2008)
It may be better to have a different index as the clustered index - obviously this might hurt performance elsewhere so it would require testing and a lot more info re data - but e.g. if you could cluster on say a user identifier column in the table then the contention for the clustered index page would only be against the same user's inserts.


If you decide to do that, pick a nice low FILL FACTOR or the page splits will be even more painfull than the hot spot.

--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
James Horsley
James Horsley
SSC-Enthusiastic
SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)

Group: General Forum Members
Points: 163 Visits: 451
If you decide to do that, pick a nice low FILL FACTOR or the page splits will be even more painfull than the hot spot.


Indeed.




James Horsley
Workflow Consulting Limited
Ray Mond
Ray Mond
Old Hand
Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)Old Hand (347 reputation)

Group: General Forum Members
Points: 347 Visits: 1542
You could also check the growth rate that's set for your data and log files. If it's too small (e.g. in 10 MB increments), the insert will take longer than necessay due to the need to constantly grow the files.

Also, here's another view on using identity columns for the clustered index.

Ray Mond
Get a SQL Size 2.0 single-instance license for FREE
Claim one here!
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