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 «««1234»»

Costly update trigger -70,000,000 logical reads for 30,000 rows updated! Expand / Collapse
Author
Message
Posted Monday, February 2, 2009 4:24 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, November 20, 2014 10:24 AM
Points: 1,865, Visits: 3,620
GilaMonster (2/1/2009)
RBarryYoung (2/1/2009)
But Marios should be able to get the Actual from Profiler or tracing, right?


Yes, absolutely. Providing he traces the correct event. I seem to recall there are about 6 events relating to the exec plan and I can't recall offhand which produces what. BoL should say.


Looks like running a trace will get me what I'm looking for, ie. the actual exec plan.

I will do so and post my findings.

Thanks guys!


__________________________________________________________________________________

Turbocharge Your Database Maintenance With Service Broker: Part 2
Turbocharge Your Database Maintenance With Service Broker: Part 1
Real-Time Tracking of Tempdb Utilization Through Reporting Services
Monitoring Database Blocking Through SCOM 2007 Custom Rules and Alerts
Preparing for the Unthinkable - a Disaster/Recovery Implementation
Post #647913
Posted Monday, February 2, 2009 6:17 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 2:57 AM
Points: 40,618, Visits: 37,085
Marios Philippopoulos (2/2/2009)

Wow, that was something I didn't know, but makes sense the way you put it.

Not that I don't believe you, but can you post a link that mentions this?


I don't have one offhand (and I'm sitting at the airport), but it's easy to check. Open the exec plan, find any joi, seek or scan operator and look at the tooltips. If you see things like 'Actual rows', 'Actual IO cost', etc then it's an 'actual' plan with run-time information. If you don't then it's essentially an estimated plan.

Not on this exactly, but - http://sqlinthewild.co.za/index.php/2007/09/04/execution-plans-estimated-vs-actual/



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #647957
Posted Monday, February 2, 2009 7:57 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, November 20, 2014 10:24 AM
Points: 1,865, Visits: 3,620
GilaMonster (2/2/2009)
Marios Philippopoulos (2/2/2009)

Wow, that was something I didn't know, but makes sense the way you put it.

Not that I don't believe you, but can you post a link that mentions this?


I don't have one offhand (and I'm sitting at the airport), but it's easy to check. Open the exec plan, find any joi, seek or scan operator and look at the tooltips. If you see things like 'Actual rows', 'Actual IO cost', etc then it's an 'actual' plan with run-time information. If you don't then it's essentially an estimated plan.

Not on this exactly, but - http://sqlinthewild.co.za/index.php/2007/09/04/execution-plans-estimated-vs-actual/


I just looked at the Index-seek operator that accounts for 86% of the total workload of the exec plan I posted (2nd post in this thread) and it only lists Estimated values.

I'm sold! ;)

I will set up the trace and post my findings.


__________________________________________________________________________________

Turbocharge Your Database Maintenance With Service Broker: Part 2
Turbocharge Your Database Maintenance With Service Broker: Part 1
Real-Time Tracking of Tempdb Utilization Through Reporting Services
Monitoring Database Blocking Through SCOM 2007 Custom Rules and Alerts
Preparing for the Unthinkable - a Disaster/Recovery Implementation
Post #648044
Posted Monday, February 2, 2009 8:03 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, October 28, 2014 11:02 AM
Points: 2,397, Visits: 3,419
No need to check for UPDATE, DELETE or INSERT.
Trigger is designed for UPDATE.

Also, the trigger is nesting itself by updating the table for which the trigger ís triggering on...

Use this

CREATE TRIGGER [dbo].[TG_U_UpdTable]
ON [dbo].[UpdTable]
AFTER UPDATE
AS

IF UPDATE(db_updateDate) OR UPDATE(db_updateBy)
RETURN

UPDATE d
SET d.db_updateDate = GETDATE(),
d.db_updateBy = SYSTEM_USER
FROM dbo.UpdTable AS d
INNER JOIN inserted AS i ON i.UpdTableOID = d.UpdTableOID



N 56°04'39.16"
E 12°55'05.25"
Post #648050
Posted Monday, February 2, 2009 8:22 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, November 20, 2014 10:24 AM
Points: 1,865, Visits: 3,620
Peso (2/2/2009)
No need to check for UPDATE, DELETE or INSERT.
Trigger is designed for UPDATE.

Also, the trigger is nesting itself by updating the table for which the trigger ís triggering on...

Use this

CREATE TRIGGER [dbo].[TG_U_UpdTable]
ON [dbo].[UpdTable]
AFTER UPDATE
AS

IF UPDATE(db_updateDate) OR UPDATE(db_updateBy)
RETURN

UPDATE d
SET d.db_updateDate = GETDATE(),
d.db_updateBy = SYSTEM_USER
FROM dbo.UpdTable AS d
INNER JOIN inserted AS i ON i.UpdTableOID = d.UpdTableOID


Thanks for the suggestion, yes, the code that checks for type of DML is redundant.

Can you explain what the following does though, it's not clear to me:

IF UPDATE(db_updateDate) OR UPDATE(db_updateBy)
RETURN



__________________________________________________________________________________

Turbocharge Your Database Maintenance With Service Broker: Part 2
Turbocharge Your Database Maintenance With Service Broker: Part 1
Real-Time Tracking of Tempdb Utilization Through Reporting Services
Monitoring Database Blocking Through SCOM 2007 Custom Rules and Alerts
Preparing for the Unthinkable - a Disaster/Recovery Implementation
Post #648065
Posted Monday, February 2, 2009 8:28 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, October 28, 2014 11:02 AM
Points: 2,397, Visits: 3,419
The trigger is updating the same base table on where the trigger is resided.
So when the trigger updates the two columns, the same trigger is fired again!
And again.. And again...



N 56°04'39.16"
E 12°55'05.25"
Post #648070
Posted Monday, February 2, 2009 8:45 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, November 20, 2014 10:24 AM
Points: 1,865, Visits: 3,620
Peso (2/2/2009)
The trigger is updating the same base table on where the trigger is resided.
So when the trigger updates the two columns, the same trigger is fired again!
And again.. And again...


Wow, would the trigger feed on itself that way? I hadn't thought of that...

How many iterations would that involve?


__________________________________________________________________________________

Turbocharge Your Database Maintenance With Service Broker: Part 2
Turbocharge Your Database Maintenance With Service Broker: Part 1
Real-Time Tracking of Tempdb Utilization Through Reporting Services
Monitoring Database Blocking Through SCOM 2007 Custom Rules and Alerts
Preparing for the Unthinkable - a Disaster/Recovery Implementation
Post #648080
Posted Monday, February 2, 2009 9:50 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, October 28, 2014 11:02 AM
Points: 2,397, Visits: 3,419
Normally the SQL Server thinks 32 is the limit and stops execution with an error.
See Books Online for Nested Triggers and Recursive Triggers.



N 56°04'39.16"
E 12°55'05.25"
Post #648144
Posted Monday, February 2, 2009 10:23 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 2:57 AM
Points: 40,618, Visits: 37,085
Marios Philippopoulos (2/2/2009)

Wow, would the trigger feed on itself that way? I hadn't thought of that...


That's only possible if recursive triggers are enabled. It's a database-level option and it's disabled by default.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #648175
Posted Monday, February 2, 2009 10:48 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, November 20, 2014 10:24 AM
Points: 1,865, Visits: 3,620
GilaMonster (2/2/2009)
Marios Philippopoulos (2/2/2009)

Wow, would the trigger feed on itself that way? I hadn't thought of that...


That's only possible if recursive triggers are enabled. It's a database-level option and it's disabled by default.


I ran the following on the db in which the trigger resides and confirmed that recursive triggers is indeed turned off at the database level

EXEC sp_dboption 'myDB', 'recursive triggers'

However, the nested triggers setting is turned on at the server instance level. What is the difference between the 2 settings, apart from the scope in which they operate?

EXEC sp_configure 'nested triggers'

Returns:

config_value: 1
run_value: 1


__________________________________________________________________________________

Turbocharge Your Database Maintenance With Service Broker: Part 2
Turbocharge Your Database Maintenance With Service Broker: Part 1
Real-Time Tracking of Tempdb Utilization Through Reporting Services
Monitoring Database Blocking Through SCOM 2007 Custom Rules and Alerts
Preparing for the Unthinkable - a Disaster/Recovery Implementation
Post #648202
« Prev Topic | Next Topic »

Add to briefcase «««1234»»

Permissions Expand / Collapse