Fix a join in the postgres_indexes view
What does this MR do and why?
Fix a join in the postgres_indexes
view that didn't join index information properly when multiple indexes with the same name existed in different schemas. This could result in queries returning multiple rows for a single index, with potentially different index definitions.
How to set up and validate locally
- Before running the migration from this MR, setup the database:
create table main_schema_table (id serial not null primary key); create table gitlab_partitions_dynamic.gpd_schema_table (id serial not null primary key); create index testi1 on main_schema_table (id); create index testi1 on gitlab_partitions_dynamic.gpd_schema_table (id);
- Verify that we see extra entries for each index:
select schema, tablename, name, definition from postgres_indexes where name = 'testi1'; schema | tablename | name | definition ---------------------------+-------------------+--------+------------------------------------------------------------------------------------ public | main_schema_table | testi1 | CREATE INDEX testi1 ON public.main_schema_table USING btree (id) public | gpd_schema_table | testi1 | CREATE INDEX testi1 ON gitlab_partitions_dynamic.gpd_schema_table USING btree (id) gitlab_partitions_dynamic | main_schema_table | testi1 | CREATE INDEX testi1 ON public.main_schema_table USING btree (id) gitlab_partitions_dynamic | gpd_schema_table | testi1 | CREATE INDEX testi1 ON gitlab_partitions_dynamic.gpd_schema_table USING btree (id) (4 rows)
- Run the migration
rails db:migrate:up VERSION=20211018161447
- Verify that we only see a single entry per index per schema:
select schema, tablename, name, definition from postgres_indexes where name = 'testi1'; schema | tablename | name | definition ---------------------------+-------------------+--------+------------------------------------------------------------------------------------ public | main_schema_table | testi1 | CREATE INDEX testi1 ON public.main_schema_table USING btree (id) gitlab_partitions_dynamic | gpd_schema_table | testi1 | CREATE INDEX testi1 ON gitlab_partitions_dynamic.gpd_schema_table USING btree (id) (2 rows)
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Patrick Bair