.TH "MYSQLINDEXCHECK" "1" "May 09, 2012" "1.0.3" "MySQL Utilities" .SH NAME mysqlindexcheck \- Check for redundant or duplicate indexes on a list tables or databases . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .\" Man page generated from reStructeredText. . .SH SYNOPSIS .sp .nf .ft C mysqlindexcheck [options] db[:table] ... .ft P .fi .SH DESCRIPTION .sp This utility reads the indexes for one or more tables and identifies duplicate and potentially redundant indexes. .sp To check all tables in a database, specify only the database name. To check a specific table, name the table in \fIdb.table\fP format. It is possible to mix database and table names. .sp You can scan tables in any database except the internal databases \fBmysql\fP, \fBINFORMATION_SCHEMA\fP, and \fBperformance_schema\fP. .sp Depending on the index type, the utility applies the following rules to compare indexes (designated as \fBidx_a\fP and \fBidx_b\fP): .INDENT 0.0 .TP .B \fBBTREE\fP \fBidx_b\fP is redundant to \fBidx_a\fP if and only if the first \fIn\fP columns in \fBidx_b\fP also appear in \fBidx_a\fP. Order and uniqueness count. .TP .B \fBHASH\fP \fBidx_a\fP and \fBidx_b\fP are duplicates if and only if they contain the same columns in the same order. Uniqueness counts. .TP .B \fBSPATIAL\fP \fBidx_a\fP and \fBidx_b\fP are duplicates if and only if they contain the same column (only one column is permitted). .TP .B \fBFULLTEXT\fP \fBidx_b\fP is redundant to \fBidx_a\fP if and only if all columns in \fBidx_b\fP are included in \fBidx_a\fP. Order counts. .UNINDENT .sp To see \fBDROP\fP statements to drop redundant indexes, specify the \fI\%--show-drops\fP option. To examine the existing indexes, use the \fI\-\-verbose\fP option, which prints the equivalent \fBCREATE INDEX\fP (or \fBALTER TABLE\fP for primary keys. .sp To display the best or worst nonprimary key indexes for each table, use the \fI\%--best\fP or \fI\%--worst\fP option. This causes the output to show the best or worst indexes from tables with 10 or more rows. By default, each option shows five indexes. To override that, provide an integer value for the option. .sp To change the format of the index lists displayed for the \fI\%--show-indexes\fP, \fI\%--best\fP, and \fI\%--worst\fP options, use one of the following values with the \fI\-\-format\fP option: .INDENT 0.0 .TP .B \fBgrid\fP (default) Display output in grid or table format like that of the \fBmysql\fP monitor. .TP .B \fBcsv\fP Display output in comma\-separated values format. .TP .B \fBtab\fP Display output in tab\-separated format. .TP .B \fBsql\fP print SQL statements rather than a list. .TP .B \fBvertical\fP Display output in single\-column format like that of the \fB\eG\fP command for the \fBmysql\fP monitor. .UNINDENT .sp Note: The \fI\%--best\fP and \fI\%--worst\fP lists cannot be printed as SQL statements. .SH OPTIONS .sp \fBmysqlindexcheck\fP accepts the following command\-line options: .INDENT 0.0 .TP .B \-\-help Display a help message and exit. .UNINDENT .INDENT 0.0 .TP .B \-\-best[=] If \fI\%--stats\fP is given, limit index statistics to the best \fIN\fP indexes. The default value of \fIN\fP is 5 if omitted. .UNINDENT .INDENT 0.0 .TP .B \-\-format=, \-f Specify the index list display format for output produced by \fI\%--stats\fP. Permitted format values are \fBgrid\fP, \fBcsv\fP, \fBtab\fP, \fBsql\fP, and \fBvertical\fP. The default is \fBgrid\fP. .UNINDENT .INDENT 0.0 .TP .B \-\-server= Connection information for the server in <\fIuser\fP>[:<\fIpasswd\fP>]@<\fIhost\fP>[:<\fIport\fP>][:<\fIsocket\fP>] format. .UNINDENT .INDENT 0.0 .TP .B \-\-show\-drops, \-d Display \fBDROP\fP statements for dropping indexes. .UNINDENT .INDENT 0.0 .TP .B \-\-show\-indexes, \-i Display indexes for each table. .UNINDENT .INDENT 0.0 .TP .B \-\-skip, \-s Skip tables that do not exist. .UNINDENT .INDENT 0.0 .TP .B \-\-stats Show index performance statistics. .UNINDENT .INDENT 0.0 .TP .B \-\-verbose, \-v Specify how much information to display. Use this option multiple times to increase the amount of information. For example, \fI\-v\fP = verbose, \fI\-vv\fP = more verbose, \fI\-vvv\fP = debug. .UNINDENT .INDENT 0.0 .TP .B \-\-version Display version information and exit. .UNINDENT .INDENT 0.0 .TP .B \-\-worst[=] If \fI\%--stats\fP is given, limit index statistics to the worst \fIN\fP indexes. The default value of \fIN\fP is 5 if omitted. .UNINDENT .SH NOTES .sp You must provide connection parameters (user, host, password, and so forth) for an account that has the appropriate privileges to read all objects accessed during the operation. .sp For the \fI\-\-format\fP option, the permitted values are not case sensitive. In addition, values may be specified as any unambiguous prefix of a valid value. For example, \fI\-\-format=g\fP specifies the grid format. An error occurs if a prefix matches more than one valid value. .SH EXAMPLES .sp To check all tables in the \fBemployees\fP database on the local server to see the possible redundant and duplicate indexes, use this command: .sp .nf .ft C $ mysqlindexcheck \-\-server=root@localhost employees # Source on localhost: ... connected. # The following indexes are duplicates or redundant \e for table employees.dept_emp: # CREATE INDEX emp_no ON employees.dept_emp (emp_no) USING BTREE # may be redundant or duplicate of: ALTER TABLE employees.dept_emp ADD PRIMARY KEY (emp_no, dept_no) # The following indexes are duplicates or redundant \e for table employees.dept_manager: # CREATE INDEX emp_no ON employees.dept_manager (emp_no) USING BTREE # may be redundant or duplicate of: ALTER TABLE employees.dept_manager ADD PRIMARY KEY (emp_no, dept_no) # The following indexes are duplicates or redundant \e for table employees.salaries: # CREATE INDEX emp_no ON employees.salaries (emp_no) USING BTREE # may be redundant or duplicate of: ALTER TABLE employees.salaries ADD PRIMARY KEY (emp_no, from_date) # The following indexes are duplicates or redundant \e for table employees.titles: # CREATE INDEX emp_no ON employees.titles (emp_no) USING BTREE # may be redundant or duplicate of: ALTER TABLE employees.titles ADD PRIMARY KEY (emp_no, title, from_date) .ft P .fi .SH COPYRIGHT .sp Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. .sp This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. .sp This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. .sp You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110\-1301 USA .SH AUTHOR MySQL Utilities Team .SH COPYRIGHT 2010, Oracle and/or its affiliates. All rights reserved. .\" Generated by docutils manpage writer. .\" .