~percona-toolkit-dev/percona-toolkit/1.0

« back to all changes in this revision

Viewing changes to docs/user/pt-duplicate-key-checker.rst

  • Committer: Daniel Nichter
  • Date: 2011-07-14 19:08:47 UTC
  • Revision ID: daniel@percona.com-20110714190847-lggalkuvdrh7c4jp
Add standard pkg files (COPYING, README, etc.), percona-toolkit.pod, and user docs.  Remove dev/docs/html.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
########################
 
3
pt-duplicate-key-checker
 
4
########################
 
5
 
 
6
.. highlight:: perl
 
7
 
 
8
 
 
9
****
 
10
NAME
 
11
****
 
12
 
 
13
 
 
14
pt-duplicate-key-checker - Find duplicate indexes and foreign keys on MySQL tables.
 
15
 
 
16
 
 
17
********
 
18
SYNOPSIS
 
19
********
 
20
 
 
21
 
 
22
Usage: pt-duplicate-key-checker [OPTION...] [DSN]
 
23
 
 
24
pt-duplicate-key-checker examines MySQL tables for duplicate or redundant
 
25
indexes and foreign keys.  Connection options are read from MySQL option files.
 
26
 
 
27
 
 
28
.. code-block:: perl
 
29
 
 
30
    pt-duplicate-key-checker --host host1
 
31
 
 
32
 
 
33
 
 
34
*****
 
35
RISKS
 
36
*****
 
37
 
 
38
 
 
39
The following section is included to inform users about the potential risks,
 
40
whether known or unknown, of using this tool.  The two main categories of risks
 
41
are those created by the nature of the tool (e.g. read-only tools vs. read-write
 
42
tools) and those created by bugs.
 
43
 
 
44
pt-duplicate-key-checker is a read-only tool that executes SHOW CREATE TABLE and
 
45
related queries to inspect table structures, and thus is very low-risk.
 
46
 
 
47
At the time of this release, there is an unconfirmed bug that causes the tool
 
48
to crash.
 
49
 
 
50
The authoritative source for updated information is always the online issue
 
51
tracking system.  Issues that affect this tool will be marked as such.  You can
 
52
see a list of such issues at the following URL:
 
53
`http://www.percona.com/bugs/pt-duplicate-key-checker <http://www.percona.com/bugs/pt-duplicate-key-checker>`_.
 
54
 
 
55
See also "BUGS" for more information on filing bugs and getting help.
 
56
 
 
57
 
 
58
***********
 
59
DESCRIPTION
 
60
***********
 
61
 
 
62
 
 
63
This program examines the output of SHOW CREATE TABLE on MySQL tables, and if
 
64
it finds indexes that cover the same columns as another index in the same
 
65
order, or cover an exact leftmost prefix of another index, it prints out
 
66
the suspicious indexes.  By default, indexes must be of the same type, so a
 
67
BTREE index is not a duplicate of a FULLTEXT index, even if they have the same
 
68
columns.  You can override this.
 
69
 
 
70
It also looks for duplicate foreign keys.  A duplicate foreign key covers the
 
71
same columns as another in the same table, and references the same parent
 
72
table.
 
73
 
 
74
 
 
75
*******
 
76
OPTIONS
 
77
*******
 
78
 
 
79
 
 
80
This tool accepts additional command-line arguments.  Refer to the
 
81
"SYNOPSIS" and usage information for details.
 
82
 
 
83
 
 
84
--all-structs
 
85
 
 
86
 Compare indexes with different structs (BTREE, HASH, etc).
 
87
 
 
88
 By default this is disabled, because a BTREE index that covers the same columns
 
89
 as a FULLTEXT index is not really a duplicate, for example.
 
90
 
 
91
 
 
92
 
 
93
--ask-pass
 
94
 
 
95
 Prompt for a password when connecting to MySQL.
 
96
 
 
97
 
 
98
 
 
99
--charset
 
100
 
 
101
 short form: -A; type: string
 
102
 
 
103
 Default character set.  If the value is utf8, sets Perl's binmode on
 
104
 STDOUT to utf8, passes the mysql_enable_utf8 option to DBD::mysql, and runs SET
 
105
 NAMES UTF8 after connecting to MySQL.  Any other value sets binmode on STDOUT
 
106
 without the utf8 layer, and runs SET NAMES after connecting to MySQL.
 
107
 
 
108
 
 
109
 
 
110
--[no]clustered
 
111
 
 
112
 default: yes
 
113
 
 
114
 PK columns appended to secondary key is duplicate.
 
115
 
 
116
 Detects when a suffix of a secondary key is a leftmost prefix of the primary
 
117
 key, and treats it as a duplicate key.  Only detects this condition on storage
 
118
 engines whose primary keys are clustered (currently InnoDB and solidDB).
 
119
 
 
120
 Clustered storage engines append the primary key columns to the leaf nodes of
 
121
 all secondary keys anyway, so you might consider it redundant to have them
 
122
 appear in the internal nodes as well.  Of course, you may also want them in the
 
123
 internal nodes, because just having them at the leaf nodes won't help for some
 
124
 queries.  It does help for covering index queries, however.
 
125
 
 
126
 Here's an example of a key that is considered redundant with this option:
 
127
 
 
128
 
 
129
 .. code-block:: perl
 
130
 
 
131
    PRIMARY KEY  (`a`)
 
132
    KEY `b` (`b`,`a`)
 
133
 
 
134
 
 
135
 The use of such indexes is rather subtle.  For example, suppose you have the
 
136
 following query:
 
137
 
 
138
 
 
139
 .. code-block:: perl
 
140
 
 
141
    SELECT ... WHERE b=1 ORDER BY a;
 
142
 
 
143
 
 
144
 This query will do a filesort if we remove the index on \ ``b,a``\ .  But if we
 
145
 shorten the index on \ ``b,a``\  to just \ ``b``\  and also remove the ORDER BY, the query
 
146
 should return the same results.
 
147
 
 
148
 The tool suggests shortening duplicate clustered keys by dropping the key
 
149
 and re-adding it without the primary key prefix.  The shortened clustered
 
150
 key may still duplicate another key, but the tool cannot currently detect
 
151
 when this happens without being ran a second time to re-check the newly
 
152
 shortened clustered keys.  Therefore, if you shorten any duplicate clustered
 
153
 keys, you should run the tool again.
 
154
 
 
155
 
 
156
 
 
157
--config
 
158
 
 
159
 type: Array
 
160
 
 
161
 Read this comma-separated list of config files; if specified, this must be the
 
162
 first option on the command line.
 
163
 
 
164
 
 
165
 
 
166
--databases
 
167
 
 
168
 short form: -d; type: hash
 
169
 
 
170
 Check only this comma-separated list of databases.
 
171
 
 
172
 
 
173
 
 
174
--defaults-file
 
175
 
 
176
 short form: -F; type: string
 
177
 
 
178
 Only read mysql options from the given file.  You must give an absolute pathname.
 
179
 
 
180
 
 
181
 
 
182
--engines
 
183
 
 
184
 short form: -e; type: hash
 
185
 
 
186
 Check only tables whose storage engine is in this comma-separated list.
 
187
 
 
188
 
 
189
 
 
190
--help
 
191
 
 
192
 Show help and exit.
 
193
 
 
194
 
 
195
 
 
196
--host
 
197
 
 
198
 short form: -h; type: string
 
199
 
 
200
 Connect to host.
 
201
 
 
202
 
 
203
 
 
204
--ignore-databases
 
205
 
 
206
 type: Hash
 
207
 
 
208
 Ignore this comma-separated list of databases.
 
209
 
 
210
 
 
211
 
 
212
--ignore-engines
 
213
 
 
214
 type: Hash
 
215
 
 
216
 Ignore this comma-separated list of storage engines.
 
217
 
 
218
 
 
219
 
 
220
--ignore-order
 
221
 
 
222
 Ignore index order so KEY(a,b) duplicates KEY(b,a).
 
223
 
 
224
 
 
225
 
 
226
--ignore-tables
 
227
 
 
228
 type: Hash
 
229
 
 
230
 Ignore this comma-separated list of tables.  Table names may be qualified with
 
231
 the database name.
 
232
 
 
233
 
 
234
 
 
235
--key-types
 
236
 
 
237
 type: string; default: fk
 
238
 
 
239
 Check for duplicate f=foreign keys, k=keys or fk=both.
 
240
 
 
241
 
 
242
 
 
243
--password
 
244
 
 
245
 short form: -p; type: string
 
246
 
 
247
 Password to use when connecting.
 
248
 
 
249
 
 
250
 
 
251
--pid
 
252
 
 
253
 type: string
 
254
 
 
255
 Create the given PID file.  The file contains the process ID of the script.
 
256
 The PID file is removed when the script exits.  Before starting, the script
 
257
 checks if the PID file already exists.  If it does not, then the script creates
 
258
 and writes its own PID to it.  If it does, then the script checks the following:
 
259
 if the file contains a PID and a process is running with that PID, then
 
260
 the script dies; or, if there is no process running with that PID, then the
 
261
 script overwrites the file with its own PID and starts; else, if the file
 
262
 contains no PID, then the script dies.
 
263
 
 
264
 
 
265
 
 
266
--port
 
267
 
 
268
 short form: -P; type: int
 
269
 
 
270
 Port number to use for connection.
 
271
 
 
272
 
 
273
 
 
274
--set-vars
 
275
 
 
276
 type: string; default: wait_timeout=10000
 
277
 
 
278
 Set these MySQL variables.  Immediately after connecting to MySQL, this string
 
279
 will be appended to SET and executed.
 
280
 
 
281
 
 
282
 
 
283
--socket
 
284
 
 
285
 short form: -S; type: string
 
286
 
 
287
 Socket file to use for connection.
 
288
 
 
289
 
 
290
 
 
291
--[no]sql
 
292
 
 
293
 default: yes
 
294
 
 
295
 Print DROP KEY statement for each duplicate key.  By default an ALTER TABLE
 
296
 DROP KEY statement is printed below each duplicate key so that, if you want to
 
297
 remove the duplicate key, you can copy-paste the statement into MySQL.
 
298
 
 
299
 To disable printing these statements, specify --nosql.
 
300
 
 
301
 
 
302
 
 
303
--[no]summary
 
304
 
 
305
 default: yes
 
306
 
 
307
 Print summary of indexes at end of output.
 
308
 
 
309
 
 
310
 
 
311
--tables
 
312
 
 
313
 short form: -t; type: hash
 
314
 
 
315
 Check only this comma-separated list of tables.
 
316
 
 
317
 Table names may be qualified with the database name.
 
318
 
 
319
 
 
320
 
 
321
--user
 
322
 
 
323
 short form: -u; type: string
 
324
 
 
325
 User for login if not current user.
 
326
 
 
327
 
 
328
 
 
329
--verbose
 
330
 
 
331
 short form: -v
 
332
 
 
333
 Output all keys and/or foreign keys found, not just redundant ones.
 
334
 
 
335
 
 
336
 
 
337
--version
 
338
 
 
339
 Show version and exit.
 
340
 
 
341
 
 
342
 
 
343
 
 
344
***********
 
345
DSN OPTIONS
 
346
***********
 
347
 
 
348
 
 
349
These DSN options are used to create a DSN.  Each option is given like
 
350
\ ``option=value``\ .  The options are case-sensitive, so P and p are not the
 
351
same option.  There cannot be whitespace before or after the \ ``=``\  and
 
352
if the value contains whitespace it must be quoted.  DSN options are
 
353
comma-separated.  See the percona-toolkit manpage for full details.
 
354
 
 
355
 
 
356
\* A
 
357
 
 
358
 dsn: charset; copy: yes
 
359
 
 
360
 Default character set.
 
361
 
 
362
 
 
363
 
 
364
\* D
 
365
 
 
366
 dsn: database; copy: yes
 
367
 
 
368
 Default database.
 
369
 
 
370
 
 
371
 
 
372
\* F
 
373
 
 
374
 dsn: mysql_read_default_file; copy: yes
 
375
 
 
376
 Only read default options from the given file
 
377
 
 
378
 
 
379
 
 
380
\* h
 
381
 
 
382
 dsn: host; copy: yes
 
383
 
 
384
 Connect to host.
 
385
 
 
386
 
 
387
 
 
388
\* p
 
389
 
 
390
 dsn: password; copy: yes
 
391
 
 
392
 Password to use when connecting.
 
393
 
 
394
 
 
395
 
 
396
\* P
 
397
 
 
398
 dsn: port; copy: yes
 
399
 
 
400
 Port number to use for connection.
 
401
 
 
402
 
 
403
 
 
404
\* S
 
405
 
 
406
 dsn: mysql_socket; copy: yes
 
407
 
 
408
 Socket file to use for connection.
 
409
 
 
410
 
 
411
 
 
412
\* u
 
413
 
 
414
 dsn: user; copy: yes
 
415
 
 
416
 User for login if not current user.
 
417
 
 
418
 
 
419
 
 
420
 
 
421
***********
 
422
DOWNLOADING
 
423
***********
 
424
 
 
425
 
 
426
Visit `http://www.percona.com/software/ <http://www.percona.com/software/>`_ to download the latest release of
 
427
Percona Toolkit.  Or, to get the latest release from the command line:
 
428
 
 
429
 
 
430
.. code-block:: perl
 
431
 
 
432
    wget percona.com/latest/percona-toolkit/PKG
 
433
 
 
434
 
 
435
Replace \ ``PKG``\  with \ ``tar``\ , \ ``rpm``\ , or \ ``deb``\  to download the package in that
 
436
format.  You can also get individual tools from the latest release:
 
437
 
 
438
 
 
439
.. code-block:: perl
 
440
 
 
441
    wget percona.com/latest/percona-toolkit/TOOL
 
442
 
 
443
 
 
444
Replace \ ``TOOL``\  with the name of any tool.
 
445
 
 
446
 
 
447
***********
 
448
ENVIRONMENT
 
449
***********
 
450
 
 
451
 
 
452
The environment variable \ ``PTDEBUG``\  enables verbose debugging output to STDERR.
 
453
To enable debugging and capture all output to a file, run the tool like:
 
454
 
 
455
 
 
456
.. code-block:: perl
 
457
 
 
458
    PTDEBUG=1 pt-duplicate-key-checker ... > FILE 2>&1
 
459
 
 
460
 
 
461
Be careful: debugging output is voluminous and can generate several megabytes
 
462
of output.
 
463
 
 
464
 
 
465
*******************
 
466
SYSTEM REQUIREMENTS
 
467
*******************
 
468
 
 
469
 
 
470
You need Perl, DBI, DBD::mysql, and some core packages that ought to be
 
471
installed in any reasonably new version of Perl.
 
472
 
 
473
 
 
474
****
 
475
BUGS
 
476
****
 
477
 
 
478
 
 
479
For a list of known bugs, see `http://www.percona.com/bugs/pt-duplicate-key-checker <http://www.percona.com/bugs/pt-duplicate-key-checker>`_.
 
480
 
 
481
Please report bugs at `https://bugs.launchpad.net/percona-toolkit <https://bugs.launchpad.net/percona-toolkit>`_.
 
482
Include the following information in your bug report:
 
483
 
 
484
 
 
485
\* Complete command-line used to run the tool
 
486
 
 
487
 
 
488
 
 
489
\* Tool "--version"
 
490
 
 
491
 
 
492
 
 
493
\* MySQL version of all servers involved
 
494
 
 
495
 
 
496
 
 
497
\* Output from the tool including STDERR
 
498
 
 
499
 
 
500
 
 
501
\* Input files (log/dump/config files, etc.)
 
502
 
 
503
 
 
504
 
 
505
If possible, include debugging output by running the tool with \ ``PTDEBUG``\ ;
 
506
see "ENVIRONMENT".
 
507
 
 
508
 
 
509
*******
 
510
AUTHORS
 
511
*******
 
512
 
 
513
 
 
514
Baron Schwartz and Daniel Nichter
 
515
 
 
516
 
 
517
*********************
 
518
ABOUT PERCONA TOOLKIT
 
519
*********************
 
520
 
 
521
 
 
522
This tool is part of Percona Toolkit, a collection of advanced command-line
 
523
tools developed by Percona for MySQL support and consulting.  Percona Toolkit
 
524
was forked from two projects in June, 2011: Maatkit and Aspersa.  Those
 
525
projects were created by Baron Schwartz and developed primarily by him and
 
526
Daniel Nichter, both of whom are employed by Percona.  Visit
 
527
`http://www.percona.com/software/ <http://www.percona.com/software/>`_ for more software developed by Percona.
 
528
 
 
529
 
 
530
********************************
 
531
COPYRIGHT, LICENSE, AND WARRANTY
 
532
********************************
 
533
 
 
534
 
 
535
This program is copyright 2007-2011 Baron Schwartz, 2011 Percona Inc.
 
536
Feedback and improvements are welcome.
 
537
 
 
538
THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 
539
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 
540
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
541
 
 
542
This program is free software; you can redistribute it and/or modify it under
 
543
the terms of the GNU General Public License as published by the Free Software
 
544
Foundation, version 2; OR the Perl Artistic License.  On UNIX and similar
 
545
systems, you can issue \`man perlgpl' or \`man perlartistic' to read these
 
546
licenses.
 
547
 
 
548
You should have received a copy of the GNU General Public License along with
 
549
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
550
Place, Suite 330, Boston, MA  02111-1307  USA.
 
551
 
 
552
 
 
553
*******
 
554
VERSION
 
555
*******
 
556
 
 
557
 
 
558
Percona Toolkit v1.0.0 released 2011-08-01
 
559