Skip to content

Fix Pipeline#deployments and Pipeline#environments doing cross-joins

Extracted from #336423 (closed) .

We have identified these has_many through: relations cross-join between ci_* and non ci_* tables which will not be allowed once ci_* tables are moved to a new database.

Possible solutions

  1. As described in #336423 (closed) these problems can often be solved by using disable_joins. This is usually a simple fix but we must carefully compare the SQL before and after to determine that we don't have any unbounded datasets being loaded. You can see an example at !67834 (comment 647234358) where an unbounded intermediate dataset is being loaded when using disable_joins. There are other cases, however, where disable_joins works just fine so it should be investigated.
  2. Determine if this code can be re-written in some way to avoid the joins.

You can read more about typical solutions to these types of join problems at https://docs.gitlab.com/ee/development/database/multiple_databases.html#removing-joins-between-ci_-and-non-ci_-tables . It may turn out there is a simpler way to refactor this code that doesn't rely on these joins.

NOTE

This issue can be closed once these two MRs are merged:

  • This MR: !71894 (merged) which is fixing one of the cross-joins in Pipeline#environments_in_self_and_descendants, which is needed in order to remove the has_many :environments relation in Pipeline.
  • This MR: !71591 (merged) is fixing the cross-join in MergeRequest#environments, which is also needed to remove the has_many :environments relation in Pipeline.
    Please note that these two MRs are under a feature flag

Once the two feature flags have been removed, we can go ahead and remove the has_many :deployments and has_many :environments associations: #343036 (closed) as a cleanup.

Edited by Laura Montemayor