-
Notifications
You must be signed in to change notification settings - Fork 13
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
Update transaction tables to reduce queries dispatched & executed by Postgres #102
Comments
We do use Lines 303 to 327 in 08fc34a
While writing this I also realize we need to have those two tables for example to be able to find the Lines 251 to 266 in 08fc34a
In the UTXO model, an input is always linked to an older output, but when we insert the transaction with the outputs, we don't know in advance which inputs of a future tx will use those outputs. So we have to do all those So I guess we need to go for option 1 Your thoughts @polarker ? |
Hey @tdroxler, you are right about this on our Slack conversion. I got Slick confused with Hibernate. In Hibernate adding foreign-key-constraints automatically optimises queries to use joins but in Slick we have to do this manually. My excuse: haven't used ORMs in a while :( And now since we are writing raw SQL, adding foreign-key-constraints to optimise for performance makes even less sense. So this issue is invalid. Thank you for pointing this out. If you are ok I will close this task? |
👍 all good to close it |
Overview
Update
utransactions
&transactions
tables to use foreign key constraintsIssue
To fetch a single transaction 3 queries are dispatched to Postgres.
Similar occurs for a write.
Options
1. Foreign key constraints
Use foreign key constraints on existing tables so Postgres knows the relationships between the tables, and we can reduce
the number of queries dispatched & executed by Postgres for each read and write to 1.
2. Merge all data into a single
transaction
tableI'm seeing these
transaction
queries always fetch their relevantinputs
andoutputs
rows.inputs
andoutputs
tables are never queried individually. Merginginputs
andoutputs
tables into the maintransaction
table as single column or two columns and storing them as un-indexedvarchar
orblob
would increase performance by a large factor over option 1 above becausetransactions
table and none forinputs
and
outputs
(which are much larger tables with larger indexes).We can store them as
jsonb
if we want indexing. But if indexing is needed option 1 is easier to maintain andjsonb
's value size is limited to 268.435455 MB (from StackOverflow question).Drawback of using this option over option 1 - In-case we want to query
inputs
andoutputs
individually, separate tables are much easier to maintain. But if we want performance this option 2 will be noticeably better.Thoughts?
The text was updated successfully, but these errors were encountered: