Skip to content

Conversation

@saponifi3d
Copy link
Contributor

@saponifi3d saponifi3d commented Jan 9, 2026

Description

Got a few reports of slow load times when visiting pages, and @malwilley found this trace.

The trace shows this query:

SELECT
    "workflow_engine_incidentgroupopenperiod"."id",
    "workflow_engine_incidentgroupopenperiod"."date_updated", 
    "workflow_engine_incidentgroupopenperiod"."date_added", 
    "workflow_engine_incidentgroupopenperiod"."incident_id", 
    "workflow_engine_incidentgroupopenperiod"."incident_identifier", 
    "workflow_engine_incidentgroupopenperiod"."group_open_period_id"
FROM 
    "workflow_engine_incidentgroupopenperiod"
INNER JOIN "sentry_groupopenperiod" ON ("workflow_engine_incidentgroupopenperiod"."group_open_period_id" = "sentry_groupopenperiod"."id")
INNER JOIN "sentry_project" ON ("sentry_groupopenperiod"."project_id" = "sentry_project"."id")
WHERE (
    "sentry_project"."organization_id" = %s
AND
    "workflow_engine_incidentgroupopenperiod"."incident_identifier" = %s)
ORDER BY "workflow_engine_incidentgroupopenperiod"."id" ASC LIMIT 1

Being the slow down. This query is slow because the incident_identifier here is doing a full table scan.

Adding this index will improve the filtering by incident_identifier, and hopefully improve performance enough to be negligible during page loads. If not, a next step could be to add the organization_id to remove the join with sentry_project.

NOTE -- this is running as a post deployment migration, because there are ~3.5m rows in this table.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 9, 2026
@saponifi3d saponifi3d marked this pull request as ready for review January 10, 2026 00:07
@saponifi3d saponifi3d requested review from a team as code owners January 10, 2026 00:07
@github-actions
Copy link
Contributor

This PR has a migration; here is the generated SQL for src/sentry/workflow_engine/migrations/0105_add_incident_identifer_index.py

for 0105_add_incident_identifer_index in workflow_engine

--
-- Create index workflow_en_inciden_2450f4_idx on field(s) incident_identifier of model incidentgroupopenperiod
--
CREATE INDEX CONCURRENTLY "workflow_en_inciden_2450f4_idx" ON "workflow_engine_incidentgroupopenperiod" ("incident_identifier");

@saponifi3d saponifi3d requested review from a team and kcons and removed request for a team January 10, 2026 00:07
Copy link
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. This is probably good enough to fix the query. I assume incident_identifier is close to unique as well?

@saponifi3d saponifi3d merged commit 925c8ff into master Jan 12, 2026
68 checks passed
@saponifi3d saponifi3d deleted the jcallender/aci/investigate-open-periods branch January 12, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants