Skip to content

Remove the `Gitlab::Database::Subquery.self_join` helper

Manoj M J requested to merge remove-subquery-helper into master

What does this MR do?

This removal is possible now because:

There was only one instance of usage of this helper (Gitlab::Database::Subquery.self_join) in our repo and this helper seems to be written specifically to issue a delete_all with limit.

And since now this is supported by default in Rails, there is no need to use a self_join and hence this helper can possibly be removed.

Going forward:

There are a couple of other instances of using self_join mechanism that I noticed, but without the use of this helper. (Like here & here), but I will tackle these in a different MR and re-write them to a simple where().limit().delete_all

Database queries

Before:

DELETE
FROM "geo_repository_updated_events"
WHERE "geo_repository_updated_events"."id" IN
    (SELECT "geo_repository_updated_events"."id"
     FROM "geo_repository_updated_events"
     INNER JOIN
       (SELECT "geo_repository_updated_events".*
        FROM "geo_repository_updated_events"
        LIMIT $1) t2 ON "geo_repository_updated_events"."id" = t2."id");

After:

DELETE
FROM "geo_repository_updated_events"
WHERE "geo_repository_updated_events"."id" IN
    (SELECT "geo_repository_updated_events"."id"
     FROM "geo_repository_updated_events"
     LIMIT $1);

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Toon Claes

Merge request reports