5.11 mysqlindexcheck — Identify Potentially Redundant Table Indexes

This utility reads the indexes for one or more tables and
identifies duplicate and potentially redundant indexes.

To check all tables in a database, only specify the database name.
To check a specific table, name the table in
db.table format. It is possible to mix
database and table names.

You can scan tables in any database except the internal databases
mysql,
INFORMATION_SCHEMA, and
performance_schema.

Depending on the index type, the utility applies the following
rules to compare indexes (designated as idx_a
and idx_b):

BTREE

idx_b is redundant to
idx_a if and only if all the columns from
idx_b are a prefix of
idx_a. Order and uniqueness count.

HASH

idx_a and idx_b are
redundant if they are duplicates, i.e. if and only if they
contain the same columns in the same order.

SPATIAL

idx_a and idx_b are
duplicates if and only if they contain the same column (only
one column is permitted).

FULLTEXT

idx_b is redundant to
idx_a if and only if all columns in
idx_b are included in
idx_a. Order does not count.

To see DROP statements drop redundant indexes,
specify the --show-drops
option. To examine the existing indexes, use the
--verbose option, which
prints the equivalent CREATE
INDEX (or ALTER
TABLE) for primary keys.

To display the best or worst non-primary key indexes for each
table, use the --best or
--worst 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.

OPTIONS

If --stats is given,
limit index statistics to the best N
indexes. The default value of N is 5 if
omitted.

--format=index_format,
-findex_format

Specify the index list display format for output produced by
--stats. Permitted
format values are grid,
csv,
tab,
sql, and
vertical. The default is
grid.

--report-indexes, -r

Reports if a table has neither UNIQUE indexes nor a PRIMARY
key.

--server=source

Connection information for the server.

To connect to a server, it is necessary to specify connection
parameters such as the user name, host name, password, and either a
port or socket. MySQL Utilities provides a number of ways to supply this
information. All of the methods require specifying your choice via a
command-line option such as --server, --master, --slave, etc. The
methods include the following in order of most secure to least secure.

The name of the SSL certificate file to use for establishing a
secure connection.

--ssl-key

The name of the SSL key file to use for establishing a secure
connection.

--ssl

Specifies if the server connection requires use of SSL. If an
encrypted connection cannot be established, the connection
attempt fails. Default setting is 0 (SSL not required).

--stats

Show index performance statistics.

--verbose, -v

Specify how much information to display. Use this option
multiple times to increase the amount of information. For
example, -v = verbose, -vv =
more verbose, -vvv = debug.

--version

Display version information and exit.

--worst[=N]

If --stats is also
passed in, limit index statistics to the worst
N indexes. The default value of
N is 5, if omitted.

NOTES

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.

For the --format option,
the permitted values are not case sensitive. In addition, values
may be specified as any unambiguous prefix of a valid value. For
example, --format=g
specifies the grid format. An error occurs if a prefix matches
more than one valid value.

The path to the MySQL client tools should be included in the
PATH environment variable in order to use the
authentication mechanism with login-paths. This will allow the
utility to use the my_print_defaults tools
which is required to read the login-path values from the login
configuration file (.mylogin.cnf).

EXAMPLES

To check all tables in the employees database
on the local server to see the possible redundant and duplicate
indexes, use this command: