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

Check for duplicate indexes #42

Closed
mkindahl opened this issue Jan 26, 2024 · 1 comment · Fixed by #43 · May be fixed by #44
Closed

Check for duplicate indexes #42

mkindahl opened this issue Jan 26, 2024 · 1 comment · Fixed by #43 · May be fixed by #44
Assignees

Comments

@mkindahl
Copy link
Collaborator

mkindahl commented Jan 26, 2024

Check if there are duplicate indexes for a table, that is, two different indexes that are for the same relation and have the same set of key columns.

@mkindahl
Copy link
Collaborator Author

mkindahl commented Jan 29, 2024

This query will check for exactly the same set of columns as keys:

SELECT indrelid::regclass as relation,
       a.indexrelid::regclass as index1,
       b.indexrelid::regclass as index2
  FROM pg_index a JOIN pg_index b USING (indrelid, indkey)
 WHERE a.indexrelid != b.indexrelid;

It might be interesting to check if one index is redundant in the sense that there is another index that has the same set of initial columns. Something like:

CREATE TABLE foo (a int, b int, c int);
CREATE INDEX ON foo(a,b);
CREATE INDEX ON foo(a,b,c);

There seems to be a few customer cases with this kind of situation, especially if the customer creates a covering index but forget to remove the old index.

mkindahl added a commit to mkindahl/doctor that referenced this issue Jan 29, 2024
Add rule to check for duplicate indexes. Two indexes are duplicates if
they have different relation OID and are indexes for the same relation
and has *exactly* the same list of keys in the same order.

Note that we are not checking if an index is redundant (if one index
has a set of key columns that is a prefix of the other).

Complete timescale#42
mkindahl added a commit to mkindahl/doctor that referenced this issue Jan 29, 2024
Add rule to check for duplicate indexes. Two indexes are duplicates if
they have different relation OID and are indexes for the same relation
and has *exactly* the same list of keys in the same order.

Note that we are not checking if an index is redundant (if one index
has a set of key columns that is a prefix of the other).

Complete timescale#42
mkindahl added a commit to mkindahl/doctor that referenced this issue Jan 29, 2024
Add rule to check for duplicate indexes. Two indexes are duplicates if
they have different relation OID and are indexes for the same relation
and has *exactly* the same list of keys in the same order.

Note that we are not checking if an index is redundant (if one index
has a set of key columns that is a prefix of the other).

Complete timescale#42
@mkindahl mkindahl self-assigned this Jan 29, 2024
mkindahl added a commit to mkindahl/doctor that referenced this issue Jan 29, 2024
Add rule to check for duplicate indexes. Two indexes are duplicates if
they have different relation OID and are indexes for the same relation
and has *exactly* the same list of keys in the same order.

Note that we are not checking if an index is redundant (if one index
has a set of key columns that is a prefix of the other).

Complete timescale#42
mkindahl added a commit to mkindahl/doctor that referenced this issue Jan 29, 2024
Add rule to check for duplicate indexes. Two indexes are duplicates if
they have different relation OID and are indexes for the same relation
and has *exactly* the same list of keys in the same order.

Note that we are not checking if an index is redundant (if one index
has a set of key columns that is a prefix of the other).

Resolves timescale#42
mkindahl added a commit that referenced this issue Feb 5, 2024
Add rule to check for duplicate indexes. Two indexes are duplicates if
they have different relation OID and are indexes for the same relation
and has *exactly* the same list of keys in the same order.

Note that we are not checking if an index is redundant (if one index
has a set of key columns that is a prefix of the other).

Resolves #42
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 a pull request may close this issue.

1 participant