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

Simplify history.CreateAccounts() to avoid select statement #4864

Closed
tamirms opened this issue May 4, 2023 · 1 comment · Fixed by #5415
Closed

Simplify history.CreateAccounts() to avoid select statement #4864

tamirms opened this issue May 4, 2023 · 1 comment · Fixed by #5415
Assignees
Labels

Comments

@tamirms
Copy link
Contributor

tamirms commented May 4, 2023

The CreateAccounts , CreateHistoryClaimableBalances , CreateAssets, and CreateHistoryLiquidityPools functions are used to insert records into the history_accounts, history_claimable_balances, history_assets, and history_liquidity_pools tables. The functions are implemented by first executing insert statements into the respective tables followed by executing select statements to lookup the rows which where just inserted.

However, the select statements can be avoided because we can add a RETURNING clause to the insert statements which will return the row which was just inserted.

@tamirms tamirms moved this from Backlog to Next Sprint Proposal in Platform Scrum May 16, 2023
@mollykarcher mollykarcher moved this from Next Sprint Proposal to Backlog in Platform Scrum Jun 13, 2023
@urvisavla urvisavla moved this from Backlog to Next Sprint Proposal in Platform Scrum Oct 9, 2023
@urvisavla urvisavla moved this from Next Sprint Proposal to Current Sprint in Platform Scrum Oct 10, 2023
@urvisavla urvisavla self-assigned this Oct 10, 2023
@urvisavla
Copy link
Contributor

The RETURNING clause in an INSERT statement only returns the newly inserted rows. To return all rows, including existing ones, we can force an update using the ON CONFLICT UPDATE SET... clause. However this additional update will likely have a negative impact on performance.

To improve reap performance, we plan to add a last_Reference_ledger column to these tables. This column will be updated every time which will allow us to use the RETURNING clause. However, when reingesting older ledgers, we may not want to update the last_Reference_ledger if it is greater than the one we are reingesting. So at this point I'm not sure that we can combine the two statements.

@urvisavla urvisavla moved this from Current Sprint to Next Sprint Proposal in Platform Scrum Nov 1, 2023
@mollykarcher mollykarcher moved this from Next Sprint Proposal to Backlog in Platform Scrum Nov 2, 2023
@github-project-automation github-project-automation bot moved this from Backlog to Done in Platform Scrum Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
2 participants