You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's my first time here, and I'm already posting new features, sorry!.
OK, imagine this scenario:
TABLEA (
ID (PK),
CUSTOMERID,
VLTOTAL,
VLTOTAL1,
VLTOTAL2)
TABLE B (
ID (PK),
IDTABLEA (FK),
IDPRODUCT,
VALUE,
VL1,
VL2)
The fields VLTOTAL1 and VLTOTAL2 of TABLEA are a SUM of VL1 and VL2 from TABLEB grouping by IDTABLEA.
Today I've an application that generate this SUM by trigger on AFTER INSERT of TABLEB, but this consume a lot of CPU, specially in cases that TABLEB have a thousand records. Another reason it's cause we use an script executing to insert several records in TABLEA and, of course, another several records in TABLEB.
Now, if we've an On Transaction Commit Trigger to TABLEB, the SUM would by execute once only in the end of this transaction. The ideia of this type of Triggers is the same as Database Triggers except that can be applied to a specific table.
Maybe, another approach would be an On Before Transaction Commit to use the same transaction isolation level to perform all of the commands. Or might be existis an On After Transaction Commit in case we've to do same operation in another table or another database (in FB 2.5) that's independ of the same transaction.
Thank you.
Daisson.
The text was updated successfully, but these errors were encountered:
Use the AFTER INSERT trigger to set a transaction context variable or temporary table. Read the variable or temp table in the commit trigger and do what you want.
I don't believe that UPDATE TABLE A SET VLTOTAL1=VLTOTAL1+:NEW.VL1, VLTOTAL2=VLTOTAL2+VL2 WHERE ID=:NEW.IDTABLEA can "consume a lot of CPU". Are you sure that you don't do something stupid like full update or MERGE?..
Submitted by: Daisson - JB Software (daissonjb)
Hi everyone.
It's my first time here, and I'm already posting new features, sorry!.
OK, imagine this scenario:
TABLEA (
ID (PK),
CUSTOMERID,
VLTOTAL,
VLTOTAL1,
VLTOTAL2)
TABLE B (
ID (PK),
IDTABLEA (FK),
IDPRODUCT,
VALUE,
VL1,
VL2)
The fields VLTOTAL1 and VLTOTAL2 of TABLEA are a SUM of VL1 and VL2 from TABLEB grouping by IDTABLEA.
Today I've an application that generate this SUM by trigger on AFTER INSERT of TABLEB, but this consume a lot of CPU, specially in cases that TABLEB have a thousand records. Another reason it's cause we use an script executing to insert several records in TABLEA and, of course, another several records in TABLEB.
Now, if we've an On Transaction Commit Trigger to TABLEB, the SUM would by execute once only in the end of this transaction. The ideia of this type of Triggers is the same as Database Triggers except that can be applied to a specific table.
Maybe, another approach would be an On Before Transaction Commit to use the same transaction isolation level to perform all of the commands. Or might be existis an On After Transaction Commit in case we've to do same operation in another table or another database (in FB 2.5) that's independ of the same transaction.
Thank you.
Daisson.
The text was updated successfully, but these errors were encountered: