Repository navigation
Index room_agents on agent_id (CHOO-3667) - #1260
Closed
abeldantas wants to merge 3 commits into
Closed
abeldantas wants to merge 3 commits into
abeldantas wants to merge 3 commits into
Conversation
Reading the rooms an agent is in (RoomStore.get_rooms_for_agent and six other reads by agent), and the foreign key's check when an agent is deleted, filter room_agents by agent. Its primary key leads with the room, so each was a sequential scan, 2.9 ms at 10,000 agents, and every process runs it for each agent of a controller that connects. Expand only, and not CONCURRENTLY, as for ix_client_rooms_room_id.
abeldantas
requested review from
agent-runner353,
amaudruz,
christian-mcdermott,
lbangalosbt,
massimo-sandboxaq,
niall-sandboxaq,
petr-sandbox,
raullopez-sandbox and
simonflk-sb
as code owners
November 1, 2026 04:50
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the index migration, metadata registration, or changelog update.
No open issues 🎉
What changed in this PR
Adds an index on room_agents.agent_id to improve agent-based room lookups and foreign-key checks during agent deletion, without changing application behavior.
Changes:
- Adds an expand-only Alembic migration for
ix_room_agents_agent_id. - Registers the index in the SQLAlchemy metadata.
- Documents the performance improvement in the changelog.
| File | Description |
|---|---|
core/switch_core/migrations/versions/063652bcb450_index_room_agents_agent_id.py |
Creates and removes the agent_id index through the migration chain. |
core/switch_core/db/models.py |
Declares the new room_agents.agent_id index in the schema metadata. |
CHANGELOG.md |
Records the improved performance of agent room lookups. |
Review effort: Lite
Collaborator
Author
|
Combined into #1307 with the other scaling PRs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Seven
RoomStorereads by agent, and the check offk_room_agents_agentwhen an agent is deleted, filterroom_agentsbyagent_id. The primary key is(room_id, agent_id), so each was a sequential scan. In this PR we indexagent_id.room_agentsrowsEvery process reads the rooms of a controller's agents this way when the controller connects, one agent at a time. Expand only, and not
CONCURRENTLY, as forix_client_rooms_room_id.