diff --git a/lib/TableNibbler.pm b/lib/TableNibbler.pm index f1a0f860..788598ca 100644 --- a/lib/TableNibbler.pm +++ b/lib/TableNibbler.pm @@ -82,6 +82,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)]; } diff --git a/t/lib/TableNibbler.t b/t/lib/TableNibbler.t index 480704eb..51fe17cf 100644 --- a/t/lib/TableNibbler.t +++ b/t/lib/TableNibbler.t @@ -9,7 +9,7 @@ BEGIN { use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); -use Test::More tests => 25; +use Test::More tests => 26; use TableParser; use TableNibbler; @@ -325,6 +325,39 @@ is_deeply( '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( $n->generate_asc_stmt( tbl_struct => $t, diff --git a/t/pt-table-checksum/chunk_index.t b/t/pt-table-checksum/chunk_index.t index 14879d7e..969234f4 100644 --- a/t/pt-table-checksum/chunk_index.t +++ b/t/pt-table-checksum/chunk_index.t @@ -25,7 +25,7 @@ if ( !$dbh ) { plan skip_all => 'Cannot connect to sandbox master'; } else { - plan tests => 14; + plan tests => 15; } # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic @@ -199,6 +199,11 @@ ok( ), "--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.