Skip to content

FDN-4939: Fix NOT IN → NOT EXISTS in ScheduleMigrateVersionsProcessor#972

Merged
jackl merged 1 commit into
mainfrom
FDN-4939-fix-not-in-query-schedule-migrate-versions
May 20, 2026
Merged

FDN-4939: Fix NOT IN → NOT EXISTS in ScheduleMigrateVersionsProcessor#972
jackl merged 1 commit into
mainfrom
FDN-4939-fix-not-in-query-schedule-migrate-versions

Conversation

@jackl
Copy link
Copy Markdown
Contributor

@jackl jackl commented May 20, 2026

Summary

  • FDN-4939
  • ScheduleMigrateVersionsProcessor was running a query with NOT IN (SELECT type_id::uuid FROM tasks WHERE type = ...) that caused ~99% CPU on apibuilderdb20211217. Two issues combined to cause the full-table scan:
    1. type_id::uuid applied a cast to an indexed column on every subquery row, defeating the index and forcing a full scan of tasks.
    2. NOT IN materialises the entire subquery before the anti-join, compounding the cost.
  • Replaced with NOT EXISTS and flipped the cast to v.guid::text, so Postgres can seek the existing unique(type_id, type) index directly — one targeted lookup per outer row instead of a full scan.

Dependencies

None. The existing unique(type_id, type) index on tasks already covers the new predicate; no schema migration needed.

Validation

  • CPU on apibuilderdb20211217 drops after deploy
  • ScheduleMigrateVersionsProcessor continues to enqueue MigrateVersion tasks correctly

Eng-Review Summary

  • Revision: 915bc4a
  • Timestamp: 2026-05-20T14:00:00Z
  • Status: passed
  • Issues: None

NOT IN with a subquery was causing ~99% CPU on apibuilderdb20211217.
The subquery cast type_id::uuid per row, defeating the index, and the
NOT IN semantics materialise the full subquery before filtering.

NOT EXISTS with a correlated predicate (type_id = v.guid::text) lets
Postgres use the existing unique index on tasks(type_id, type) for a
targeted seek per outer row instead of a full subquery scan.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jackl jackl merged commit c7ea47e into main May 20, 2026
2 checks passed
@jackl jackl deleted the FDN-4939-fix-not-in-query-schedule-migrate-versions branch May 20, 2026 14:12
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.

1 participant