Make sure we're using indexes during rollbacks 13.6.0.5#2085
Merged
kderme merged 2 commits intorelease/13.6.0.5from Mar 24, 2026
Merged
Make sure we're using indexes during rollbacks 13.6.0.5#2085kderme merged 2 commits intorelease/13.6.0.5from
kderme merged 2 commits intorelease/13.6.0.5from
Conversation
Fixes #2083 The `queryMinRefId` query uses ```sql SELECT id FROM <table> WHERE <field> >= $1 ORDER BY id ASC LIMIT 1. ``` The planner sometimes picks a bad plan: ```sql Index Scan using tx_pkey on tx Filter: (block_id >= $1) ``` the filter is not Index Cond, so this ends up in a sequential scan. The index refers to the primary key and is only used for sorting. Instead we use a simpler query without ORDER BY: SELECT id FROM <table> WHERE <field> >= $1 LIMIT 10000 This forces the planner to use the field's index. The results are fetched and the minimum is found in Haskell. Near the tip this returns only a handful of rows. If there are more than 10000 matching rows (large rollback), we fall back to the original ORDER BY id ASC LIMIT 1 query.
380862f to
39c66db
Compare
sgillespie
approved these changes
Mar 24, 2026
Contributor
|
I think this is good to merge.
|
angerman
added a commit
to input-output-hk/devx
that referenced
this pull request
Mar 24, 2026
Cabal needs git on PATH for source-repository-package stanzas in cabal.project files. Without it, builds fail with Cabal-6666. This was observed in IntersectMBO/cardano-db-sync#2085 where 6 out of 9 failing CI jobs reported "The program 'git' is required but it could not be found." Add gitMinimal (146 MiB closure) instead of git (1.5 GiB) to all four shell definitions — the same package nixpkgs uses for fetchgit. The 10x smaller closure matters for container images built from devx shells. - dynamic.nix: add gitMinimal to buildInputs, drop redundant git from withGHCTooling (gitMinimal now covers it) - static.nix: add gitMinimal to nativeBuildInputs - cross-js.nix: add gitMinimal to nativeBuildInputs - cross-windows.nix: add pkgsBuildBuild.gitMinimal to nativeBuildInputs
3 tasks
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.
Fixes #2083 (comment) for 13.6.0.5.
The
queryMinRefIdquery usesThe planner sometimes picks a bad plan:
the filter is not Index Cond, so this ends up in a sequential scan.
The index refers to the primary key and is only used for sorting.
Instead we use a simpler query without ORDER BY:
This forces the planner to use the field's index.
The results are fetched and the minimum is found in Haskell.
Near the tip this returns only a handful of rows.
If there are more than 10000 matching rows (large rollback),
we fall back to the original ORDER BY id ASC LIMIT 1 query.