Skip to content

Do not make db queries to find gitlab_schema of a table

Manoj M J requested to merge mmj-alter-index-fix into master

What does this MR do and why?

In !116921 (merged), we made some changes to how a gitlab_schema is inferred from a generated SQL query.

One of the changes in that MR was 24e67d99 (comment 1390497827), for ALTER INDEX index_name queries, where index_name was being misinterpreted as a table name. This index will not have it's YAML in the database dictionary, so it would error out since it cannot find a gitlab_schema for index_name.

To prevent this, we were internally figuring out the table that contained an index named index_name, and return the gitlab_schema of that table instead. We were gathering this information from the Gitlab::Database::PostgresIndex table. However, this information gathering means that we issue an SQL where query every time this code path is hit, which we should avoid.

Kamil made an upstream fix to pg_query to fix this problem when parsing SQL: https://github.com/pganalyze/pg_query/pull/285, and we have now updated to this version of pg_query: Update gitlab-labkit & pg_query gems (!121504 - merged), and hence this problem no longer exists.

So, in this MR, we remove the piece of code that tries to figure out the table that contained an index named index_name, as pg_query itself can handle this specific condition.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Manoj M J

Merge request reports