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

Reduce use of foreign key constraints and depend more heavily on BlockNo #1223

Merged
merged 4 commits into from
Aug 18, 2022

Conversation

erikd
Copy link
Contributor

@erikd erikd commented Aug 9, 2022

No description provided.

@erikd erikd requested a review from kderme as a code owner August 9, 2022 08:52
@erikd erikd force-pushed the erikd/no-foreign-keys-does-this-work-3 branch from b81c61f to 42e98a5 Compare August 9, 2022 21:29
While testing it was found that if all foreign key constraints were
removed from the generated schema migrations, total chain sync time
on mainnet dropped from 6 days to a little over 3 days.

These constraints do very little to improve data integrity of the data
in the database because they are already checked in Haskell land. They
can therefore be dropped.

The Haskell land code will however need to be modified/updated to work
around the lack of these constraints. For example removing these
foreign key constraints means that `OnDeleteCascade` will no longer
work and will therefore have to be done manually. This is a small price
to pay for the sync speed improvements.
@erikd erikd force-pushed the erikd/no-foreign-keys-does-this-work-3 branch from 42e98a5 to beabf9a Compare August 10, 2022 21:26
erikd added 3 commits August 18, 2022 17:11
Needed to drop the reliance of foreign key constraints because their
use forced PostgreSQL to validate the foreign keys before the data
was inserted. Therefore using `BlockNo` should result in faster data
insertion into the database.

This also required massive changes across most of the code base.

Closes: #1082
Rollbacks are now done on the `block_no` field, so adding indicies for
this field in all tables should help improve rollback speed.
These got reintroduced by mistake when rebasing against master.
They have all be replaced with explicit delete statements.
@erikd erikd force-pushed the erikd/no-foreign-keys-does-this-work-3 branch from beabf9a to 58147d5 Compare August 18, 2022 07:11
@erikd erikd changed the title Reduce use of foreign key constrants and depend more heavily on BlockNo Reduce use of foreign key constraints and depend more heavily on BlockNo Aug 18, 2022
@erikd
Copy link
Contributor Author

erikd commented Aug 18, 2022

I have been running this for nearly two weeks, on top of snapshotting and restoring the database. Seems fine.

@erikd erikd merged commit 4675c19 into master Aug 18, 2022
@iohk-bors iohk-bors bot deleted the erikd/no-foreign-keys-does-this-work-3 branch August 18, 2022 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant