Skip to content

index car_blocks.file_id to fix FK cascade scans#665

Merged
parkan merged 2 commits intomainfrom
fix/car-blocks-file-id-index
Apr 18, 2026
Merged

index car_blocks.file_id to fix FK cascade scans#665
parkan merged 2 commits intomainfrom
fix/car-blocks-file-id-index

Conversation

@parkan
Copy link
Copy Markdown
Collaborator

@parkan parkan commented Apr 18, 2026

CarBlock.FileID was unindexed, so ON DELETE SET NULL from files.id triggered a full seq scan of car_blocks per deleted file. At ~1.5B rows this wedged the reaper's files phase for months.

  • add gorm:"index" on CarBlock.FileID (matching CarID)
  • regression test asserting CarID, FileID, CID are all indexed

parkan and others added 2 commits April 18, 2026 12:12
without this index, ON DELETE SET NULL from files.id to car_blocks.file_id
causes a full-table sequential scan of car_blocks for every file being deleted.
on a billion-row car_blocks table this makes file deletion effectively
impossible -- the healthcheck reaper in prod wedged for 5 months because of
exactly this.

add gorm:"index" to CarBlock.FileID (CarID already has one). add a
regression test that asserts both FK columns plus cid are indexed, so this
doesn't silently regress again.
@parkan parkan merged commit 8e9b2c2 into main Apr 18, 2026
1 check passed
@parkan parkan deleted the fix/car-blocks-file-id-index branch April 18, 2026 16:36
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