Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the logic that checks indices on foreign keys #113

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

Raveline
Copy link
Contributor

This PR fixes two limitations of our current index-on-fk checker:

  • It fails on compounded indexes;
  • It ignores the Primary Key when checking the indexes (any PK is also an index, but is not listed as such).

Copy link
Collaborator

@arybczak arybczak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks 👍

Please use punctuation in comments 🙏

idxColumnsSets :: [S.Set Text]
idxColumnsSets = cname . idxColumns <$> indexes
-- Map index on the given table name to a list of list of names
-- So that index on a and index on (b, c) becomes [[a], [b, c,]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-- So that index on a and index on (b, c) becomes [[a], [b, c,]]
-- so that index on a and index on (b, c) becomes [[a], [b, c]].

allCoverage = maybe [] pkColumns pkey:allIndexes

-- A foreign key is covered if it is a prefix of a list of indices.
-- So a FK on a is covered by an index on (a, b) but not an index on (b, a)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-- So a FK on a is covered by an index on (a, b) but not an index on (b, a)
-- So a FK on a is covered by an index on (a, b) but not an index on (b, a).

@Raveline
Copy link
Contributor Author

Raveline commented Sep 3, 2024

Sorry about punctuation, I'll try to remember this for next time.

@Raveline Raveline merged commit 1299379 into master Sep 3, 2024
7 checks passed
@Raveline Raveline deleted the fix-index-detection branch September 3, 2024 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants