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

perf(eth-sender): optimize sql query #3437

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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

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

16 changes: 10 additions & 6 deletions core/lib/dal/src/eth_sender_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ impl EthSenderDal<'_, '_> {
from_addr IS NOT DISTINCT FROM $1 -- can't just use equality as NULL != NULL
AND confirmed_eth_tx_history_id IS NULL
AND is_gateway = $2
AND id <= (
SELECT
COALESCE(MAX(eth_tx_id), 0)
AND id <= COALESCE(
(SELECT
eth_tx_id
FROM
eth_txs_history
JOIN eth_txs ON eth_txs.id = eth_txs_history.eth_tx_id
WHERE
eth_txs_history.sent_at_block IS NOT NULL
AND eth_txs.from_addr IS NOT DISTINCT FROM $1
AND is_gateway = $2
ORDER BY eth_tx_id DESC LIMIT 1),
0
)
ORDER BY
id
Expand Down Expand Up @@ -172,16 +174,18 @@ impl EthSenderDal<'_, '_> {
WHERE
from_addr IS NOT DISTINCT FROM $2 -- can't just use equality as NULL != NULL
AND is_gateway = $3
AND id > (
SELECT
COALESCE(MAX(eth_tx_id), 0)
AND id > COALESCE(
(SELECT
eth_tx_id
FROM
eth_txs_history
JOIN eth_txs ON eth_txs.id = eth_txs_history.eth_tx_id
WHERE
eth_txs_history.sent_at_block IS NOT NULL
AND eth_txs.from_addr IS NOT DISTINCT FROM $2
AND is_gateway = $3
ORDER BY eth_tx_id DESC LIMIT 1),
0
)
ORDER BY
id
Expand Down
Loading