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

Adding unique index check for schema_unused_indexes #108

Closed
wants to merge 1 commit into from
Closed

Adding unique index check for schema_unused_indexes #108

wants to merge 1 commit into from

Conversation

ggunson
Copy link

@ggunson ggunson commented Sep 3, 2016

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 on information_schema.statistics, making the new select:

SELECT t.object_schema,
       t.object_name,
       t.index_name
  FROM performance_schema.table_io_waits_summary_by_index_usage t
 INNER JOIN information_schema.statistics s 
    ON t.object_schema = s.table_schema 
   AND t.object_name = s.table_name 
   AND t.index_name = s.index_name
 WHERE t.index_name IS NOT NULL
   AND t.count_star = 0
   AND t.object_schema != 'mysql'
   AND t.index_name != 'PRIMARY'
   AND s.NON_UNIQUE = 1
   AND s.SEQ_IN_INDEX = 1
 ORDER BY object_schema, object_name;

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 the p_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.

@mysql-oca-bot
Copy link

Hi, thank you for submitting this pull request. In order to consider your code we need you to sign the Oracle Contribution Agreement (OCA). Please review the details and follow the instructions at http://www.oracle.com/technetwork/community/oca-486395.html
Please make sure to include your MySQL bug system user (email) in the returned form.
Thanks

@mysql-oca-bot
Copy link

Hi, there was no response to our request to sign an OCA or confirm the code is submitted under the terms of the OCA. As such this request will be closed.
Thanks

@mysql-admin
Copy link

Sorry for the confusion - this was closed prematurely
==Omer

@mysql-admin mysql-admin reopened this Oct 4, 2016
@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment:
"I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it."
Thanks

@ggunson
Copy link
Author

ggunson commented Oct 4, 2016

I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow
bug http://bugs.mysql.com/bug.php?id=83257 for updates.
Thanks

@ggunson ggunson deleted the unique-check-on-schema-unused-indexes branch December 27, 2018 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants