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


Costly update trigger -70,000,000 logical reads for 30,000 rows updated!


Costly update trigger -70,000,000 logical reads for 30,000 rows updated!

Author
Message
Marios Philippopoulos
Marios Philippopoulos
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1954 Visits: 3740
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!

__________________________________________________________________________________
SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables
Persisting SQL Server Index-Usage Statistics with MERGE
Turbocharge Your Database Maintenance With Service Broker: Part 2
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47198 Visits: 44367
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, MVP, M.Sc (Comp Sci)
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


Marios Philippopoulos
Marios Philippopoulos
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1954 Visits: 3740
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! Wink

I will set up the trace and post my findings.

__________________________________________________________________________________
SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables
Persisting SQL Server Index-Usage Statistics with MERGE
Turbocharge Your Database Maintenance With Service Broker: Part 2
SwePeso
SwePeso
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2469 Visits: 3431
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"
Marios Philippopoulos
Marios Philippopoulos
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1954 Visits: 3740
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



__________________________________________________________________________________
SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables
Persisting SQL Server Index-Usage Statistics with MERGE
Turbocharge Your Database Maintenance With Service Broker: Part 2
SwePeso
SwePeso
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2469 Visits: 3431
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"
Marios Philippopoulos
Marios Philippopoulos
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1954 Visits: 3740
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?

__________________________________________________________________________________
SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables
Persisting SQL Server Index-Usage Statistics with MERGE
Turbocharge Your Database Maintenance With Service Broker: Part 2
SwePeso
SwePeso
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2469 Visits: 3431
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"
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47198 Visits: 44367
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, MVP, M.Sc (Comp Sci)
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


Marios Philippopoulos
Marios Philippopoulos
SSCommitted
SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)SSCommitted (2K reputation)

Group: General Forum Members
Points: 1954 Visits: 3740
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

__________________________________________________________________________________
SQL Server 2016 Columnstore Index Enhancements - System Views for Disk-Based Tables
Persisting SQL Server Index-Usage Statistics with MERGE
Turbocharge Your Database Maintenance With Service Broker: Part 2
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