Adding unique index check for schema_unused_indexes #108
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.
Currently the
schema_unused_indexes
view will return unique (non-primary) indexes if they are unused. This could be because the server has been recently restarted, or there haven't been any writes to the table since the last restart.This PR modifies the
schema_unused_indexes
view definition to filter out unique indexes. This is done via a join oninformation_schema.statistics
, making the new select:Since there's one row for each column in an index in the
statistics
table, I have it join on only the first column's row (s.SEQ_IN_INDEX = 1
).The join is on an
information_schema
table, and the view definition is under thep_s
heading, so I don't know if this join changes that categorization.Note this change will also require a modification of the help docs.