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

Trigger order on delete cascade [CORE1541] #797

Closed
firebird-automations opened this issue Oct 26, 2007 · 7 comments
Closed

Trigger order on delete cascade [CORE1541] #797

firebird-automations opened this issue Oct 26, 2007 · 7 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Valdir Stiebe Junior (ogecrom)

Attachments:
trigger order test case.sql

In a master-detail relationship with a cascade delete FK, the detail table before delete trigger can't see the master table record. It looks like the database is in an inconsistent state (a detail without a master record) at this time.

Correct me if I am wrong but the correct trigger order in a cascade delete would be:
1. before delete master
2. before delete detail
3. delete detail
4. after delete detail
5. delete master
6. after delete master

The actual order is:
1. before delete master
2. delete master
3. after delete master
4. before delete detail
5. delete detail
4. after delete detail

@firebird-automations
Copy link
Collaborator Author

Modified by: Valdir Stiebe Junior (ogecrom)

Attachment: trigger order test case.sql [ 10631 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: Smirnoff Serg (wildsery)

I think this is not a bug.
Master must be deleted first 'cause if other transaction inserting details records of same master, it checks FK okay, while you delete only your details, and may commit them.
Your subsequent deletion of master will fail - new details remaining.

@firebird-automations
Copy link
Collaborator Author

Commented by: Valdir Stiebe Junior (ogecrom)

It is the same behaviour as if in a first transaction we insert detail records and in a second transaction we try to delete the master. The "Foreign key references are present for the record" exception is raised.

But I agree that if I first tried to delete the master, this operation must have more priority than the inserts in other transactions.

I've filled this issue because of the trigger order and the visibility of the master record in the before delete detail trigger.

@firebird-automations
Copy link
Collaborator Author

Commented by: @hvlad

It's as designed and not a bug

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Open [ 1 ] => Closed [ 6 ]

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Workflow: jira [ 13349 ] => Firebird [ 13923 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: Philip Williams (unordained)

Is the suggested work-around, then, that rather than relying on on-delete-cascade, you should put a before-delete trigger on the master record which deletes any detail records, thus allowing the detail table's before-delete triggers to still see the master record?

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