You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/common/src/main/scala/org/lfdecentralizedtrust/splice/store/UpdateHistory.scala
+13-3Lines changed: 13 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1726,10 +1726,20 @@ class UpdateHistory(
1726
1726
):Future[Option[Long]] = {
1727
1727
defpreviousId(table: String) = {
1728
1728
storage.query(
1729
+
// The following is equivalent to:
1730
+
// select max(migration_id)
1731
+
// from #$table
1732
+
// where history_id = $historyId and migration_id < $migrationId
1733
+
// but uses a recursive CTE to avoid a backwards-index-scan which attempts to read most of the table.
1729
1734
sql"""
1730
-
select max(migration_id)
1731
-
from #$table
1732
-
where history_id = $historyId and migration_id < $migrationId
1735
+
WITH RECURSIVE t AS (
1736
+
(SELECT migration_id FROM #$table where history_id = $historyId and migration_id < $migrationId ORDER BY migration_id LIMIT 1)
1737
+
UNION ALL
1738
+
SELECT (SELECT migration_id FROM #$table WHERE history_id = $historyId and migration_id < $migrationId and migration_id > t.migration_id ORDER BY migration_id LIMIT 1)
1739
+
FROM t
1740
+
WHERE t.migration_id IS NOT NULL
1741
+
)
1742
+
SELECT MAX(migration_id) FROM t WHERE migration_id IS NOT NULL;
0 commit comments