Skip to content

Replace query used by `OrphanedRemediationsCleanupWorker`

What does this MR do and why?

This MR is a spin-off from Deleted `vulnerability_remediations` leave behi... (!160579 - merged) • Michael Becker • 17.4

based on this thread

While trying to fix the issue of orphaned uploads, we ran into the issue of the existing query timing out in production.

That resulted in two spin-off MRs:

  • This MR: removing an unnecessary join from the existing query
  • !161891 (merged): adding additional metadata to the worker's logs

With these two MRs merged, we will have better insight into how to further improve this query in production

SQL

Current

SELECT
    "vulnerability_remediations"."id"
FROM
    "vulnerability_remediations"
    LEFT OUTER JOIN "vulnerability_findings_remediations" ON "vulnerability_findings_remediations"."vulnerability_remediation_id" = "vulnerability_remediations"."id"
    LEFT OUTER JOIN "vulnerability_occurrences" ON "vulnerability_occurrences"."id" = "vulnerability_findings_remediations"."vulnerability_occurrence_id"
WHERE
    "vulnerability_occurrences"."id" IS NULL

New

SELECT
    "vulnerability_remediations"."id"
FROM
    "vulnerability_remediations"
    LEFT OUTER JOIN "vulnerability_findings_remediations" ON "vulnerability_findings_remediations"."vulnerability_remediation_id" = "vulnerability_remediations"."id"
WHERE
    "vulnerability_findings_remediations"."id" IS NULL

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #462724 (closed)

Edited by Michael Becker

Merge request reports

Loading