diff --git a/bin/pt-archiver b/bin/pt-archiver index a6c10fa8..3a93c65b 100755 --- a/bin/pt-archiver +++ b/bin/pt-archiver @@ -5811,7 +5811,18 @@ sub main { $next_sql .= " AND $sel_stmt->{where}"; } + # Obtain index cols so we can order them when ascending + # this ensures returned sets are disjoint when ran on partitioned tables + # issue 1376561 + my $index_cols; + if ( $sel_stmt->{index} + && $src->{info}->{keys}->{$sel_stmt->{index}}->{cols} + ) { + $index_cols = $src->{info}->{keys}->{$sel_stmt->{index}}->{colnames}; + } + foreach my $thing ( $first_sql, $next_sql ) { + $thing .= " ORDER BY $index_cols " if $index_cols; $thing .= " LIMIT $limit"; if ( $o->get('for-update') ) { $thing .= ' FOR UPDATE'; diff --git a/t/pt-archiver/basics.t b/t/pt-archiver/basics.t index b0101468..f2f43d79 100644 --- a/t/pt-archiver/basics.t +++ b/t/pt-archiver/basics.t @@ -161,7 +161,7 @@ $output = output( my $t = time - $t0; ok( - $t >= 2 && $t <= 3.5, + $t >= 2 && $t <= ($ENV{PERCONA_SLOW_BOX} ? 5 : 3), "--sleep between SELECT (bug 979092)" ) or diag($output, "t=", $t); diff --git a/t/pt-archiver/indexes.t b/t/pt-archiver/indexes.t index 646b05da..bb698950 100644 --- a/t/pt-archiver/indexes.t +++ b/t/pt-archiver/indexes.t @@ -97,7 +97,7 @@ is($output, '', "No output when --no-ascend"); # Check ascending only first column $output = `$cmd --where 1=1 --dry-run --ascend-first --source D=test,t=table_5,F=$cnf --purge --limit 50 2>&1`; -like ( $output, qr/WHERE \(1=1\) AND \(\(`a` >= \?\)\) LIMIT/, 'Can ascend just first column'); +like ( $output, qr/WHERE \(1=1\) AND \(\(`a` >= \?\)\) ORDER BY `a`,`b`,`c`,`d` LIMIT/, 'Can ascend just first column'); # ############################################################################# # Done. diff --git a/t/pt-archiver/samples/issue-248.txt b/t/pt-archiver/samples/issue-248.txt index 6f517a4d..bd2b0cfd 100644 --- a/t/pt-archiver/samples/issue-248.txt +++ b/t/pt-archiver/samples/issue-248.txt @@ -1,3 +1,3 @@ -SELECT /*!40001 SQL_NO_CACHE */ `film_id`,`title`,`description`,`release_year`,`language_id`,`original_language_id`,`rental_duration`,`rental_rate`,`length`,`replacement_cost`,`rating`,`special_features`,`last_update` FROM `sakila`.`film` FORCE INDEX(`PRIMARY`) WHERE (film_id < 100) AND (`film_id` < '1000') LIMIT 1 -SELECT /*!40001 SQL_NO_CACHE */ `film_id`,`title`,`description`,`release_year`,`language_id`,`original_language_id`,`rental_duration`,`rental_rate`,`length`,`replacement_cost`,`rating`,`special_features`,`last_update` FROM `sakila`.`film` FORCE INDEX(`PRIMARY`) WHERE (film_id < 100) AND (`film_id` < '1000') AND ((`film_id` >= ?)) LIMIT 1 +SELECT /*!40001 SQL_NO_CACHE */ `film_id`,`title`,`description`,`release_year`,`language_id`,`original_language_id`,`rental_duration`,`rental_rate`,`length`,`replacement_cost`,`rating`,`special_features`,`last_update` FROM `sakila`.`film` FORCE INDEX(`PRIMARY`) WHERE (film_id < 100) AND (`film_id` < '1000') ORDER BY `film_id` LIMIT 1 +SELECT /*!40001 SQL_NO_CACHE */ `film_id`,`title`,`description`,`release_year`,`language_id`,`original_language_id`,`rental_duration`,`rental_rate`,`length`,`replacement_cost`,`rating`,`special_features`,`last_update` FROM `sakila`.`film` FORCE INDEX(`PRIMARY`) WHERE (film_id < 100) AND (`film_id` < '1000') AND ((`film_id` >= ?)) ORDER BY `film_id` LIMIT 1 DELETE FROM `sakila`.`film` WHERE (`film_id` = ?)