Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Transaction Commit Triggers to specific Table [CORE4019] #4350

Closed
firebird-automations opened this issue Dec 28, 2012 · 5 comments
Closed

Comments

@firebird-automations
Copy link
Collaborator

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.

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

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.

@firebird-automations
Copy link
Collaborator Author

Commented by: @aafemt

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?..

@firebird-automations
Copy link
Collaborator Author

Commented by: Daisson - JB Software (daissonjb)

Thank you Adriano, that seems a very good ideia. I'll test it. Thanks.

@firebird-automations
Copy link
Collaborator Author

Modified by: Sean Leyne (seanleyne)

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant