-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: optimize block insertion (#330)
* Add the previous value to the account_slots table * add the previous nonce and balance to the accounts schema * update sqls * sqlx prepare * revert column name change
- Loading branch information
1 parent
efb3268
commit 46b403a
Showing
9 changed files
with
109 additions
and
76 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
.sqlx/query-33f7d317d0eb2660f5e6cb0cefe2154eebc03eaa6eda3999a43da709be4bec56.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
.sqlx/query-ba23066f867cccf985f4895180a47523e061bd992f9a325865690ba2c03d8d09.json
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...37209d945a0dc16ed42f452322dd332e4cea.json → ...18043577aaab2e774cf451ba20698b274f1f.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
INSERT INTO accounts (address, latest_nonce, latest_balance, bytecode, creation_block) | ||
VALUES ($1, $2, $3, $4, $5) | ||
INSERT INTO accounts (address, latest_nonce, latest_balance, bytecode, creation_block, previous_balance, previous_nonce) | ||
VALUES ($1, $2, $3, $4, $5, $6, $7) | ||
ON CONFLICT (address) DO | ||
UPDATE | ||
SET latest_nonce = EXCLUDED.latest_nonce, | ||
latest_balance = EXCLUDED.latest_balance | ||
WHERE accounts.latest_nonce = $6 AND accounts.latest_balance = $7 | ||
WHERE accounts.latest_nonce = excluded.previous_balance AND accounts.latest_balance = excluded.previous_balance |
49 changes: 39 additions & 10 deletions
49
src/eth/storage/postgres/queries/insert_account_batch.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,43 @@ | ||
WITH account_updates | ||
AS (SELECT * | ||
FROM UNNEST($1::bytea[], $2::bytea[], $3::numeric[], $4::numeric[], $5::numeric[], $6::numeric[], $7::numeric[]) | ||
AS t(address, bytecode, new_balance, new_nonce, creation_block, original_balance, original_nonce) | ||
WITH account_updates AS ( | ||
SELECT * | ||
FROM | ||
unnest( | ||
$50::bytea [], | ||
$51::bytea [], | ||
$52::numeric [], | ||
$53::numeric [], | ||
$54::numeric [], | ||
$55::numeric [], | ||
$56::numeric [] | ||
) | ||
AS t ( | ||
address, | ||
bytecode, | ||
new_balance, | ||
new_nonce, | ||
creation_block, | ||
previous_balance, | ||
previous_nonce | ||
) | ||
) | ||
INSERT INTO accounts (address, bytecode, latest_balance, latest_nonce, creation_block) | ||
SELECT address, bytecode, new_balance, new_nonce, creation_block | ||
|
||
INSERT INTO accounts ( | ||
address, bytecode, latest_balance, latest_nonce, creation_block, previous_balance, previous_nonce | ||
) | ||
SELECT | ||
address, | ||
bytecode, | ||
new_balance, | ||
new_nonce, | ||
creation_block, | ||
previous_balance, | ||
previous_nonce | ||
FROM account_updates | ||
ON CONFLICT (address) DO | ||
UPDATE | ||
SET latest_nonce = EXCLUDED.latest_nonce, | ||
latest_balance = EXCLUDED.latest_balance | ||
WHERE accounts.latest_nonce = (SELECT original_nonce FROM account_updates WHERE account_updates.address=accounts.address) | ||
AND accounts.latest_balance = (SELECT original_balance FROM account_updates WHERE account_updates.address=accounts.address) | ||
SET latest_nonce = excluded.latest_nonce, | ||
latest_balance = excluded.latest_balance, | ||
previous_balance = excluded.previous_balance, | ||
previous_nonce = excluded.previous_nonce | ||
WHERE accounts.latest_nonce = excluded.previous_nonce | ||
AND accounts.latest_balance = excluded.previous_balance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
INSERT INTO account_slots VALUES ($1, $2, $3, $4) | ||
INSERT INTO account_slots(idx, value, previous_value, account_address, creation_block) | ||
VALUES ($1, $2, $3, $4, $5) | ||
ON CONFLICT (idx, account_address) | ||
DO UPDATE SET value = EXCLUDED.value | ||
WHERE account_slots.value = $5 | ||
WHERE account_slots.value = excluded.previous_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
WITH slot_updates | ||
AS (SELECT * | ||
FROM UNNEST($1::bytea[], $2::bytea[], $3::bytea[], $4::numeric[], $5::bytea[]) | ||
AS t(idx, value, account_address, creation_block, original_value) | ||
WITH slot_updates AS ( | ||
SELECT * | ||
FROM | ||
unnest( | ||
$57::bytea [], | ||
$58::bytea [], | ||
$59::bytea [], | ||
$60::numeric [], | ||
$61::bytea [] | ||
) | ||
AS t (idx, value, account_address, creation_block, original_value) | ||
) | ||
INSERT INTO account_slots (idx, value, account_address, creation_block) | ||
SELECT idx, value, account_address, creation_block | ||
|
||
INSERT INTO account_slots (idx, value, previous_value, account_address, creation_block) | ||
SELECT | ||
idx, | ||
value, | ||
original_value, | ||
account_address, | ||
creation_block | ||
FROM slot_updates | ||
ON CONFLICT (idx, account_address) DO | ||
UPDATE | ||
SET value = EXCLUDED.value | ||
WHERE account_slots.value = ( | ||
SELECT original_value | ||
FROM slot_updates | ||
WHERE slot_updates.idx = EXCLUDED.idx | ||
AND slot_updates.account_address = EXCLUDED.account_address) | ||
SET value = excluded.value, | ||
previous_value = excluded.previous_value | ||
WHERE account_slots.value = excluded.previous_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters