Update alert group search to force index in MySQL #4731
Merged
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.
Related to https://github.com/grafana/oncall-private/issues/2679
Confirmed the query rewriting works via MySQL query logs (index is also forced for the stats queries):
2024-07-24T19:50:59.482751Z 3977 Query SELECT
alerts_alertgroup.
idFROM
alerts_alertgroupFORCE INDEX (
alert_group_list_index) WHERE (
alerts_alertgroup.
channel_idIN (13) AND (1) AND (
alerts_alertgroup.
public_primary_keyLIKE 'test' OR
alerts_alertgroup.
inside_organization_numberLIKE 'test' OR
alerts_alertgroup.
web_title_cacheLIKE '%test%') AND
alerts_alertgroup.
root_alert_group_idIS NULL AND ((
alerts_alertgroup.
silenced= ('0') AND
alerts_alertgroup.
acknowledged= ('0') AND
alerts_alertgroup.
resolved= ('0')) OR (
alerts_alertgroup.
acknowledged= ('1') AND
alerts_alertgroup.
resolved= ('0'))) AND
alerts_alertgroup.
started_at>= '2024-06-24 19:50:58' AND
alerts_alertgroup.
started_at<= '2024-07-24 19:50:58') ORDER BY
alerts_alertgroup.
started_atDESC LIMIT 26
Rewriting will only be applied to the alert group search queries, when the feature flags are enabled. Dependency was already listed as a requirement.