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
=== modified file 'bin/pt-online-schema-change'
--- bin/pt-online-schema-change 2012-06-10 17:25:44 +0000
+++ bin/pt-online-schema-change 2012-06-11 12:18:22 +0000
@@ -1893,6 +1893,7 @@
1893 @asc_cols = $asc_cols[0];1893 @asc_cols = $asc_cols[0];
1894 }1894 }
1895 elsif ( my $n = $args{n_index_cols} ) {1895 elsif ( my $n = $args{n_index_cols} ) {
1896 $n = scalar @asc_cols if $n > @asc_cols;
1896 PTDEBUG && _d('Ascending only first', $n, 'columns');1897 PTDEBUG && _d('Ascending only first', $n, 'columns');
1897 @asc_cols = @asc_cols[0..($n-1)];1898 @asc_cols = @asc_cols[0..($n-1)];
1898 }1899 }
@@ -5209,14 +5210,8 @@
5209 }5210 }
5210 }5211 }
52115212
5212 # Parse --chunk-index INDEX:N where N is the number of
5213 # left-most columns of INDEX to use.
5214 # https://bugs.launchpad.net/percona-toolkit/+bug/10102325213 # https://bugs.launchpad.net/percona-toolkit/+bug/1010232
5215 my ($chunk_index, $n_chunk_index_cols)5214 my $n_chunk_index_cols = $o->get('chunk-index-columns');
5216 = split(':', $o->get('chunk-index') || '');
5217 if ( defined $chunk_index && $chunk_index eq '' ) {
5218 $o->save_error('--chunk-index cannot be an empty string');
5219 }
5220 if ( defined $n_chunk_index_cols5215 if ( defined $n_chunk_index_cols
5221 && (!$n_chunk_index_cols5216 && (!$n_chunk_index_cols
5222 || $n_chunk_index_cols =~ m/\D/5217 || $n_chunk_index_cols =~ m/\D/
@@ -6108,8 +6103,8 @@
6108 Cxn => $cxn,6103 Cxn => $cxn,
6109 tbl => $orig_tbl,6104 tbl => $orig_tbl,
6110 chunk_size => $orig_tbl->{chunk_size},6105 chunk_size => $orig_tbl->{chunk_size},
6111 chunk_index => $chunk_index,6106 chunk_index => $o->get('chunk-index'),
6112 n_chunk_index_cols => $n_chunk_index_cols,6107 n_chunk_index_cols => $o->get('chunk-index-columns'),
6113 dml => $dml,6108 dml => $dml,
6114 select => $select,6109 select => $select,
6115 callbacks => $callbacks,6110 callbacks => $callbacks,
@@ -7453,16 +7448,18 @@
7453a C<FORCE INDEX> clause. Be careful when using this option; a poor choice of7448a C<FORCE INDEX> clause. Be careful when using this option; a poor choice of
7454index could cause bad performance.7449index could cause bad performance.
74557450
7456This option supports a special syntax to select a prefix of the index instead of7451=item --chunk-index-columns
7457the entire index. The syntax is NAME:N, where NAME is the name of the index, and7452
7458N is the number of columns you wish to use. This works only for compound7453type: int
7459indexes, and is useful in cases where a bug in the MySQL query optimizer7454
7460(planner) causes it to scan a large range of rows instead of using the index to7455Use only this many left-most columns of a L<"--chunk-index">. This works
7461locate starting and ending points precisely. This problem sometimes occurs on7456only for compound indexes, and is useful in cases where a bug in the MySQL
7462indexes with many columns, such as 4 or more. If this happens, the tool might7457query optimizer (planner) causes it to scan a large range of rows instead
7463print a warning related to the L<"--[no]check-plan"> option. Instructing7458of using the index to locate starting and ending points precisely. This
7464the tool to use only the first N columns from the index is a workaround for7459problem sometimes occurs on indexes with many columns, such as 4 or more.
7465the bug in some cases.7460If this happens, the tool might print a warning related to the
7461L<"--[no]check-plan"> option. Instructing the tool to use only the first
7462N columns of the index is a workaround for the bug in some cases.
74667463
7467=item --chunk-size7464=item --chunk-size
74687465
74697466
=== modified file 'bin/pt-table-checksum'
--- bin/pt-table-checksum 2012-06-10 17:25:44 +0000
+++ bin/pt-table-checksum 2012-06-11 12:18:22 +0000
@@ -2294,6 +2294,7 @@
2294 @asc_cols = $asc_cols[0];2294 @asc_cols = $asc_cols[0];
2295 }2295 }
2296 elsif ( my $n = $args{n_index_cols} ) {2296 elsif ( my $n = $args{n_index_cols} ) {
2297 $n = scalar @asc_cols if $n > @asc_cols;
2297 PTDEBUG && _d('Ascending only first', $n, 'columns');2298 PTDEBUG && _d('Ascending only first', $n, 'columns');
2298 @asc_cols = @asc_cols[0..($n-1)];2299 @asc_cols = @asc_cols[0..($n-1)];
2299 }2300 }
@@ -6170,14 +6171,8 @@
6170 }6171 }
6171 }6172 }
61726173
6173 # Parse --chunk-index INDEX:N where N is the number of
6174 # left-most columns of INDEX to use.
6175 # https://bugs.launchpad.net/percona-toolkit/+bug/10102326174 # https://bugs.launchpad.net/percona-toolkit/+bug/1010232
6176 my ($chunk_index, $n_chunk_index_cols)6175 my $n_chunk_index_cols = $o->get('chunk-index-columns');
6177 = split(':', $o->get('chunk-index') || '');
6178 if ( defined $chunk_index && $chunk_index eq '' ) {
6179 $o->save_error('--chunk-index cannot be an empty string');
6180 }
6181 if ( defined $n_chunk_index_cols6176 if ( defined $n_chunk_index_cols
6182 && (!$n_chunk_index_cols6177 && (!$n_chunk_index_cols
6183 || $n_chunk_index_cols =~ m/\D/6178 || $n_chunk_index_cols =~ m/\D/
@@ -7116,8 +7111,8 @@
7116 Cxn => $master_cxn,7111 Cxn => $master_cxn,
7117 tbl => $tbl,7112 tbl => $tbl,
7118 chunk_size => $tbl->{chunk_size},7113 chunk_size => $tbl->{chunk_size},
7119 chunk_index => $chunk_index,7114 chunk_index => $o->get('chunk-index'),
7120 n_chunk_index_cols => $n_chunk_index_cols,7115 n_chunk_index_cols => $o->get('chunk-index-columns'),
7121 dml => $checksum_dml,7116 dml => $checksum_dml,
7122 select => $checksum_cols,7117 select => $checksum_cols,
7123 past_dml => $checksum_dml,7118 past_dml => $checksum_dml,
@@ -8302,16 +8297,18 @@
8302This is probably best to use when you are checksumming only a single table, not8297This is probably best to use when you are checksumming only a single table, not
8303an entire server.8298an entire server.
83048299
8305This option supports a special syntax to select a prefix of the index instead of8300=item --chunk-index-columns
8306the entire index. The syntax is NAME:N, where NAME is the name of the index, and8301
8307N is the number of columns you wish to use. This works only for compound8302type: int
8308indexes, and is useful in cases where a bug in the MySQL query optimizer8303
8309(planner) causes it to scan a large range of rows instead of using the index to8304Use only this many left-most columns of a L<"--chunk-index">. This works
8310locate starting and ending points precisely. This problem sometimes occurs on8305only for compound indexes, and is useful in cases where a bug in the MySQL
8311indexes with many columns, such as 4 or more. If this happens, the tool might8306query optimizer (planner) causes it to scan a large range of rows instead
8312print a warning related to the L<"--[no]check-plan"> option. Instructing8307of using the index to locate starting and ending points precisely. This
8313the tool to use only the first N columns from the index is a workaround for8308problem sometimes occurs on indexes with many columns, such as 4 or more.
8314the bug in some cases.8309If this happens, the tool might print a warning related to the
8310L<"--[no]check-plan"> option. Instructing the tool to use only the first
8311N columns of the index is a workaround for the bug in some cases.
83158312
8316=item --chunk-size8313=item --chunk-size
83178314
83188315
=== modified file 'lib/TableNibbler.pm'
--- lib/TableNibbler.pm 2012-06-10 14:01:25 +0000
+++ lib/TableNibbler.pm 2012-06-11 12:18:22 +0000
@@ -82,6 +82,7 @@
82 @asc_cols = $asc_cols[0];82 @asc_cols = $asc_cols[0];
83 }83 }
84 elsif ( my $n = $args{n_index_cols} ) {84 elsif ( my $n = $args{n_index_cols} ) {
85 $n = scalar @asc_cols if $n > @asc_cols;
85 PTDEBUG && _d('Ascending only first', $n, 'columns');86 PTDEBUG && _d('Ascending only first', $n, 'columns');
86 @asc_cols = @asc_cols[0..($n-1)];87 @asc_cols = @asc_cols[0..($n-1)];
87 }88 }
8889
=== modified file 't/lib/TableNibbler.t'
--- t/lib/TableNibbler.t 2012-06-10 14:01:25 +0000
+++ t/lib/TableNibbler.t 2012-06-11 12:18:22 +0000
@@ -9,7 +9,7 @@
9use strict;9use strict;
10use warnings FATAL => 'all';10use warnings FATAL => 'all';
11use English qw(-no_match_vars);11use English qw(-no_match_vars);
12use Test::More tests => 25;12use Test::More tests => 26;
1313
14use TableParser;14use TableParser;
15use TableNibbler;15use TableNibbler;
@@ -327,6 +327,39 @@
327327
328is_deeply(328is_deeply(
329 $n->generate_asc_stmt(329 $n->generate_asc_stmt(
330 tbl_struct => $t,
331 cols => $t->{cols},
332 index => 'rental_date',
333 n_index_cols => 5,
334 ),
335 {
336 cols => [qw(rental_id rental_date inventory_id customer_id
337 return_date staff_id last_update)],
338 index => 'rental_date',
339 where => '((`rental_date` > ?) OR (`rental_date` = ? AND `inventory_id` > ?)'
340 . ' OR (`rental_date` = ? AND `inventory_id` = ? AND `customer_id` >= ?))',
341 slice => [1, 1, 2, 1, 2, 3],
342 scols => [qw(rental_date rental_date inventory_id rental_date inventory_id customer_id)],
343 boundaries => {
344 '>=' => '((`rental_date` > ?) OR (`rental_date` = ? AND '
345 . '`inventory_id` > ?) OR (`rental_date` = ? AND `inventory_id` '
346 . '= ? AND `customer_id` >= ?))',
347 '>' => '((`rental_date` > ?) OR (`rental_date` = ? AND '
348 . '`inventory_id` > ?) OR (`rental_date` = ? AND `inventory_id` '
349 . '= ? AND `customer_id` > ?))',
350 '<=' => '((`rental_date` < ?) OR (`rental_date` = ? AND '
351 . '`inventory_id` < ?) OR (`rental_date` = ? AND `inventory_id` '
352 . '= ? AND `customer_id` <= ?))',
353 '<' => '((`rental_date` < ?) OR (`rental_date` = ? AND '
354 . '`inventory_id` < ?) OR (`rental_date` = ? AND `inventory_id` '
355 . '= ? AND `customer_id` < ?))',
356 },
357 },
358 "Don't crash if N > number of index columns"
359);
360
361is_deeply(
362 $n->generate_asc_stmt(
330 tbl_struct => $t,363 tbl_struct => $t,
331 cols => $t->{cols},364 cols => $t->{cols},
332 index => 'rental_date',365 index => 'rental_date',
333366
=== modified file 't/pt-table-checksum/chunk_index.t'
--- t/pt-table-checksum/chunk_index.t 2012-06-10 17:25:44 +0000
+++ t/pt-table-checksum/chunk_index.t 2012-06-11 12:18:22 +0000
@@ -25,7 +25,7 @@
25 plan skip_all => 'Cannot connect to sandbox master';25 plan skip_all => 'Cannot connect to sandbox master';
26}26}
27else {27else {
28 plan tests => 14;28 plan tests => 16;
29}29}
3030
31# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic31# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
@@ -193,11 +193,29 @@
193 pt_table_checksum::main(193 pt_table_checksum::main(
194 $master_dsn, '--max-load', '',194 $master_dsn, '--max-load', '',
195 qw(--lock-wait-timeout 3 --chunk-size 5000 -t sakila.rental),195 qw(--lock-wait-timeout 3 --chunk-size 5000 -t sakila.rental),
196 qw(--chunk-index rental_date:2 --explain --explain));196 qw(--chunk-index rental_date --chunk-index-columns 2),
197 qw(--explain --explain));
197 },198 },
198 "t/pt-table-checksum/samples/n-chunk-index-cols.txt",199 "t/pt-table-checksum/samples/n-chunk-index-cols.txt",
199 ),200 ),
200 "--chunk-index index:n"201 "--chunk-index-columns"
202);
203
204$output = output(
205 sub {
206 $exit_status = pt_table_checksum::main(
207 $master_dsn, '--max-load', '',
208 qw(--lock-wait-timeout 3 --chunk-size 5000 -t sakila.rental),
209 qw(--chunk-index rental_date --chunk-index-columns 5),
210 qw(--explain --explain));
211 },
212 stderr => 1,
213);
214
215is(
216 $exit_status,
217 0,
218 "--chunk-index-columns > number of index columns"
201);219);
202220
203# #############################################################################221# #############################################################################

Subscribers

People subscribed via source and target branches