Skip to content

feat(cells): Add idx to OrganizationMapping table for synapse#110168

Merged
lynnagara merged 1 commit intomasterfrom
org-mapping-idx-with-cell-name
Mar 6, 2026
Merged

feat(cells): Add idx to OrganizationMapping table for synapse#110168
lynnagara merged 1 commit intomasterfrom
org-mapping-idx-with-cell-name

Conversation

@lynnagara
Copy link
Copy Markdown
Member

Add another index that includes the cell_name to serve queries that filter on a subset of cells.

migration is post-deploy

Add another index that includes the cell_name to serve queries
that filter on a subset of cells.

migration is post-deploy
@lynnagara lynnagara requested review from a team and markstory March 6, 2026 22:34
@lynnagara lynnagara requested a review from a team as a code owner March 6, 2026 22:34
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 6, 2026

This PR has a migration; here is the generated SQL for src/sentry/migrations/1048_organizationmapping_cell_name_idx.py

for 1048_organizationmapping_cell_name_idx in sentry

--
-- Create index sentry_orgmapping_cell_name_date_updated_id_idx on F(cell_name), TruncSecond(F(date_updated)), F(id) on model organizationmapping
--
CREATE INDEX CONCURRENTLY "sentry_orgmapping_cell_name_date_updated_id_idx" ON "sentry_organizationmapping" ("region_name", (DATE_TRUNC('second', "date_updated" AT TIME ZONE 'UTC')), "id");

Copy link
Copy Markdown
Member

@wedamija wedamija left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. What query are you hoping to use this on btw? Are you wanting to filter to some subset of ids within a second?

@lynnagara
Copy link
Copy Markdown
Member Author

lynnagara commented Mar 6, 2026

lgtm. What query are you hoping to use this on btw? Are you wanting to filter to some subset of ids within a second?

this index matches the ordering that SynapsePaginator expects https://github.com/getsentry/sentry/blob/master/src/sentry/synapse/paginator.py

there is already an existing index with (TruncSecond(date_updated), id) but that didn't previously handle the case where we are requesting by a subset of cells (most of the time), hence the addition of this index (cell_name, TruncSecond(date_updated), id)

@lynnagara lynnagara merged commit ac6e00e into master Mar 6, 2026
78 checks passed
@lynnagara lynnagara deleted the org-mapping-idx-with-cell-name branch March 6, 2026 23:53
@wedamija
Copy link
Copy Markdown
Member

wedamija commented Mar 6, 2026

lgtm. What query are you hoping to use this on btw? Are you wanting to filter to some subset of ids within a second?

this index matches the ordering that SynapsePaginator expects https://github.com/getsentry/sentry/blob/master/src/sentry/synapse/paginator.py

there is already an existing index with (TruncSecond(date_updated), id) but that didn't previously handle the case where we are requesting by a subset of cells (most of the time), hence the addition of this index (cell_name, TruncSecond(date_updated), id)

Got it, so the id is just a tie breaker there. Makes sense.

Since that query is using an OR, it might be worth making sure the index gets used. I've sometimes seen weird behaviour from postgres in those cases, but might not be all that big of a deal here.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants