Query MergeRequestDiff#includes_any_commits?
from metadata table
What does this MR do and why?
Query commit shas from commits metadata table
In MergeRequestDiff#includes_any_commits?
, we query the merge_request_diff_commits
table to check if the diff contains at least one of the given SHAs.
Since the column merge_request_diff_commits.sha
will be moved to the merge_request_commits_metadata
table, we need to update the query to look in this table as well. We revert to the original behaviour when the feature flag merge_request_diff_commits_dedup
is disabled or the table merge_request_commits_metadata
has no records for the diff's commits.
References
Related to #527236
Database changes
Previous query
In the previous implementation, we queried the SHAs in batches of 1000
SELECT 1 AS one FROM "merge_request_diff_commits" WHERE "merge_request_diff_commits"."merge_request_diff_id" = 1 AND "merge_request_diff_commits"."sha" IN ('\x1b4bfb22711e78e892f5861687c33065', '\x1b4bfb22711e78e892f5861687c33065') LIMIT 1;
query plan: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/44743/commands/137346
New query
In the new implementation, we need to query SHAs from the merge_request_commits_metadata
table
SELECT 1 AS one
FROM "merge_request_commits_metadata"
WHERE "merge_request_commits_metadata"."project_id" = 29
AND "merge_request_commits_metadata"."sha" IN ('\x1b4bfb22711e78e892f5861687c33065', '\x1b4bfb22711e78e892f5861687c33065')
AND (EXISTS
(SELECT 1
FROM "merge_request_diff_commits"
WHERE "merge_request_diff_commits"."merge_request_diff_id" = 1
AND (merge_request_diff_commits.merge_request_commits_metadata_id = merge_request_commits_metadata.id))) LIMIT 1;
query plan: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/44748/commands/137472
MR acceptance checklist
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 #527236