Skip to content

Commit

Permalink
perf: optimize pgsql schema (#345)
Browse files Browse the repository at this point in the history
* perf: denormalize schema

* group deletions in one file
  • Loading branch information
carneiro-cw authored Mar 13, 2024
1 parent cb5cb6f commit 96cf175
Show file tree
Hide file tree
Showing 5 changed files with 757 additions and 162 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

2 changes: 1 addition & 1 deletion src/eth/storage/postgres/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ impl PermanentStorage for Postgres {
}

async fn reset_at(&self, number: BlockNumber) -> anyhow::Result<()> {
sqlx::query!("DELETE FROM blocks WHERE number > $1", number as _)
sqlx::query_file!("src/eth/storage/postgres/queries/delete_after_block.sql", number as _)
.execute(&self.connection_pool)
.await?;

Expand Down
25 changes: 25 additions & 0 deletions src/eth/storage/postgres/queries/delete_after_block.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
WITH delete_blocks AS (
DELETE FROM blocks WHERE number > $1
),
delete_account_slots AS (
DELETE FROM account_slots WHERE creation_block > $1
),
delete_accounts AS (
DELETE FROM accounts WHERE creation_block > $1
),
delete_historical_balances AS (
DELETE FROM historical_balances WHERE block_number > $1
),
delete_historical_nonces AS (
DELETE FROM historical_nonces WHERE block_number > $1
),
delete_historical_slots AS (
DELETE FROM historical_slots WHERE block_number > $1
),
delete_logs AS (
DELETE FROM logs WHERE block_number > $1
),
delete_topics AS (
DELETE FROM topics WHERE block_number > $1
)
DELETE FROM transactions WHERE block_number > $1
Loading

0 comments on commit 96cf175

Please sign in to comment.