Merge lp:~percona-toolkit-dev/percona-toolkit/chunk-index-columns-opt into lp:percona-toolkit/2.1

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 281
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/chunk-index-columns-opt
Merge into: lp:percona-toolkit/2.1
Diff against target: 245 lines (+88/-42)
5 files modified
bin/pt-online-schema-change (+16/-19)
bin/pt-table-checksum (+16/-19)
lib/TableNibbler.pm (+1/-0)
t/lib/TableNibbler.t (+34/-1)
t/pt-table-checksum/chunk_index.t (+21/-3)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/chunk-index-columns-opt
Reviewer Review Type Date Requested Status
Baron Schwartz (community) Approve
Daniel Nichter Approve
Review via email: mp+109618@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve
Revision history for this message
Baron Schwartz (baron-xaprb) :
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 2012-06-10 17:25:44 +0000
3+++ bin/pt-online-schema-change 2012-06-11 12:18:22 +0000
4@@ -1893,6 +1893,7 @@
5 @asc_cols = $asc_cols[0];
6 }
7 elsif ( my $n = $args{n_index_cols} ) {
8+ $n = scalar @asc_cols if $n > @asc_cols;
9 PTDEBUG && _d('Ascending only first', $n, 'columns');
10 @asc_cols = @asc_cols[0..($n-1)];
11 }
12@@ -5209,14 +5210,8 @@
13 }
14 }
15
16- # Parse --chunk-index INDEX:N where N is the number of
17- # left-most columns of INDEX to use.
18 # https://bugs.launchpad.net/percona-toolkit/+bug/1010232
19- my ($chunk_index, $n_chunk_index_cols)
20- = split(':', $o->get('chunk-index') || '');
21- if ( defined $chunk_index && $chunk_index eq '' ) {
22- $o->save_error('--chunk-index cannot be an empty string');
23- }
24+ my $n_chunk_index_cols = $o->get('chunk-index-columns');
25 if ( defined $n_chunk_index_cols
26 && (!$n_chunk_index_cols
27 || $n_chunk_index_cols =~ m/\D/
28@@ -6108,8 +6103,8 @@
29 Cxn => $cxn,
30 tbl => $orig_tbl,
31 chunk_size => $orig_tbl->{chunk_size},
32- chunk_index => $chunk_index,
33- n_chunk_index_cols => $n_chunk_index_cols,
34+ chunk_index => $o->get('chunk-index'),
35+ n_chunk_index_cols => $o->get('chunk-index-columns'),
36 dml => $dml,
37 select => $select,
38 callbacks => $callbacks,
39@@ -7453,16 +7448,18 @@
40 a C<FORCE INDEX> clause. Be careful when using this option; a poor choice of
41 index could cause bad performance.
42
43-This option supports a special syntax to select a prefix of the index instead of
44-the entire index. The syntax is NAME:N, where NAME is the name of the index, and
45-N is the number of columns you wish to use. This works only for compound
46-indexes, and is useful in cases where a bug in the MySQL query optimizer
47-(planner) causes it to scan a large range of rows instead of using the index to
48-locate starting and ending points precisely. This problem sometimes occurs on
49-indexes with many columns, such as 4 or more. If this happens, the tool might
50-print a warning related to the L<"--[no]check-plan"> option. Instructing
51-the tool to use only the first N columns from the index is a workaround for
52-the bug in some cases.
53+=item --chunk-index-columns
54+
55+type: int
56+
57+Use only this many left-most columns of a L<"--chunk-index">. This works
58+only for compound indexes, and is useful in cases where a bug in the MySQL
59+query optimizer (planner) causes it to scan a large range of rows instead
60+of using the index to locate starting and ending points precisely. This
61+problem sometimes occurs on indexes with many columns, such as 4 or more.
62+If this happens, the tool might print a warning related to the
63+L<"--[no]check-plan"> option. Instructing the tool to use only the first
64+N columns of the index is a workaround for the bug in some cases.
65
66 =item --chunk-size
67
68
69=== modified file 'bin/pt-table-checksum'
70--- bin/pt-table-checksum 2012-06-10 17:25:44 +0000
71+++ bin/pt-table-checksum 2012-06-11 12:18:22 +0000
72@@ -2294,6 +2294,7 @@
73 @asc_cols = $asc_cols[0];
74 }
75 elsif ( my $n = $args{n_index_cols} ) {
76+ $n = scalar @asc_cols if $n > @asc_cols;
77 PTDEBUG && _d('Ascending only first', $n, 'columns');
78 @asc_cols = @asc_cols[0..($n-1)];
79 }
80@@ -6170,14 +6171,8 @@
81 }
82 }
83
84- # Parse --chunk-index INDEX:N where N is the number of
85- # left-most columns of INDEX to use.
86 # https://bugs.launchpad.net/percona-toolkit/+bug/1010232
87- my ($chunk_index, $n_chunk_index_cols)
88- = split(':', $o->get('chunk-index') || '');
89- if ( defined $chunk_index && $chunk_index eq '' ) {
90- $o->save_error('--chunk-index cannot be an empty string');
91- }
92+ my $n_chunk_index_cols = $o->get('chunk-index-columns');
93 if ( defined $n_chunk_index_cols
94 && (!$n_chunk_index_cols
95 || $n_chunk_index_cols =~ m/\D/
96@@ -7116,8 +7111,8 @@
97 Cxn => $master_cxn,
98 tbl => $tbl,
99 chunk_size => $tbl->{chunk_size},
100- chunk_index => $chunk_index,
101- n_chunk_index_cols => $n_chunk_index_cols,
102+ chunk_index => $o->get('chunk-index'),
103+ n_chunk_index_cols => $o->get('chunk-index-columns'),
104 dml => $checksum_dml,
105 select => $checksum_cols,
106 past_dml => $checksum_dml,
107@@ -8302,16 +8297,18 @@
108 This is probably best to use when you are checksumming only a single table, not
109 an entire server.
110
111-This option supports a special syntax to select a prefix of the index instead of
112-the entire index. The syntax is NAME:N, where NAME is the name of the index, and
113-N is the number of columns you wish to use. This works only for compound
114-indexes, and is useful in cases where a bug in the MySQL query optimizer
115-(planner) causes it to scan a large range of rows instead of using the index to
116-locate starting and ending points precisely. This problem sometimes occurs on
117-indexes with many columns, such as 4 or more. If this happens, the tool might
118-print a warning related to the L<"--[no]check-plan"> option. Instructing
119-the tool to use only the first N columns from the index is a workaround for
120-the bug in some cases.
121+=item --chunk-index-columns
122+
123+type: int
124+
125+Use only this many left-most columns of a L<"--chunk-index">. This works
126+only for compound indexes, and is useful in cases where a bug in the MySQL
127+query optimizer (planner) causes it to scan a large range of rows instead
128+of using the index to locate starting and ending points precisely. This
129+problem sometimes occurs on indexes with many columns, such as 4 or more.
130+If this happens, the tool might print a warning related to the
131+L<"--[no]check-plan"> option. Instructing the tool to use only the first
132+N columns of the index is a workaround for the bug in some cases.
133
134 =item --chunk-size
135
136
137=== modified file 'lib/TableNibbler.pm'
138--- lib/TableNibbler.pm 2012-06-10 14:01:25 +0000
139+++ lib/TableNibbler.pm 2012-06-11 12:18:22 +0000
140@@ -82,6 +82,7 @@
141 @asc_cols = $asc_cols[0];
142 }
143 elsif ( my $n = $args{n_index_cols} ) {
144+ $n = scalar @asc_cols if $n > @asc_cols;
145 PTDEBUG && _d('Ascending only first', $n, 'columns');
146 @asc_cols = @asc_cols[0..($n-1)];
147 }
148
149=== modified file 't/lib/TableNibbler.t'
150--- t/lib/TableNibbler.t 2012-06-10 14:01:25 +0000
151+++ t/lib/TableNibbler.t 2012-06-11 12:18:22 +0000
152@@ -9,7 +9,7 @@
153 use strict;
154 use warnings FATAL => 'all';
155 use English qw(-no_match_vars);
156-use Test::More tests => 25;
157+use Test::More tests => 26;
158
159 use TableParser;
160 use TableNibbler;
161@@ -327,6 +327,39 @@
162
163 is_deeply(
164 $n->generate_asc_stmt(
165+ tbl_struct => $t,
166+ cols => $t->{cols},
167+ index => 'rental_date',
168+ n_index_cols => 5,
169+ ),
170+ {
171+ cols => [qw(rental_id rental_date inventory_id customer_id
172+ return_date staff_id last_update)],
173+ index => 'rental_date',
174+ where => '((`rental_date` > ?) OR (`rental_date` = ? AND `inventory_id` > ?)'
175+ . ' OR (`rental_date` = ? AND `inventory_id` = ? AND `customer_id` >= ?))',
176+ slice => [1, 1, 2, 1, 2, 3],
177+ scols => [qw(rental_date rental_date inventory_id rental_date inventory_id customer_id)],
178+ boundaries => {
179+ '>=' => '((`rental_date` > ?) OR (`rental_date` = ? AND '
180+ . '`inventory_id` > ?) OR (`rental_date` = ? AND `inventory_id` '
181+ . '= ? AND `customer_id` >= ?))',
182+ '>' => '((`rental_date` > ?) OR (`rental_date` = ? AND '
183+ . '`inventory_id` > ?) OR (`rental_date` = ? AND `inventory_id` '
184+ . '= ? AND `customer_id` > ?))',
185+ '<=' => '((`rental_date` < ?) OR (`rental_date` = ? AND '
186+ . '`inventory_id` < ?) OR (`rental_date` = ? AND `inventory_id` '
187+ . '= ? AND `customer_id` <= ?))',
188+ '<' => '((`rental_date` < ?) OR (`rental_date` = ? AND '
189+ . '`inventory_id` < ?) OR (`rental_date` = ? AND `inventory_id` '
190+ . '= ? AND `customer_id` < ?))',
191+ },
192+ },
193+ "Don't crash if N > number of index columns"
194+);
195+
196+is_deeply(
197+ $n->generate_asc_stmt(
198 tbl_struct => $t,
199 cols => $t->{cols},
200 index => 'rental_date',
201
202=== modified file 't/pt-table-checksum/chunk_index.t'
203--- t/pt-table-checksum/chunk_index.t 2012-06-10 17:25:44 +0000
204+++ t/pt-table-checksum/chunk_index.t 2012-06-11 12:18:22 +0000
205@@ -25,7 +25,7 @@
206 plan skip_all => 'Cannot connect to sandbox master';
207 }
208 else {
209- plan tests => 14;
210+ plan tests => 16;
211 }
212
213 # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
214@@ -193,11 +193,29 @@
215 pt_table_checksum::main(
216 $master_dsn, '--max-load', '',
217 qw(--lock-wait-timeout 3 --chunk-size 5000 -t sakila.rental),
218- qw(--chunk-index rental_date:2 --explain --explain));
219+ qw(--chunk-index rental_date --chunk-index-columns 2),
220+ qw(--explain --explain));
221 },
222 "t/pt-table-checksum/samples/n-chunk-index-cols.txt",
223 ),
224- "--chunk-index index:n"
225+ "--chunk-index-columns"
226+);
227+
228+$output = output(
229+ sub {
230+ $exit_status = pt_table_checksum::main(
231+ $master_dsn, '--max-load', '',
232+ qw(--lock-wait-timeout 3 --chunk-size 5000 -t sakila.rental),
233+ qw(--chunk-index rental_date --chunk-index-columns 5),
234+ qw(--explain --explain));
235+ },
236+ stderr => 1,
237+);
238+
239+is(
240+ $exit_status,
241+ 0,
242+ "--chunk-index-columns > number of index columns"
243 );
244
245 # #############################################################################

Subscribers

People subscribed via source and target branches