Skip to content

Commit 703a467

Browse files
authored
Merge pull request #2085 from IntersectMBO/kderme/fix-slow-rollbacks-13.6.0.5
Make sure we're using indexes during rollbacks 13.6.0.5
2 parents cb61094 + 39c66db commit 703a467

10 files changed

Lines changed: 52 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Revision history for cardano-db-sync
22

3+
## 13.6.0.7
4+
- Fix slow rollbacks caused by suboptimal query plans on large tables [#2083]
5+
36
## 13.6.0.5
47
- Fix offchain data so it supports files up to 3MB [#1928]
58
- Upgrade to PostgreSQL 17

cardano-chain-gen/cardano-chain-gen.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 3.6
22

33
name: cardano-chain-gen
4-
version: 13.6.0.5
4+
version: 13.6.0.7
55
synopsis: A fake chain generator for testing cardano DB sync.
66
description: A fake chain generator for testing cardano DB sync.
77
homepage: https://github.com/IntersectMBO/cardano-db-sync

cardano-db-sync/cardano-db-sync.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 3.6
22

33
name: cardano-db-sync
4-
version: 13.6.0.5
4+
version: 13.6.0.7
55
synopsis: The Cardano DB Sync node
66
description: A Cardano node that follows the Cardano chain and inserts data from the
77
chain into a PostgresQL database.

cardano-db-tool/cardano-db-tool.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 3.6
22

33
name: cardano-db-tool
4-
version: 13.6.0.5
4+
version: 13.6.0.7
55
synopsis: Utilities to manage the cardano-db-sync databases.
66
description: Utilities and executable, used to manage and validate the
77
PostgreSQL db and the ledger database of the cardano-db-sync node

cardano-db/cardano-db.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 3.6
22

33
name: cardano-db
4-
version: 13.6.0.5
4+
version: 13.6.0.7
55
synopsis: A base PostgreSQL component for the cardano-db-sync node.
66
description: Code for the Cardano DB Sync node that is shared between the
77
cardano-db-node and other components.

cardano-db/src/Cardano/Db/Operations/Query.hs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,45 @@ queryMinRefId ::
581581
field ->
582582
ReaderT SqlBackend m (Maybe (Key record))
583583
queryMinRefId txIdField txId = do
584+
res <- select $ do
585+
rec <- from $ table @record
586+
where_ (rec ^. txIdField >=. val txId)
587+
limit 10000
588+
pure $ rec ^. persistIdField
589+
if length res >= 10000
590+
then queryMinRefIdFallback txIdField txId
591+
else pure $ minimumMay $ map unValue res
592+
where
593+
minimumMay [] = Nothing
594+
minimumMay xs = Just (minimum xs)
595+
596+
queryMinRefIdNullable ::
597+
forall m field record.
598+
(MonadIO m, PersistEntity record, PersistField field) =>
599+
EntityField record (Maybe field) ->
600+
field ->
601+
ReaderT SqlBackend m (Maybe (Key record))
602+
queryMinRefIdNullable txIdField txId = do
603+
res <- select $ do
604+
rec <- from $ table @record
605+
where_ (isJust (rec ^. txIdField))
606+
where_ (rec ^. txIdField >=. just (val txId))
607+
limit 10000
608+
pure $ rec ^. persistIdField
609+
if length res >= 10000
610+
then queryMinRefIdNullableFallback txIdField txId
611+
else pure $ minimumMay $ map unValue res
612+
where
613+
minimumMay [] = Nothing
614+
minimumMay xs = Just (minimum xs)
615+
616+
queryMinRefIdFallback ::
617+
forall m field record.
618+
(MonadIO m, PersistEntity record, PersistField field) =>
619+
EntityField record field ->
620+
field ->
621+
ReaderT SqlBackend m (Maybe (Key record))
622+
queryMinRefIdFallback txIdField txId = do
584623
res <- select $ do
585624
rec <- from $ table @record
586625
where_ (rec ^. txIdField >=. val txId)
@@ -589,13 +628,13 @@ queryMinRefId txIdField txId = do
589628
pure $ rec ^. persistIdField
590629
pure $ unValue <$> listToMaybe res
591630

592-
queryMinRefIdNullable ::
631+
queryMinRefIdNullableFallback ::
593632
forall m field record.
594633
(MonadIO m, PersistEntity record, PersistField field) =>
595634
EntityField record (Maybe field) ->
596635
field ->
597636
ReaderT SqlBackend m (Maybe (Key record))
598-
queryMinRefIdNullable txIdField txId = do
637+
queryMinRefIdNullableFallback txIdField txId = do
599638
res <- select $ do
600639
rec <- from $ table @record
601640
where_ (isJust (rec ^. txIdField))

cardano-db/test/cardano-db-test.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 3.6
22

33
name: cardano-db-test
4-
version: 13.6.0.5
4+
version: 13.6.0.7
55
synopsis: Tests for the base functionality of the cardano-db library
66
description: Code for the Cardano DB Sync node that is shared between the
77
cardano-db-node and other components.

cardano-smash-server/cardano-smash-server.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 3.6
22

33
name: cardano-smash-server
4-
version: 13.6.0.5
4+
version: 13.6.0.7
55
synopsis: The Cardano smash server
66
description: Please see the README on GitHub at
77
<https://github.com/IntersectMBO/cardano-db-sync/cardano-smash-server/#readme>

docker-compose.example.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ services:
5959
max-file: "10"
6060

6161
cardano-db-sync:
62-
image: ghcr.io/intersectmbo/cardano-db-sync:13.6.0.5
62+
image: ghcr.io/intersectmbo/cardano-db-sync:13.6.0.7
6363
environment:
6464
- NETWORK=${NETWORK:-mainnet}
6565
- POSTGRES_HOST=postgres

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ services:
5454
max-file: "10"
5555

5656
cardano-db-sync:
57-
image: ghcr.io/intersectmbo/cardano-db-sync:13.6.0.5
57+
image: ghcr.io/intersectmbo/cardano-db-sync:13.6.0.7
5858
environment:
5959
- DB_SYNC_CONFIG=${DB_SYNC_CONFIG:-}
6060
- DISABLE_LEDGER=${DISABLE_LEDGER}

0 commit comments

Comments
 (0)