Skip to content

Filter cross project dependencies by partition_id

Ref: #437855

What does this MR do and why?

This MR refactors Ci::BuildDependencies#all to filter cross project dependencies by partition_id.

This will allow us to take advantage of partition pruning and select the right partition automatically without scanning all of them.

Example of updated query

Before

SELECT p_ci_builds.*
FROM (
        (SELECT p_ci_builds.*
         FROM p_ci_builds
         WHERE p_ci_builds.type = 'Ci::Build'
           AND p_ci_builds.id IN
             (SELECT max(p_ci_builds.id) AS id
              FROM p_ci_builds
              WHERE p_ci_builds.type = 'Ci::Build'
                AND (p_ci_builds.retried = FALSE
                     OR p_ci_builds.retried IS NULL)
                AND (p_ci_builds.status IN ('success'))
                AND p_ci_builds.name = 'dependency'
                AND p_ci_builds.ref = 'feature'
                AND p_ci_builds.project_id = 1))) p_ci_builds
WHERE p_ci_builds.type = 'Ci::Build'
LIMIT 5

After

SELECT p_ci_builds.*
FROM (
        (SELECT p_ci_builds.*
         FROM p_ci_builds
         WHERE p_ci_builds.type = 'Ci::Build'
           AND p_ci_builds.id IN
             (SELECT max(p_ci_builds.id) AS id
              FROM p_ci_builds
              WHERE p_ci_builds.type = 'Ci::Build'
                AND (p_ci_builds.retried = FALSE
                     OR p_ci_builds.retried IS NULL)
                AND (p_ci_builds.status IN ('success'))
+               AND p_ci_builds.partition_id = 101
                AND p_ci_builds.name = 'dependency'
                AND p_ci_builds.ref = 'feature'
                AND p_ci_builds.project_id = 4))) p_ci_builds
WHERE p_ci_builds.type = 'Ci::Build'
LIMIT 5
Edited by Max Orefice

Merge request reports

Loading