Skip to content

perf: drop redundant indexes, index dead_letters.retried_message_id - #116

Merged
cardmagic merged 2 commits into
mainfrom
perf/drop-redundant-indexes-115
Dec 2, 2026
Merged

cardmagic merged 2 commits into
mainfrom
perf/drop-redundant-indexes-115

Conversation

@cardmagic

Copy link
Copy Markdown
Owner

Summary

New migration 20261202000000_drop_redundant_solid_objects_indexes.rb (reversible):

 ready_messages   - index_solid_objects_ready_messages_on_message_id     (idx_so_ready_message covers)
 ready_messages   - index_solid_objects_ready_messages_on_instance_id    (idx_so_ready_instance_sequence covers)
 claimed_messages - index_solid_objects_claimed_messages_on_message_id   (idx_so_claimed_message covers)
 claimed_messages - index_solid_objects_claimed_messages_on_instance_id  (idx_so_claimed_instance covers)
 dead_letters     - index_solid_objects_dead_letters_on_message_id       (idx_so_dead_letters_message covers)
 broadcasts       - index_solid_objects_broadcasts_on_message_id         (idx_so_broadcasts_observable covers)
 dead_letters     + idx_so_dead_letters_retried_message (retried_message_id), only when the column has no index

Each dropped index is a plain index whose leading columns already lead a unique index, so inserts and deletes maintained two b-trees for one access path. dead_letters.retried_message_id has a foreign key with no index on SQLite and PostgreSQL, so every pruned message scans dead_letters. MySQL already indexes the key, so the migration adds nothing there and never leaves two indexes on the column. index_solid_objects_effects_on_message_id and index_solid_objects_dead_letters_on_instance_id stay: each is the only index on its column. Down restores the six indexes first, then removes the index this migration added when it is present.

Compatibility and migration

Existing installs run bin/rails solid_objects:install:migrations and db:migrate. New installs reach the same index set through SchemaBootstrap.install. No public API change, no version bump, and shipped migrations are unchanged. This is a minor-release change; the CHANGELOG ## Unreleased note says so.

Tests

test/models/redundant_index_schema_test.rb:

  • fails on any non-unique index whose leading columns lead a unique index on the same table, except an allowlist of exactly index_solid_objects_messages_on_instance_id and index_solid_objects_reminders_on_instance_id (commented as known and left for a possible follow-up), and fails when an allowlisted index no longer exists;
  • passes for idx_so_messages_instance_sequence and idx_so_messages_idempotency sharing instance_id, and a scratch table proves the detector does flag a covered index;
  • asserts the final index set, a single retried_message_id index, down and up on the live adapter, and an upgrade of an already-installed SQLite schema ending in the same index set as a fresh install;
  • checks foreign key coverage for the message_id and instance_id keys on every adapter, and for every foreign key on MySQL (mysql2 and trilogy jobs). The MySQL-only test skips on SQLite and PostgreSQL.

Before the migration existed, 6 of the 10 tests failed (the six indexes present, the migration missing). Full local run on SQLite: 1030 runs, 0 failures, 40 skips. rake standard rubocop rbs steep security is clean. PostgreSQL and MySQL run in CI; neither server was available locally.

Closes #115

Merge Danger

Door: two-way (down restores the indexes)

Blast Radius: index set on six tables for installs that run the migration

@greptile-apps

greptile-apps Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge; the earlier database comparison issue is fixed.

Summary

The PR drops six covered indexes and adds an index for dead_letters.retried_message_id when needed.

  • Four message tables keep unique indexes without six duplicates.
  • Dead-letter retry lookups gain an index where the database lacks one.

Reviews (2) · Last reviewed commit: "test: compare upgrade with fresh install..." · Reviewed by Greptile

@cardmagic

Copy link
Copy Markdown
Owner Author

@greptileai review

@context7

context7 Bot commented Dec 2, 2026

Copy link
Copy Markdown

Docs7 for cardmagic/solid-objects-ruby

Result Status Action
Deployment ➖ Not used —
Content review ✅ Passed. No problems found. —

Commit b2cc5f7

@cardmagic
cardmagic merged commit 60b40cf into main Dec 2, 2026
46 checks passed
@cardmagic
cardmagic deleted the perf/drop-redundant-indexes-115 branch December 2, 2026 23:09
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.

Drop redundant leading-column indexes and index dead_letters.retried_message_id

1 participant