Merge lp:~percona-toolkit-dev/percona-toolkit/fix-ptc-index-bug-1199591 into lp:~percona-toolkit-dev/percona-toolkit/release-2.2.4

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 601
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-ptc-index-bug-1199591
Merge into: lp:~percona-toolkit-dev/percona-toolkit/release-2.2.4
Diff against target: 139 lines (+73/-7)
5 files modified
bin/pt-online-schema-change (+1/-1)
bin/pt-table-checksum (+1/-1)
lib/NibbleIterator.pm (+1/-1)
t/lib/NibbleIterator.t (+21/-4)
t/lib/samples/cardinality.sql (+49/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-ptc-index-bug-1199591
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+174007@code.launchpad.net
To post a comment you must log in.
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-online-schema-change'
2--- bin/pt-online-schema-change 2013-06-26 20:28:27 +0000
3+++ bin/pt-online-schema-change 2013-07-10 17:30:39 +0000
4@@ -5495,7 +5495,7 @@
5 }
6 @possible_indexes = sort {
7 my $cmp
8- = $indexes->{$b}->{cardinality} <=> $indexes->{$b}->{cardinality};
9+ = $indexes->{$b}->{cardinality} <=> $indexes->{$a}->{cardinality};
10 if ( $cmp == 0 ) {
11 $cmp = scalar @{$indexes->{$b}->{cols}}
12 <=> scalar @{$indexes->{$a}->{cols}};
13
14=== modified file 'bin/pt-table-checksum'
15--- bin/pt-table-checksum 2013-06-26 01:30:12 +0000
16+++ bin/pt-table-checksum 2013-07-10 17:30:39 +0000
17@@ -6479,7 +6479,7 @@
18 }
19 @possible_indexes = sort {
20 my $cmp
21- = $indexes->{$b}->{cardinality} <=> $indexes->{$b}->{cardinality};
22+ = $indexes->{$b}->{cardinality} <=> $indexes->{$a}->{cardinality};
23 if ( $cmp == 0 ) {
24 $cmp = scalar @{$indexes->{$b}->{cols}}
25 <=> scalar @{$indexes->{$a}->{cols}};
26
27=== modified file 'lib/NibbleIterator.pm'
28--- lib/NibbleIterator.pm 2013-03-01 02:26:04 +0000
29+++ lib/NibbleIterator.pm 2013-07-10 17:30:39 +0000
30@@ -554,7 +554,7 @@
31 @possible_indexes = sort {
32 # Prefer the index with the highest cardinality.
33 my $cmp
34- = $indexes->{$b}->{cardinality} <=> $indexes->{$b}->{cardinality};
35+ = $indexes->{$b}->{cardinality} <=> $indexes->{$a}->{cardinality};
36 if ( $cmp == 0 ) {
37 # Indexes have the same cardinality; prefer the one with
38 # more columns.
39
40=== modified file 't/lib/NibbleIterator.t'
41--- t/lib/NibbleIterator.t 2013-03-13 19:49:44 +0000
42+++ t/lib/NibbleIterator.t 2013-07-10 17:30:39 +0000
43@@ -38,9 +38,6 @@
44 if ( !$dbh ) {
45 plan skip_all => 'Cannot connect to sandbox master';
46 }
47-else {
48- plan tests => 54;
49-}
50
51 my $q = new Quoter();
52 my $tp = new TableParser(Quoter=>$q);
53@@ -831,6 +828,26 @@
54 "Bug 995274: nibble iter works"
55 );
56
57+
58+# #############################################################################
59+# pt-table-checksum doesn't use non-unique index with highest cardinality
60+# https://bugs.launchpad.net/percona-toolkit/+bug/1199591
61+# #############################################################################
62+
63+diag(`/tmp/12345/use < $trunk/t/lib/samples/cardinality.sql >/dev/null`);
64+
65+$ni = make_nibble_iter(
66+ db => 'cardb',
67+ tbl => 't',
68+ argv => [qw(--databases cardb --chunk-size 2)],
69+);
70+
71+is(
72+ $ni->{index},
73+ 'b',
74+ "Use non-unique index with highest cardinality (bug 1199591)"
75+);
76+
77 # #############################################################################
78 # Done.
79 # #############################################################################
80@@ -846,4 +863,4 @@
81 );
82 $sb->wipe_clean($dbh);
83 ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
84-exit;
85+done_testing;
86
87=== added file 't/lib/samples/cardinality.sql'
88--- t/lib/samples/cardinality.sql 1970-01-01 00:00:00 +0000
89+++ t/lib/samples/cardinality.sql 2013-07-10 17:30:39 +0000
90@@ -0,0 +1,49 @@
91+DROP DATABASE IF EXISTS cardb;
92+CREATE DATABASE cardb;
93+USE cardb;
94+CREATE TABLE t (
95+ high INT UNSIGNED NOT NULL,
96+ low INT UNSIGNED NOT NULL,
97+ INDEX a (low),
98+ INDEX b (high),
99+ INDEX c (low)
100+) ENGINE=InnoDB;
101+INSERT INTO t VALUES
102+ (1, 1),
103+ (2, 1),
104+ (3, 1),
105+ (4, 1),
106+ (5, 1),
107+ (6, 1),
108+ (7, 1),
109+ (8, 1),
110+ (9, 1),
111+ (10, 1),
112+ (11, 1),
113+ (12, 1),
114+ (13, 1),
115+ (14, 1),
116+ (15, 1),
117+ (16, 1),
118+ (17, 1),
119+ (18, 1),
120+ (19, 1),
121+ (20, 1),
122+ (21, 2),
123+ (22, 2),
124+ (23, 2),
125+ (24, 2),
126+ (25, 2),
127+ (26, 2),
128+ (27, 2),
129+ (28, 2),
130+ (29, 2),
131+ (30, 2),
132+ (31, 2),
133+ (32, 2),
134+ (33, 2),
135+ (34, 2),
136+ (35, 2),
137+ (36, 2),
138+ (37, 2);
139+ANALYZE TABLE t;

Subscribers

People subscribed via source and target branches

to all changes: