• Just another strange thing happening with the triggers on the database....

    The GCP_VND_ActualizaDocumentoVenda_LinhasDocStatus procedure has an INSERT on a table that has a trigger.

    I start a server trace on the SP to monitor what's going on the database and get this:

    INSERT INTO [dbo].[LinhasDocStatus] ([IDLinhasDoc], [Quantidade], [QuantReserv], [QuantTrans], [EstadoTrans], [Fechado]) SELECT [ID], [QT], [QTR], [QTS], [ET], [FE] FROM [dbo].[#TmpLinhas] WHERE ([EBD] = 2 OR ([EBD] = 3 AND @bitDocNovo = 1))

    This statement takes 248ms to execute...

    The trigger code "fired" by the INSERT has an IF EXISTS with a SELECT and two UPDATE...

    * IF with SELECT: 0,169ms

    * UPDATE: 1,071ms

    * UPDATE: 7,287ms

    The SUM from the trigger time is way less than the time the INSERT says it takes to execute..

    So I disabled the trigger to see how long would the INSERT execute just by itself.... 13,39ms!!!

    So, math made, the INSERT 13,39ms + SUM(Trigger) 9ms gives 23ms... but the INSERT with the trigger takes 248ms.. 10x more...

    Can anyone tell me how to figure what's going on the database?!

    The scenarios are the same on both cases since I restore the database and do an index rebuild and statistics update every time and clear the cache and buffers...

    Thanks,

    Pedro



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