Fix Project#upstream_projects and Project#downstream_projects 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
- 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 usingdisable_joins
. There are other cases, however, wheredisable_joins
works just fine so it should be investigated. - 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.
Edited by Dylan Griffith