fix(storage): index triggers_occurrences(trigger_id, date) (EN-1231) - #194
fix(storage): index triggers_occurrences(trigger_id, date) (EN-1231)#194flemzord wants to merge 1 commit into
Conversation
Migration 8 dropped the (trigger_id, event_id) primary key in favour of (id), leaving trigger_id unindexed. ListTriggersOccurrences filters WHERE trigger_id = ? ordered by date, so every page was a sequential scan over an ever-growing table. Add a migration creating the composite index, built CONCURRENTLY (the migrator runs each migration on a dedicated non-transactional connection) and IF NOT EXISTS for idempotency.
|
Warning Review limit reached
More reviews will be available in 37 minutes and 26 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Superseded by #199, which consolidates this change with the related reliability and safety fixes on top of the current main branch. |
Problem (H12 — HIGH)
Migration 8 dropped the
(trigger_id, event_id)primary key in favour of(id), leavingtrigger_idunindexed.ListTriggersOccurrencesfiltersWHERE trigger_id = ?ordered bydate(internal/triggers/manager.go), andtriggers_occurrencesgains one row per matched event — so every page request is a sequential scan over an ever-growing table, plusOFFSET.Fix
Add a migration creating the composite index
triggers_occurrences (trigger_id, date):CONCURRENTLYto avoid blocking writes during deploy (the go-libs migrator runs each migration on a dedicated, non-transactional connection, soCONCURRENTLYis valid here — verified against the migration test harness);IF NOT EXISTSfor idempotency.Test
Verified the full
storage.Migratechain runs cleanly (storage + triggers integration suites).Severity: HIGH.