mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-27 16:12:04 +00:00
Add --chunk-index-columns to pt-table-checksum.
This commit is contained in:
@@ -2294,6 +2294,7 @@ sub generate_asc_stmt {
|
||||
@asc_cols = $asc_cols[0];
|
||||
}
|
||||
elsif ( my $n = $args{n_index_cols} ) {
|
||||
$n = scalar @asc_cols if $n > @asc_cols;
|
||||
PTDEBUG && _d('Ascending only first', $n, 'columns');
|
||||
@asc_cols = @asc_cols[0..($n-1)];
|
||||
}
|
||||
@@ -6173,11 +6174,7 @@ sub main {
|
||||
# Parse --chunk-index INDEX:N where N is the number of
|
||||
# left-most columns of INDEX to use.
|
||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1010232
|
||||
my ($chunk_index, $n_chunk_index_cols)
|
||||
= split(':', $o->get('chunk-index') || '');
|
||||
if ( defined $chunk_index && $chunk_index eq '' ) {
|
||||
$o->save_error('--chunk-index cannot be an empty string');
|
||||
}
|
||||
my $n_chunk_index_cols = $o->get('chunk-index-columns');
|
||||
if ( defined $n_chunk_index_cols
|
||||
&& (!$n_chunk_index_cols
|
||||
|| $n_chunk_index_cols =~ m/\D/
|
||||
@@ -7116,8 +7113,8 @@ sub main {
|
||||
Cxn => $master_cxn,
|
||||
tbl => $tbl,
|
||||
chunk_size => $tbl->{chunk_size},
|
||||
chunk_index => $chunk_index,
|
||||
n_chunk_index_cols => $n_chunk_index_cols,
|
||||
chunk_index => $o->get('chunk-index'),
|
||||
n_chunk_index_cols => $o->get('chunk-index-columns'),
|
||||
dml => $checksum_dml,
|
||||
select => $checksum_cols,
|
||||
past_dml => $checksum_dml,
|
||||
@@ -8302,16 +8299,18 @@ when using this option; a poor choice of index could cause bad performance.
|
||||
This is probably best to use when you are checksumming only a single table, not
|
||||
an entire server.
|
||||
|
||||
This option supports a special syntax to select a prefix of the index instead of
|
||||
the entire index. The syntax is NAME:N, where NAME is the name of the index, and
|
||||
N is the number of columns you wish to use. This works only for compound
|
||||
indexes, and is useful in cases where a bug in the MySQL query optimizer
|
||||
(planner) causes it to scan a large range of rows instead of using the index to
|
||||
locate starting and ending points precisely. This problem sometimes occurs on
|
||||
indexes with many columns, such as 4 or more. If this happens, the tool might
|
||||
print a warning related to the L<"--[no]check-plan"> option. Instructing
|
||||
the tool to use only the first N columns from the index is a workaround for
|
||||
the bug in some cases.
|
||||
=item --chunk-index-columns
|
||||
|
||||
type: int
|
||||
|
||||
Use only this many left-most columns of a L<"--chunk-index">. This works
|
||||
only for compound indexes, and is useful in cases where a bug in the MySQL
|
||||
query optimizer (planner) causes it to scan a large range of rows instead
|
||||
of using the index to locate starting and ending points precisely. This
|
||||
problem sometimes occurs on indexes with many columns, such as 4 or more.
|
||||
If this happens, the tool might print a warning related to the
|
||||
L<"--[no]check-plan"> option. Instructing the tool to use only the first
|
||||
N columns of the index is a workaround for the bug in some cases.
|
||||
|
||||
=item --chunk-size
|
||||
|
||||
|
@@ -25,7 +25,7 @@ if ( !$dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
else {
|
||||
plan tests => 15;
|
||||
plan tests => 16;
|
||||
}
|
||||
|
||||
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
|
||||
@@ -193,17 +193,30 @@ ok(
|
||||
pt_table_checksum::main(
|
||||
$master_dsn, '--max-load', '',
|
||||
qw(--lock-wait-timeout 3 --chunk-size 5000 -t sakila.rental),
|
||||
qw(--chunk-index rental_date:2 --explain --explain));
|
||||
qw(--chunk-index rental_date --chunk-index-columns 2),
|
||||
qw(--explain --explain));
|
||||
},
|
||||
"t/pt-table-checksum/samples/n-chunk-index-cols.txt",
|
||||
),
|
||||
"--chunk-index index:n"
|
||||
"--chunk-index-columns"
|
||||
);
|
||||
|
||||
pt_table_checksum::main(
|
||||
$output = output(
|
||||
sub {
|
||||
$exit_status = pt_table_checksum::main(
|
||||
$master_dsn, '--max-load', '',
|
||||
qw(--lock-wait-timeout 3 --chunk-size 5000 -t sakila.rental),
|
||||
qw(--chunk-index rental_date:5 --explain --explain));
|
||||
qw(--chunk-index rental_date --chunk-index-columns 5),
|
||||
qw(--explain --explain));
|
||||
},
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
is(
|
||||
$exit_status,
|
||||
0,
|
||||
"--chunk-index-columns > number of index columns"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
|
Reference in New Issue
Block a user