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

Multi-column index support and related checks #9

Open
2 tasks
ReinierMaas opened this issue Jan 4, 2023 · 0 comments
Open
2 tasks

Multi-column index support and related checks #9

ReinierMaas opened this issue Jan 4, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@ReinierMaas
Copy link

XRef: https://www.postgresql.org/docs/current/indexes-multicolumn.html

mkIssue : String -> String -> String -> Issue
mkIssue table fk cols =
let
qual = table ++ "." ++ fk
identifier = [ table, fk ]
description = "The foreign key constraint ‘" ++ qual ++ "’ is missing an index on its referencing side."
problems = [ "Updating rows in the referenced table causes a sequential scan on the referencing table."
, "Deleting rows from the referenced table causes a sequential scan on the referencing table." ]
solutions = [ "Create an index on ‘" ++ table ++ " (" ++ cols ++ ")’." ]
in
MkIssue identifier description problems solutions IsNonEmpty IsNonEmpty IsNonEmpty

There are two related warnings, one can be improved and the other can be newly added:

  • When you have a multi-index that covers the required column it should be detected and not issue the Index Foreign Key warning
  • We should try to minimise the number of indexes that a database has, we can detect overlapping indexes and propose to drop the prefix indexes

Having fewer indexes, especially overlapping indexes, gives a larger chance that a certain index is used. Reducing the number of indexes used makes them more likely to be in memory and updates need to write to fewer indexes. An index that is in memory is quicker to read from and updating fewer indexes on write speeds up writes.


There is a known bug with the Index Foreign Key warning:

In the check index_fk_ref, the order of the columns in the suggested index is not always correct.

@ReinierMaas ReinierMaas added the enhancement New feature or request label Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant