![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Would it be better if we just bit the bullet and moved both out of the trigger to a stored procedure which was called by each of the SPs which writes to the client table? Although this would mean that we could mistakenly bypass validation and processing, if it led to significant performance problems, it would be worth it. |
#3
| |||
| |||
|
|
I'm working on a fairly well established piece of software consisting of a SQL 2000 database which is accessed by a Windows application and a couple of web sites. All business logic etc. is implemented by the database. It started off as a fairly simple application with a small number of concurrent users. It has now grown in to a more complicated one with many concurrent users and we are having the inevitable performance problems - principally, slowness and locking. These performance problems are mainly confined to the handling of certain entities, such as clients, by the system. When a new client etc. is added or an existing one modified, we have to do the following tasks: - Validation - Processing Both of these steps require a lot of SQL to be run and I don't think there's any way to avoid this. However, perhaps the manner in which it is run could be improved? Currently, the validation and processing are both done in triggers on the client table - this approach was initially chosen so that the code could be centralised and run no matter what was making the change (i.e. stored procedures called by the Windows application or any of the web sites). One option might be to do some of the tasks asynchronously. However, the validation has to be done at the time the change is being made so that the user can be informed of any problems, and doing the processing at a later time raises all manner of difficult problems. I was therefore wondering if the fact that the validation and processing tasks are both done in the client table's trigger would be causing performance problems. Would it be better if we just bit the bullet and moved both out of the trigger to a stored procedure which was called by each of the SPs which writes to the client table? Although this would mean that we could mistakenly bypass validation and processing, if it led to significant performance problems, it would be worth it. I've just about run out of idea, so any suggestions or guidance would be very gratefully received. Thanks very much in advance. |
#4
| |||
| |||
|
|
I assume you've already don't due diligence in SQL query and index tuning but you should consider turning on the READ_COMMITTED_SNAPSHOT database option. This might improve concurrency. |
|
Would it be better if we just bit the bullet and moved both out of the trigger to a stored procedure which was called by each of the SPs which writes to the client table? Although this would mean that we could mistakenly bypass validation and processing, if it led to significant performance problems, it would be worth it. I agree it generally best to avoid the triggers from both a performance and concurrency perspective. You'll have the same risk of bypassing rules if you move the business logic to the middle tier. I assume you've already don't due diligence in SQL query and index tuning but you should consider turning on the READ_COMMITTED_SNAPSHOT database option. This might improve concurrency. -- Hope this helps. Dan Guzman SQL Server MVP http://weblogs.sqlteam.com/dang/ |
#5
| |||
| |||
|
|
He is running SQL Server 2000.... |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
So you're saying that the same processing (obviously achieved in slightly different ways) will run faster in a stored procedure than in a trigger? What are the reasons for this? Is it anything to do with not running code within the implicit transaction of an insert / update statement? |
|
I did read somewhere that there might be a problem with the time taken to compile code in triggers compared to SPs. |
|
Thanks for the replies. Yes, we have tuned indexes, prefixed everything with "dbo", not interleaved DDL and DML operations, split large SPs in to smaller ones, got rid of cursors where possible, used unique and check constraints instead of code where possible, done some careful denormalisation, implemented and used a tally table, added WITH (NOLOCK) to carefully selected SPs, minimised use of views, SET NOCOUNT ON everywhere, and turned all knobs to 11. As for READ_COMMITTED_SNAPSHOT, we're still on SQL 2000 unfortunately. So you're saying that the same processing (obviously achieved in slightly different ways) will run faster in a stored procedure than in a trigger? What are the reasons for this? Is it anything to do with not running code within the implicit transaction of an insert / update statement? I did read somewhere that there might be a problem with the time taken to compile code in triggers compared to SPs. Thanks again. |
![]() |
| Thread Tools | |
| Display Modes | |
| |