• Hi,

    Just added an Excel file with the full trace with the original trigger and the changed trigger (that should be faster, and in "simple" UPDATE tests to the table it is much, much faster).

    I also added a 3rd sheet with a side by side comparison of the code I find strange...

    The statement UPDATE AA SET QtReservada = 0 FROM Inserted I INNER ... executes inside a trigger and fires another trigger, I don't know if this might be the problem source (trigger inside triggers is badddd).

    But the truth is that with the slow ArtigoArmazem trigger (the 1st on the SQL script attachment) it's much faster than the improved trigger (2,25ms vs 55,7ms).

    So I made a test... I changed the new trigger and added a RETURN statement right at the top.... same result...

    The I removed the rest of the trigger code, just left the RETURN... fast again....

    Does SQL have an issue with the WITH statement or something??! I made a test and removed the WITH and replaced it with a subquery but still slow...

    It's the same database, I just keep changing the trigger code and executing the traces so nothing to do with indexes, or whatever... Statistics are updated, indexes full rebuild...

    What can be causing this issue with the triggers?!

    Further on the trace the trigger is used again and the new one is faster with less reads, since it's used... In this case it's used but does nothing since the StkActual column isn't updated...

    Thanks,

    Pedro



    If you need to work better, try working less...