Merge lp:~percona-toolkit-dev/percona-toolkit/fix-dupe-key-bug-894140 into lp:percona-toolkit/2.1

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 253
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-dupe-key-bug-894140
Merge into: lp:percona-toolkit/2.1
Diff against target: 165 lines (+94/-4)
6 files modified
bin/pt-duplicate-key-checker (+1/-1)
lib/DuplicateKeyFinder.pm (+1/-1)
t/lib/DuplicateKeyFinder.t (+43/-1)
t/lib/samples/dupekeys/dupe-cluster-bug-894140.sql (+8/-0)
t/pt-duplicate-key-checker/basics.t (+12/-1)
t/pt-duplicate-key-checker/samples/bug-894140.txt (+29/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-dupe-key-bug-894140
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+105744@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-duplicate-key-checker'
2--- bin/pt-duplicate-key-checker 2012-04-03 19:42:45 +0000
3+++ bin/pt-duplicate-key-checker 2012-05-15 01:11:18 +0000
4@@ -2664,7 +2664,7 @@
5 }
6 else {
7 PTDEBUG && _d($right_name, 'not left-prefix of', $left_name);
8- next LEFT_KEY;
9+ next RIGHT_KEY;
10 }
11 } # RIGHT_KEY
12 } # LEFT_KEY
13
14=== modified file 'lib/DuplicateKeyFinder.pm'
15--- lib/DuplicateKeyFinder.pm 2012-01-19 19:46:56 +0000
16+++ lib/DuplicateKeyFinder.pm 2012-05-15 01:11:18 +0000
17@@ -359,7 +359,7 @@
18 }
19 else {
20 PTDEBUG && _d($right_name, 'not left-prefix of', $left_name);
21- next LEFT_KEY;
22+ next RIGHT_KEY;
23 }
24 } # RIGHT_KEY
25 } # LEFT_KEY
26
27=== modified file 't/lib/DuplicateKeyFinder.t'
28--- t/lib/DuplicateKeyFinder.t 2012-03-06 13:56:08 +0000
29+++ t/lib/DuplicateKeyFinder.t 2012-05-15 01:11:18 +0000
30@@ -9,7 +9,7 @@
31 use strict;
32 use warnings FATAL => 'all';
33 use English qw(-no_match_vars);
34-use Test::More tests => 37;
35+use Test::More tests => 38;
36
37 use DuplicateKeyFinder;
38 use Quoter;
39@@ -729,6 +729,48 @@
40 'Issue 1192'
41 );
42
43+
44+# #############################################################################
45+# https://bugs.launchpad.net/percona-toolkit/+bug/894140
46+# #############################################################################
47+$ddl = load_file('t/lib/samples/dupekeys/dupe-cluster-bug-894140.sql');
48+$dupes = [];
49+($keys, $ck) = $tp->get_keys($ddl, $opt);
50+$dk->get_duplicate_keys(
51+ $keys,
52+ clustered_key => $ck,
53+ clustered => 1,
54+ callback => $callback,
55+ tbl_info => { engine => 'InnoDB', ddl => $ddl },
56+);
57+
58+is_deeply(
59+ $dupes,
60+ [
61+ {
62+ cols => [ 'row_id' ],
63+ ddl => 'UNIQUE KEY `row_id` (`row_id`),',
64+ dupe_type => 'exact',
65+ duplicate_of => 'PRIMARY',
66+ duplicate_of_cols => [ 'row_id' ],
67+ duplicate_of_ddl => 'PRIMARY KEY (`row_id`),',
68+ key => 'row_id',
69+ reason => 'row_id is a duplicate of PRIMARY',
70+ },
71+ {
72+ cols => [ 'player_id' ],
73+ ddl => 'KEY `player_id_2` (`player_id`)',
74+ dupe_type => 'exact',
75+ duplicate_of => 'player_id',
76+ duplicate_of_cols => [ 'player_id' ],
77+ duplicate_of_ddl => 'UNIQUE KEY `player_id` (`player_id`),',
78+ key => 'player_id_2',
79+ reason => 'player_id_2 is a duplicate of player_id',
80+ },
81+ ],
82+ 'Finds duplicates OK on uppercase columns',
83+);
84+
85 # #############################################################################
86 # Done.
87 # #############################################################################
88
89=== added file 't/lib/samples/dupekeys/dupe-cluster-bug-894140.sql'
90--- t/lib/samples/dupekeys/dupe-cluster-bug-894140.sql 1970-01-01 00:00:00 +0000
91+++ t/lib/samples/dupekeys/dupe-cluster-bug-894140.sql 2012-05-15 01:11:18 +0000
92@@ -0,0 +1,8 @@
93+CREATE TABLE `bug_894140` (
94+ `row_id` bigint(20) NOT NULL AUTO_INCREMENT,
95+ `player_id` bigint(20) DEFAULT NULL,
96+ PRIMARY KEY (`row_id`),
97+ UNIQUE KEY `row_id` (`row_id`),
98+ UNIQUE KEY `player_id` (`player_id`),
99+ KEY `player_id_2` (`player_id`)
100+) ENGINE=InnoDB DEFAULT CHARSET=utf8
101
102=== modified file 't/pt-duplicate-key-checker/basics.t'
103--- t/pt-duplicate-key-checker/basics.t 2011-07-12 22:56:55 +0000
104+++ t/pt-duplicate-key-checker/basics.t 2012-05-15 01:11:18 +0000
105@@ -23,7 +23,7 @@
106 plan skip_all => 'Cannot connect to sandbox master';
107 }
108 else {
109- plan tests => 8;
110+ plan tests => 9;
111 }
112
113 my $output;
114@@ -95,6 +95,17 @@
115 'No results for nonexistent db'
116 );
117
118+$dbh->do('create database test');
119+$sb->load_file('master', 't/lib/samples/dupekeys/dupe-cluster-bug-894140.sql', 'test');
120+
121+ok(
122+ no_diff(
123+ sub { pt_duplicate_key_checker::main(@args, qw(-d test)) },
124+ "$sample/bug-894140.txt",
125+ ),
126+ "Bug 894140"
127+);
128+
129 # #############################################################################
130 # Done.
131 # #############################################################################
132
133=== added file 't/pt-duplicate-key-checker/samples/bug-894140.txt'
134--- t/pt-duplicate-key-checker/samples/bug-894140.txt 1970-01-01 00:00:00 +0000
135+++ t/pt-duplicate-key-checker/samples/bug-894140.txt 2012-05-15 01:11:18 +0000
136@@ -0,0 +1,29 @@
137+# ########################################################################
138+# test.bug_894140
139+# ########################################################################
140+
141+# row_id is a duplicate of PRIMARY
142+# Key definitions:
143+# UNIQUE KEY `row_id` (`row_id`),
144+# PRIMARY KEY (`row_id`),
145+# Column types:
146+# `row_id` bigint(20) not null auto_increment
147+# To remove this duplicate index, execute:
148+ALTER TABLE `test`.`bug_894140` DROP INDEX `row_id`;
149+
150+# player_id_2 is a duplicate of player_id
151+# Key definitions:
152+# KEY `player_id_2` (`player_id`)
153+# UNIQUE KEY `player_id` (`player_id`),
154+# Column types:
155+# `player_id` bigint(20) default null
156+# To remove this duplicate index, execute:
157+ALTER TABLE `test`.`bug_894140` DROP INDEX `player_id_2`;
158+
159+# ########################################################################
160+# Summary of indexes
161+# ########################################################################
162+
163+# Size Duplicate Indexes 17
164+# Total Duplicate Indexes 2
165+# Total Indexes 4

Subscribers

People subscribed via source and target branches