perf: fix cardano blocks with transactions retrieval in mainnet network - #3081
Merged
Alenar merged 2 commits intoMar 10, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a SQLite query planner regression on large (mainnet) datasets by forcing index usage for the GetCardanoBlockTransactionsQuery, avoiding full scans on a ~30GB database during high-volume block/transaction retrieval.
Changes:
- Force SQLite to use
cardano_block_block_number_indexviaINDEXED BYin the block+transactions retrieval query. - Document the hard dependency between the query and the index name in the migration SQL.
- Bump
mithril-persistencecrate version.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| internal/mithril-persistence/src/database/query/cardano_block/get_cardano_block_with_transactions.rs | Adds INDEXED BY cardano_block_block_number_index to guarantee indexed access by block number range. |
| internal/mithril-persistence/src/database/cardano_transaction_migration.rs | Documents that the cardano_block_block_number_index name is coupled to the query and must not be removed/renamed without updating it. |
| internal/mithril-persistence/Cargo.toml | Bumps crate version to 0.2.68. |
| Cargo.lock | Updates locked version for mithril-persistence to 0.2.68. |
* mithril-persistence from `0.2.67` to `0.2.68`
Alenar
force-pushed
the
djo/3050/fix_index_not_used_for_blocks+txs_retrieval
branch
from
March 10, 2026 11:43
18d7543 to
c09584e
Compare
turmelclem
approved these changes
Mar 10, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Content
This PR includes a performance fix for the
GetCardanoBlockTransactionsQueryto guarantee that it use indexes in the largemainnetdataset.We found that the SQLite query planner is not able to compute a fast plan for this query on large dataset, even after running
pragma optimize, the available index is ignored and a full scan is performed ... which is extremely slow with a 30GB database, taking seconds to retrieve a single row (and we needs millions of them).Forcing the planner to use the index fix the issue:
Caution
This use the
indexed bySQLite clause which is not recommended under normal circumstances to tune performance, but we did not find alternatives, even running a largeANALYZE(with aanalysis_limitof100 000rows) did not fix the plan.Pre-submit checklist
Issue(s)
Relates to #3050