1MK-DUPLICATE-KEY-CHECKEURs(e1r)Contributed Perl DocumentMaKt-iDoUnPLICATE-KEY-CHECKER(1)
2
3
4

NAME

6       mk-duplicate-key-checker - Find duplicate indexes and foreign keys on
7       MySQL tables.
8

SYNOPSIS

10          mk-duplicate-key-checker --host host1
11

RISKS

13       The following section is included to inform users about the potential
14       risks, whether known or unknown, of using this tool.  The two main
15       categories of risks are those created by the nature of the tool (e.g.
16       read-only tools vs. read-write tools) and those created by bugs.
17
18       mk-duplicate-key-checker is a read-only tool that executes SHOW CREATE
19       TABLE and related queries to inspect table structures, and thus is very
20       low-risk.
21
22       At the time of this release, there is an unconfirmed bug that causes
23       the tool to crash.
24
25       The authoritative source for updated information is always the online
26       issue tracking system.  Issues that affect this tool will be marked as
27       such.  You can see a list of such issues at the following URL:
28       http://www.maatkit.org/bugs/mk-duplicate-key-checker
29       <http://www.maatkit.org/bugs/mk-duplicate-key-checker>.
30
31       See also "BUGS" for more information on filing bugs and getting help.
32

DESCRIPTION

34       This program examines the output of SHOW CREATE TABLE on MySQL tables,
35       and if it finds indexes that cover the same columns as another index in
36       the same order, or cover an exact leftmost prefix of another index, it
37       prints out the suspicious indexes.  By default, indexes must be of the
38       same type, so a BTREE index is not a duplicate of a FULLTEXT index,
39       even if they have the same colums.  You can override this.
40
41       It also looks for duplicate foreign keys.  A duplicate foreign key
42       covers the same columns as another in the same table, and references
43       the same parent table.
44

OPTIONS

46       --all-structs
47           Compare indexes with different structs (BTREE, HASH, etc).
48
49           By default this is disabled, because a BTREE index that covers the
50           same columns as a FULLTEXT index is not really a duplicate, for
51           example.
52
53       --ask-pass
54           Prompt for a password when connecting to MySQL.
55
56       --charset
57           short form: -A; type: string
58
59           Default character set.  If the value is utf8, sets Perl's binmode
60           on STDOUT to utf8, passes the mysql_enable_utf8 option to
61           DBD::mysql, and runs SET NAMES UTF8 after connecting to MySQL.  Any
62           other value sets binmode on STDOUT without the utf8 layer, and runs
63           SET NAMES after connecting to MySQL.
64
65       --[no]clustered
66           default: yes
67
68           PK columns appended to secondary key is duplicate.
69
70           Detects when a suffix of a secondary key is a leftmost prefix of
71           the primary key, and treats it as a duplicate key.  Only detects
72           this condition on storage engines whose primary keys are clustered
73           (currently InnoDB and solidDB).
74
75           Clustered storage engines append the primary key columns to the
76           leaf nodes of all secondary keys anyway, so you might consider it
77           redundant to have them appear in the internal nodes as well.  Of
78           course, you may also want them in the internal nodes, because just
79           having them at the leaf nodes won't help for some queries.  It does
80           help for covering index queries, however.
81
82           Here's an example of a key that is considered redundant with this
83           option:
84
85             PRIMARY KEY  (`a`)
86             KEY `b` (`b`,`a`)
87
88           The use of such indexes is rather subtle.  For example, suppose you
89           have the following query:
90
91             SELECT ... WHERE b=1 ORDER BY a;
92
93           This query will do a filesort if we remove the index on "b,a".  But
94           if we shorten the index on "b,a" to just "b" and also remove the
95           ORDER BY, the query should return the same results.
96
97           The tool suggests shortening duplicate clustered keys by dropping
98           the key and re-adding it without the primary key prefix.  The
99           shortened clustered key may still duplicate another key, but the
100           tool cannot currently detect when this happens without being ran a
101           second time to re-check the newly shortened clustered keys.
102           Therefore, if you shorten any duplicate clusterted keys, you should
103           run the tool again.
104
105       --config
106           type: Array
107
108           Read this comma-separated list of config files; if specified, this
109           must be the first option on the command line.
110
111       --databases
112           short form: -d; type: hash
113
114           Check only this comma-separated list of databases.
115
116       --defaults-file
117           short form: -F; type: string
118
119           Only read mysql options from the given file.  You must give an
120           absolute pathname.
121
122       --engines
123           short form: -e; type: hash
124
125           Check only tables whose storage engine is in this comma-separated
126           list.
127
128       --help
129           Show help and exit.
130
131       --host
132           short form: -h; type: string
133
134           Connect to host.
135
136       --ignore-databases
137           type: Hash
138
139           Ignore this comma-separated list of databases.
140
141       --ignore-engines
142           type: Hash
143
144           Ignore this comma-separated list of storage engines.
145
146       --ignore-order
147           Ignore index order so KEY(a,b) duplicates KEY(b,a).
148
149       --ignore-tables
150           type: Hash
151
152           Ignore this comma-separated list of tables.  Table names may be
153           qualified with the database name.
154
155       --key-types
156           type: string; default: fk
157
158           Check for duplicate f=foreign keys, k=keys or fk=both.
159
160       --password
161           short form: -p; type: string
162
163           Password to use when connecting.
164
165       --pid
166           type: string
167
168           Create the given PID file.  The file contains the process ID of the
169           script.  The PID file is removed when the script exits.  Before
170           starting, the script checks if the PID file already exists.  If it
171           does not, then the script creates and writes its own PID to it.  If
172           it does, then the script checks the following: if the file contains
173           a PID and a process is running with that PID, then the script dies;
174           or, if there is no process running with that PID, then the script
175           overwrites the file with its own PID and starts; else, if the file
176           contains no PID, then the script dies.
177
178       --port
179           short form: -P; type: int
180
181           Port number to use for connection.
182
183       --set-vars
184           type: string; default: wait_timeout=10000
185
186           Set these MySQL variables.  Immediately after connecting to MySQL,
187           this string will be appended to SET and executed.
188
189       --socket
190           short form: -S; type: string
191
192           Socket file to use for connection.
193
194       --[no]sql
195           default: yes
196
197           Print DROP KEY statement for each duplicate key.  By default an
198           ALTER TABLE DROP KEY statement is printed below each duplicate key
199           so that, if you want to remove the duplicate key, you can copy-
200           paste the statement into MySQL.
201
202           To disable printing these statements, specify --nosql.
203
204       --[no]summary
205           default: yes
206
207           Print summary of indexes at end of output.
208
209       --tables
210           short form: -t; type: hash
211
212           Check only this comma-separated list of tables.
213
214           Table names may be qualified with the database name.
215
216       --user
217           short form: -u; type: string
218
219           User for login if not current user.
220
221       --verbose
222           short form: -v
223
224           Output all keys and/or foreign keys found, not just redundant ones.
225
226       --version
227           Show version and exit.
228

