fix: remove-redundant-indexes-on-staging-tables - #6525
Open
ttoomey wants to merge 3 commits into
Open
Conversation
ttoomey
force-pushed
the
remove-redudnant-indexes-on-staging-tables
branch
from
May 25, 2026 02:07
c8f0d34 to
5446d33
Compare
ttoomey
commented
May 25, 2026
ttoomey
commented
Jun 1, 2026
| i.relname AS index_name, | ||
| am.amname AS access_method, | ||
| pg_get_indexdef(i.oid) AS index_def, | ||
| array_to_json(ARRAY( |
Contributor
Author
There was a problem hiding this comment.
Gets a list of columns for each index. Postgres stores these as an array of column numbers, which this query translates into names. It also splits out any extra payload columns (INCLUDE columns that are part of the index but not part of the core search key) into include_columns_json
ttoomey
commented
Jun 1, 2026
| ix.indisunique AS is_unique, | ||
| ix.indisprimary AS is_primary, | ||
| ix.indpred IS NOT NULL AS is_partial, | ||
| pg_get_expr(ix.indpred, ix.indrelid) AS predicate, |
Contributor
Author
There was a problem hiding this comment.
for partial indexes, this is the WHERE clause
ttoomey
marked this pull request as ready for review
June 2, 2026 01:08
ttoomey
force-pushed
the
remove-redudnant-indexes-on-staging-tables
branch
from
June 2, 2026 01:20
5c1bb01 to
16ba392
Compare
ttoomey
force-pushed
the
remove-redudnant-indexes-on-staging-tables
branch
from
June 2, 2026 01:21
16ba392 to
8495cf2
Compare
eanders
reviewed
Jun 2, 2026
| def staging_tables | ||
| conn.select_values(<<~SQL) | ||
| SELECT tablename FROM pg_tables | ||
| WHERE schemaname = 'public' |
Contributor
There was a problem hiding this comment.
Can we make this:
Suggested change
| WHERE schemaname = 'public' | |
| WHERE schemaname in ('public', 'hmis') |
That should find the indexes on the old 2022 tables if they exist.
eanders
reviewed
Jun 2, 2026
Comment on lines
+80
to
+81
| WHERE t.relname = #{conn.quote(table)} | ||
| AND n.nspname = 'public' |
Contributor
There was a problem hiding this comment.
Probably would need to update this as well.
eanders
approved these changes
Jun 2, 2026
eanders
left a comment
Contributor
There was a problem hiding this comment.
Looks like a good idea to me!
dtgreiner
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Merging this PR
Description
Remove redundant indexes on staging tables. These duplicates add bloat and degrade import performance.
Note the included migration is not reversible. It does not run in production though; the intent is for it to be run manually with:
Type of change
Schema cleanup, performance fix
Checklist before requesting review