Add missing composite index_ssh_signatures_on_commit_sha_and_project_id for ssh_signatures table
What does this MR do and why?
This MR adds a missing composite index index_ssh_signatures_on_commit_sha_and_project_id on the ssh_signatures table to support queries that filter by commit_sha only.
A previous MR (!216058 (merged)) introduced a composite index (project_id, commit_sha) to support Cells architecture requirements. However, this change removed the original unique index on commit_sha alone, which caused a production incident. Queries filtering by commit_sha without specifying project_id lost index coverage and started timing out.
In PostgreSQL B-tree indexes, the column order is critical for query efficiency. An index on (project_id, commit_sha) cannot efficiently support queries that filter only on commit_sha because the leading column must be specified first. According to PostgreSQL documentation on multi-column indexes:
"A multicolumn B-tree index can be used with query conditions that involve any subset of the index's columns, but the index is most efficient when there are constraints on the leading (leftmost) columns."
References
Database
Before
- NOTE: with
index_ssh_signatures_on_commit_shadropped
https://console.postgres.ai/gitlab/gitlab-production-main/sessions/46932/commands/142514
After
- NOTE: with
index_ssh_signatures_on_commit_shadropped
https://console.postgres.ai/gitlab/gitlab-production-main/sessions/46932/commands/142517
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 #583644 (closed)