Skip to content

Commit 75959c0

Browse files
perf(server): pin the index for the unscoped agent event high-water
The query without a thread could plan onto the covering per-stream index and scan every agent event: 9.3s cold / 182ms warm on a 1.45M-event database, and 1,211 reads over 150ms a day on fleet servers built from main. Pin the (application_event_version, sequence) index so MAX seeks to the end. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 60aec28 commit 75959c0

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎apps/server/src/persistence/OrchestrationEventStore.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,8 @@ const makeEventStore = Effect.gen(function* () {
645645
FROM orchestration_events
646646
${
647647
threadId === undefined
648-
? sql``
648+
? // The planner can otherwise pick the covering stream index and scan every agent event.
649+
sql`INDEXED BY idx_orchestration_events_application_sequence`
649650
: sql`INDEXED BY idx_orchestration_events_agent_stream_sequence`
650651
}
651652
WHERE application_event_version = 2

0 commit comments

Comments
 (0)