DSN OPTIONS

230       These DSN options are used to create a DSN.  Each option is given like
231       "option=value".  The options are case-sensitive, so P and p are not the
232       same option.  There cannot be whitespace before or after the "=" and if
233       the value contains whitespace it must be quoted.  DSN options are
234       comma-separated.  See the maatkit manpage for full details.
235
236       ·   A
237
238           dsn: charset; copy: yes
239
240           Default character set.
241
242       ·   D
243
244           dsn: database; copy: yes
245
246           Default database.
247
248       ·   F
249
250           dsn: mysql_read_default_file; copy: yes
251
252           Only read default options from the given file
253
254       ·   h
255
256           dsn: host; copy: yes
257
258           Connect to host.
259
260       ·   p
261
262           dsn: password; copy: yes
263
264           Password to use when connecting.
265
266       ·   P
267
268           dsn: port; copy: yes
269
270           Port number to use for connection.
271
272       ·   S
273
274           dsn: mysql_socket; copy: yes
275
276           Socket file to use for connection.
277
278       ·   u
279
280           dsn: user; copy: yes
281
282           User for login if not current user.
283

DOWNLOADING

285       You can download Maatkit from Google Code at
286       <http://code.google.com/p/maatkit/>, or you can get any of the tools
287       easily with a command like the following:
288
289          wget http://www.maatkit.org/get/toolname
290          or
291          wget http://www.maatkit.org/trunk/toolname
292
293       Where "toolname" can be replaced with the name (or fragment of a name)
294       of any of the Maatkit tools.  Once downloaded, they're ready to run; no
295       installation is needed.  The first URL gets the latest released version
296       of the tool, and the second gets the latest trunk code from Subversion.
297

ENVIRONMENT

299       The environment variable "MKDEBUG" enables verbose debugging output in
300       all of the Maatkit tools:
301
302          MKDEBUG=1 mk-....
303

SYSTEM REQUIREMENTS

305       You need the following Perl modules: DBI and DBD::mysql.
306

BUGS

308       For list of known bugs see
309       http://www.maatkit.org/bugs/mk-duplicate-key-checker
310       <http://www.maatkit.org/bugs/mk-duplicate-key-checker>.
311
312       Please use Google Code Issues and Groups to report bugs or request
313       support: <http://code.google.com/p/maatkit/>.  You can also join
314       #maatkit on Freenode to discuss Maatkit.
315
316       Please include the complete command-line used to reproduce the problem
317       you are seeing, the version of all MySQL servers involved, the complete
318       output of the tool when run with "--version", and if possible,
319       debugging output produced by running with the "MKDEBUG=1" environment
320       variable.
321

COPYRIGHT, LICENSE AND WARRANTY

323       This program is copyright 2007-2010 Baron Schwartz.  Feedback and
324       improvements are welcome.
325
326       THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
327       WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
328       MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
329
330       This program is free software; you can redistribute it and/or modify it
331       under the terms of the GNU General Public License as published by the
332       Free Software Foundation, version 2; OR the Perl Artistic License.  On
333       UNIX and similar systems, you can issue `man perlgpl' or `man
334       perlartistic' to read these licenses.
335
336       You should have received a copy of the GNU General Public License along
337       with this program; if not, write to the Free Software Foundation, Inc.,
338       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
339

AUTHOR

341       Baron Schwartz, Daniel Nichter
342

ABOUT MAATKIT

344       This tool is part of Maatkit, a toolkit for power users of MySQL.
345       Maatkit was created by Baron Schwartz; Baron and Daniel Nichter are the
346       primary code contributors.  Both are employed by Percona.  Financial
347       support for Maatkit development is primarily provided by Percona and
348       its clients.
349

VERSION

351       This manual page documents Ver 1.2.13 Distrib 6839 $Revision: 6831 $.
352
353
354
355perl v5.12.1                      2010-08-01       MK-DUPLICATE-KEY-CHECKER(1)
Impressum