Skip to content

Make sure we're using indexes during rollbacks 13.6.0.5#2085

Merged
kderme merged 2 commits intorelease/13.6.0.5from
kderme/fix-slow-rollbacks-13.6.0.5
Mar 24, 2026
Merged

Make sure we're using indexes during rollbacks 13.6.0.5#2085
kderme merged 2 commits intorelease/13.6.0.5from
kderme/fix-slow-rollbacks-13.6.0.5

Conversation

@kderme
Copy link
Copy Markdown
Contributor

@kderme kderme commented Mar 23, 2026

Fixes #2083 (comment) for 13.6.0.5.

The queryMinRefId query uses

SELECT id FROM <table> WHERE <field> >= $1 ORDER BY id ASC LIMIT 1.

The planner sometimes picks a bad plan:

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.

@kderme kderme changed the title Make sure we're using indexes during rollbacks Make sure we're using indexes during rollbacks 13.6.0.5 Mar 23, 2026
@kderme kderme marked this pull request as ready for review March 23, 2026 16:41
@kderme kderme requested a review from a team as a code owner March 23, 2026 16:41
kderme added 2 commits March 24, 2026 01:09
    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.
@kderme kderme force-pushed the kderme/fix-slow-rollbacks-13.6.0.5 branch from 380862f to 39c66db Compare March 23, 2026 23:17
@angerman
Copy link
Copy Markdown
Contributor

angerman commented Mar 24, 2026

I think this is good to merge.

  • The Haskell CI / build failures are an issue with the devx closures that are missing git.
  • The profiled builds failing isn't a big deal I believe.
  • The Check HLint / build failure is due to some dependency setup. It's just HLint, so it's at best formatting issues we didn't catch.
  • Looking at the relevant hydra build, everything seems to be green (except for profiling). Thus something with the notification delivery seems broken with the hydra -> github status reports.

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
@kderme kderme merged commit 703a467 into release/13.6.0.5 Mar 24, 2026
45 of 70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants