Skip to content

Conversation

@cathteng
Copy link
Member

@cathteng cathteng commented Nov 6, 2025

A group should only be associated with 1 detector. This is a huge table so making it post-deploy, but we still might fail to acquire the lock...

@cathteng cathteng requested review from a team as code owners November 6, 2025 22:45
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 6, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

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

for 0095_unique_detectorgroup_group in workflow_engine

--
-- Alter field group on detectorgroup
--
SET CONSTRAINTS "workflow_engine_dete_group_id_9ff57c8f_fk_sentry_gr" IMMEDIATE; ALTER TABLE "workflow_engine_detectorgroup" DROP CONSTRAINT "workflow_engine_dete_group_id_9ff57c8f_fk_sentry_gr";
DROP INDEX CONCURRENTLY IF EXISTS "workflow_engine_detectorgroup_group_id_9ff57c8f";
CREATE UNIQUE INDEX CONCURRENTLY "workflow_engine_detectorgroup_group_id_9ff57c8f_uniq" ON "workflow_engine_detectorgroup" ("group_id");
ALTER TABLE "workflow_engine_detectorgroup" ADD CONSTRAINT "workflow_engine_detectorgroup_group_id_9ff57c8f_uniq" UNIQUE USING INDEX "workflow_engine_detectorgroup_group_id_9ff57c8f_uniq";
ALTER TABLE "workflow_engine_detectorgroup" ADD CONSTRAINT "workflow_engine_dete_group_id_9ff57c8f_fk_sentry_gr" FOREIGN KEY ("group_id") REFERENCES "sentry_groupedmessage" ("id") DEFERRABLE INITIALLY DEFERRED NOT VALID;
ALTER TABLE "workflow_engine_detectorgroup" VALIDATE CONSTRAINT "workflow_engine_dete_group_id_9ff57c8f_fk_sentry_gr";
--
-- Alter unique_together for detectorgroup (0 constraint(s))
--
ALTER TABLE "workflow_engine_detectorgroup" DROP CONSTRAINT "workflow_engine_detector_detector_id_group_id_02ffc513_uniq";

Comment on lines 31 to 41
migrations.AlterUniqueTogether(
name="detectorgroup",
unique_together=set(),
),
migrations.AlterField(
model_name="detectorgroup",
name="group",
field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="sentry.group", unique=True
),
),
Copy link
Member

Choose a reason for hiding this comment

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

We should switch this order around, otherwise we won't be covered by the unique index for a while and might introduce bad rows

class Meta:
db_table = "workflow_engine_detectorgroup"
app_label = "workflow_engine"
unique_together = (("detector", "group"),)
Copy link
Member

Choose a reason for hiding this comment

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

I think we're safe enough without this index. If we search on detector_id, group_id it can just use the unique on group. The only case I can think of where this old index might have been helpful if we did where detector_id = x order by group_id, which doesn't seem like it'd happen too often

@cathteng cathteng marked this pull request as draft November 7, 2025 19:05
@cathteng cathteng force-pushed the cathy/aci/unique-detectorgroup-group branch from 82c0867 to b769a0c Compare November 10, 2025 17:32
@cathteng cathteng marked this pull request as ready for review November 10, 2025 17:32
@cathteng cathteng requested review from a team and wedamija November 10, 2025 17:32
Copy link
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

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

lgtm, might be nice to have a second pass from @wedamija tho too.

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 might end up being painful to create!

@cathteng cathteng merged commit 3dcf2c7 into master Nov 10, 2025
65 of 66 checks passed
@cathteng cathteng deleted the cathy/aci/unique-detectorgroup-group branch November 10, 2025 18:09
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.

4 participants