-
Notifications
You must be signed in to change notification settings - Fork 161
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
Remove Foreign Keys #1082
Comments
I do not fully agree, especially since this is one of the few methods we have for ensuring data integrity.
Yes, ledger has its own data integrity checks, but IMO, since
Rollbacks using foreign keys are guaranteed to be correct. Yes, theoretically, that can be replaced with |
Under this scheme rollbacks used to be done as:
where the foreign keys would cause a cascade through all the tables. Without foreign keys we would need a delete for every table:
with a separate delete statement for every table. Hopefully this would be at least as fast. |
On insertions we ensure data integrity by doing a query on referenced fields before inserting, so the additional check done by postgres is basically useless. If it fails the whole thing crashes anyway. On deletions, indeed we will have to be very careful about not missing a table. And there are no updates. |
The only table which is updated is the |
I am growing more and more skeptical about this. Replacing However, replacing a foreign key (8 bytes) with a hash (28, 29 or 32 bytes) may not have the same benefits as the above.
In summary, replacing |
I totally agree with the above we should not replace ids with hashes. I think we should still use ids, just remove the foreign key constraints and the related indexes. |
I wonder if its possible to run an experiment where all the foreign keys are removed from the generated SQL and we sync from genesis to compare speeds. |
This experiment seems to be working and its faster. I will have a better idea of how much faster in the morning. |
This is WIP. My branch is |
@kderme could you provide a more detailed update here on the work that was done? For example, were foreign key constraints removed for all keys across all tables? thanks! |
Foreign keys have been removed from master and the release branches, but in a different way which we eventually need to merge.
In master this initially recomended process to rollback was followed, but then I realised this resulted in the addition of many new fields, which could negatively affect performance and required a very compicated migration. Instead in the release branch I added a different way to rollback which used reverse indexes and doesn't require new fields. |
Relations in db-sync can be visualised as a graph (actually DAG) of references. For example a Block references its previous Block, a Tx its Block, a certificate its Tx and its StakeAddress, a TxIn its TxOut etc. The current implementation uses foreign keys for these relations. Foreign keys come with some pros and cons
Pros
Cons
delete from tableX where blockNo > ...
.Overall foreign keys make insertions slower. They allow very simple rollbacks, but rollbacks can become even faster. Finally the data integrity is not so vital. db-sync get its data from blocks that have gone through ledger validation, so doing additional checks is not needed.
The text was updated successfully, but these errors were encountered: