Solved

SQL Server - How to tune insert/update/delete on very active Tables

Posted on 2013-11-22
6
424 Views
Last Modified: 2014-02-06
Hi All,
I have some really active tables mainly with insert/update running against them.
There are lots of waits and as a result I often come across Deadlock. Once application hit deadlocks it often crashes some processes and I have to manually run those transactions. It's a pain.

How do I tune insert/update/delete so that these waits are gone for good.

Thanks
0
Comment
Question by:crazywolf2010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 39668605
so are your deadlocks in general caused by the applications waiting for resources across tables or within single tables?

userA    update TableA    wants to update tableB

userb    updated tableB  wants to update tableA

or

userA   update tableA row1   wants to update another tableA row2

userb   updated tableA row2  is still doing processing...


or is it normally more complex with with more than 2 users/connections involved?

in general
you may be able to change the clustering/partitioning  indexes to reduce contention if its page locks which are creating the problems...

you maybe able to influence the program design so that (in general) Table A is always updated before TableB

you may find that adding a logical deleted status column , instead of actually doing a DELETE (ie a delete becomes an UPDATE) will assist as DELETES are (usually) much more expensive than updates... (and run the physical delete in a batch period...)


the other standard TUNING mechanic apply ... ensure that the SQL actually needs to be performed... ensure that code delay between sql statements is minimised...
look to tune the actual statements usually involved...

e.g..

        update   row1

        select something
        insert something

         update row 2


ccould that be changed
   to
select something

update row1
 insert something
update row2

so that the lock for row1 is minimised....
0
 

Author Comment

by:crazywolf2010
ID: 39668636
Hi,
I think I forgot to add my attachment report for Tables. Could you have a look and comment how do I optimise these tables?
ActiveSQL.txt
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 39668703
its not clear what your report is actually showing...

the only comment i can make is that you appear to have 2 updates consecutively for the same table (and same basic row id...)

UPDATE NmsBroadLogRcp

could the updates  be combined into one statement and the actual
updated columns be specified by case statements in the set conditions...
*ie  move the selectivity from the where clause into case statement on the set condition

that could reduce the workload... (alternatively it could increase it if the set of rows affected significantly increases...)
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 8

Expert Comment

by:gpizzuto
ID: 39668824
You can queue the requests by creating a table in wich your requests are saved and then, execute each command one at a time...
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 39669060
How many indexes you have on that table. Keep in mind that every time you insert/update/delete all the indexes have to be updated which leads to a lot of extra work. I would recommend you to limit the indexes at a strict minimum.

Another thing is if you are running selects against that table you should use (nolock) hint:

select * from yourtable t (nolock)

or in inner join:

select
      *
from
      yourtable t (nolock)
      inner join anothertable a (nolock)
            on a.fk_col=t.pk_col
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 39669283
By far the single best tuning is to get the correct clustered index; do that FIRST.

Then you can work on/worry about other things.

Based on the extremely limited number of queries posted so far, I'd suggest verifying that:
NmsBroadLogRcp is clustered on iBroadLogId


Btw, I'd avoid using any logical delete flags, as they usually destroy SELECT performance and aren't necessary for large DELETEs anyway, since SQL itself automatically defers those physical DELETEs until later.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question