mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 21:51:21 +00:00
Don't crash if N is > number of index columns.
This commit is contained in:
@@ -82,6 +82,7 @@ sub generate_asc_stmt {
|
|||||||
@asc_cols = $asc_cols[0];
|
@asc_cols = $asc_cols[0];
|
||||||
}
|
}
|
||||||
elsif ( my $n = $args{n_index_cols} ) {
|
elsif ( my $n = $args{n_index_cols} ) {
|
||||||
|
$n = scalar @asc_cols if $n > @asc_cols;
|
||||||
PTDEBUG && _d('Ascending only first', $n, 'columns');
|
PTDEBUG && _d('Ascending only first', $n, 'columns');
|
||||||
@asc_cols = @asc_cols[0..($n-1)];
|
@asc_cols = @asc_cols[0..($n-1)];
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@ BEGIN {
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use Test::More tests => 25;
|
use Test::More tests => 26;
|
||||||
|
|
||||||
use TableParser;
|
use TableParser;
|
||||||
use TableNibbler;
|
use TableNibbler;
|
||||||
@@ -325,6 +325,39 @@ is_deeply(
|
|||||||
'Use only N left-most columns of the index',
|
'Use only N left-most columns of the index',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
is_deeply(
|
||||||
|
$n->generate_asc_stmt(
|
||||||
|
tbl_struct => $t,
|
||||||
|
cols => $t->{cols},
|
||||||
|
index => 'rental_date',
|
||||||
|
n_index_cols => 5,
|
||||||
|
),
|
||||||
|
{
|
||||||
|
cols => [qw(rental_id rental_date inventory_id customer_id
|
||||||
|
return_date staff_id last_update)],
|
||||||
|
index => 'rental_date',
|
||||||
|
where => '((`rental_date` > ?) OR (`rental_date` = ? AND `inventory_id` > ?)'
|
||||||
|
. ' OR (`rental_date` = ? AND `inventory_id` = ? AND `customer_id` >= ?))',
|
||||||
|
slice => [1, 1, 2, 1, 2, 3],
|
||||||
|
scols => [qw(rental_date rental_date inventory_id rental_date inventory_id customer_id)],
|
||||||
|
boundaries => {
|
||||||
|
'>=' => '((`rental_date` > ?) OR (`rental_date` = ? AND '
|
||||||
|
. '`inventory_id` > ?) OR (`rental_date` = ? AND `inventory_id` '
|
||||||
|
. '= ? AND `customer_id` >= ?))',
|
||||||
|
'>' => '((`rental_date` > ?) OR (`rental_date` = ? AND '
|
||||||
|
. '`inventory_id` > ?) OR (`rental_date` = ? AND `inventory_id` '
|
||||||
|
. '= ? AND `customer_id` > ?))',
|
||||||
|
'<=' => '((`rental_date` < ?) OR (`rental_date` = ? AND '
|
||||||
|
. '`inventory_id` < ?) OR (`rental_date` = ? AND `inventory_id` '
|
||||||
|
. '= ? AND `customer_id` <= ?))',
|
||||||
|
'<' => '((`rental_date` < ?) OR (`rental_date` = ? AND '
|
||||||
|
. '`inventory_id` < ?) OR (`rental_date` = ? AND `inventory_id` '
|
||||||
|
. '= ? AND `customer_id` < ?))',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Don't crash if N > number of index columns"
|
||||||
|
);
|
||||||
|
|
||||||
is_deeply(
|
is_deeply(
|
||||||
$n->generate_asc_stmt(
|
$n->generate_asc_stmt(
|
||||||
tbl_struct => $t,
|
tbl_struct => $t,
|
||||||
|
@@ -25,7 +25,7 @@ if ( !$dbh ) {
|
|||||||
plan skip_all => 'Cannot connect to sandbox master';
|
plan skip_all => 'Cannot connect to sandbox master';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plan tests => 14;
|
plan tests => 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
|
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
|
||||||
@@ -199,6 +199,11 @@ ok(
|
|||||||
),
|
),
|
||||||
"--chunk-index index:n"
|
"--chunk-index index:n"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
|
Reference in New Issue
Block a user